From ea127e3d7700d3253eb35cf90750c2bf658ed122 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 6 Aug 2015 12:26:58 +0545 Subject: Service Watchdog package code style --- .../servicewatchdog/services_servicewatchdog.php | 175 ++++++++++++--------- .../services_servicewatchdog_add.php | 4 +- config/servicewatchdog/servicewatchdog.inc | 25 +-- config/servicewatchdog/servicewatchdog.xml | 2 +- config/servicewatchdog/servicewatchdog_cron.php | 3 +- 5 files changed, 121 insertions(+), 88 deletions(-) (limited to 'config') diff --git a/config/servicewatchdog/services_servicewatchdog.php b/config/servicewatchdog/services_servicewatchdog.php index bd4d4442..6c91b98e 100644 --- a/config/servicewatchdog/services_servicewatchdog.php +++ b/config/servicewatchdog/services_servicewatchdog.php @@ -41,14 +41,16 @@ require_once("functions.inc"); require_once("service-utils.inc"); require_once("servicewatchdog.inc"); -if (!is_array($config['installedpackages']['servicewatchdog']['item'])) +if (!is_array($config['installedpackages']['servicewatchdog']['item'])) { $config['installedpackages']['servicewatchdog']['item'] = array(); +} $a_pwservices = &$config['installedpackages']['servicewatchdog']['item']; /* if a custom message has been passed along, lets process it */ -if ($_GET['savemsg']) +if ($_GET['savemsg']) { $savemsg = $_GET['savemsg']; +} if ($_GET['act'] == "del") { if ($a_pwservices[$_GET['id']]) { @@ -65,13 +67,15 @@ if (isset($_POST['Update'])) { if (is_array($_POST['notifies']) && count($_POST['notifies'])) { /* Check each service and set the notify flag only for those chosen, remove those that are unset. */ foreach ($a_pwservices as $idx => $thisservice) { - if (!is_array($thisservice)) + if (!is_array($thisservice)) { continue; + } if (in_array($idx, $_POST['notifies'])) { $a_pwservices[$idx]['notify'] = true; } else { - if (isset($a_pwservices[$idx]['notify'])) + if (isset($a_pwservices[$idx]['notify'])) { unset($a_pwservices[$idx]['notify']); + } } } } else { /* No notifies selected, remove them all. */ @@ -111,26 +115,31 @@ if (isset($_POST['del_x'])) { /* copy all services < $movebtn and not selected */ for ($i = 0; $i < $movebtn; $i++) { - if (!in_array($i, $_POST['pwservices'])) + if (!in_array($i, $_POST['pwservices'])) { $a_pwservices_new[] = $a_pwservices[$i]; + } } /* copy all selected services */ for ($i = 0; $i < count($a_pwservices); $i++) { - if ($i == $movebtn) + if ($i == $movebtn) { continue; - if (in_array($i, $_POST['pwservices'])) + } + if (in_array($i, $_POST['pwservices'])) { $a_pwservices_new[] = $a_pwservices[$i]; + } } /* copy $movebtn service */ - if ($movebtn < count($a_pwservices)) + if ($movebtn < count($a_pwservices)) { $a_pwservices_new[] = $a_pwservices[$movebtn]; + } /* copy all services > $movebtn and not selected */ for ($i = $movebtn+1; $i < count($a_pwservices); $i++) { - if (!in_array($i, $_POST['pwservices'])) + if (!in_array($i, $_POST['pwservices'])) { $a_pwservices_new[] = $a_pwservices[$i]; + } } $a_pwservices = $a_pwservices_new; servicewatchdog_cron_job(); @@ -141,7 +150,7 @@ if (isset($_POST['del_x'])) { } $closehead = false; -$pgtitle = array(gettext("Services"),gettext("Service Watchdog")); +$pgtitle = array(gettext("Services"), gettext("Service Watchdog")); include("head.inc"); ?> @@ -160,83 +169,99 @@ include("head.inc");
- - - - - - - - - - - - - - - - - + + + + - - -
- -

-
 Notify - - - + + + + + + + + + -
- - " border="0" alt="delete" /> - - " onclick="return confirm('')" /> - - " alt="add" />
+ +

+
 Notify + + + + + +
+ + " border="0" alt="delete" /> + + " onclick="return confirm('')" /> + + " alt="add" />
+
-
/> - - - - - - - - - -
" height="17" type="image" width="17" border="0" />')">" alt="delete" />
-
- + + + + + + + - + + - - + + + -
/> + + + + + + + + + +
" height="17" type="image" width="17" border="0" />')">" alt="delete" />
+
" border="0" alt="move" />" border="0" alt="move" /> + + + + + + + + +
" border="0" alt="move" />" border="0" alt="move" />
+ + " border="0" alt="delete" /> + + " onclick="return confirm('')" /> + + " alt="add" />
+
- - " border="0" alt="delete" /> - - " onclick="return confirm('')" /> - - " alt="add" /> + +
+ " /> +
+
+
-
+ +
- -
- " /> -
-
-
- -
+
diff --git a/config/servicewatchdog/services_servicewatchdog_add.php b/config/servicewatchdog/services_servicewatchdog_add.php index 11e5e284..8773a367 100644 --- a/config/servicewatchdog/services_servicewatchdog_add.php +++ b/config/servicewatchdog/services_servicewatchdog_add.php @@ -55,7 +55,7 @@ unset($input_errors); if ($_POST) { if (!is_numeric($_POST['svcid'])) - + if (!isset($system_services[$_POST['svcid']])) { $input_errors[] = gettext("The supplied service appears to be invalid."); @@ -72,7 +72,7 @@ if ($_POST) { } $closehead = false; -$pgtitle = array(gettext("Services"),gettext("servicewatchdog"), gettext("Add")); +$pgtitle = array(gettext("Services"), gettext("servicewatchdog"), gettext("Add")); include("head.inc"); ?> diff --git a/config/servicewatchdog/servicewatchdog.inc b/config/servicewatchdog/servicewatchdog.inc index 5b638836..817b92e0 100644 --- a/config/servicewatchdog/servicewatchdog.inc +++ b/config/servicewatchdog/servicewatchdog.inc @@ -7,23 +7,27 @@ require_once("notices.inc"); function servicewatchdog_service_matches($svc1, $svc2) { /* If the arrays are equal, it must be the same service. */ - if ($svc1 == $svc2) + if ($svc1 == $svc2) { return true; + } /* If the names are different, they must not be the same. */ - if ($svc1['name'] != $svc2['name']) + if ($svc1['name'] != $svc2['name']) { return false; + } switch ($svc1['name']) { case "openvpn": - if (($svc1['mode'] == $svc2['mode']) && ($svc1['vpnid'] == $svc2['vpnid'])) + if (($svc1['mode'] == $svc2['mode']) && ($svc1['vpnid'] == $svc2['vpnid'])) { return true; - else + } else { return false; + } break; case "captiveportal": - if ($svc1['zone'] == $svc2['zone']) + if ($svc1['zone'] == $svc2['zone']) { return true; - else + } else { return false; + } break; default: /* Other services must be the same if the name matches. */ @@ -39,12 +43,14 @@ function servicewatchdog_is_service_watched($svc) { $a_pwservices = &$config['installedpackages']['servicewatchdog']['item']; $blacklisted_services = array("cron"); - if (empty($svc['name']) || in_array($svc['name'], $blacklisted_services)) + if (empty($svc['name']) || in_array($svc['name'], $blacklisted_services)) { return true; + } foreach ($a_pwservices as $a_svc) { - if (servicewatchdog_service_matches($svc, $a_svc)) + if (servicewatchdog_service_matches($svc, $a_svc)) { return true; + } } return false; } @@ -77,8 +83,9 @@ function servicewatchdog_check_services() { $descr = strlen($svc['description']) > 50 ? substr($svc['description'], 0, 50) . "..." : $svc['description']; $error_message = "Service Watchdog detected service {$svc['name']} stopped. Restarting {$svc['name']} ({$descr})"; log_error($error_message); - if (isset($svc['notify'])) + if (isset($svc['notify'])) { notify_via_smtp($error_message); + } service_control_start($svc['name'], $svc); } } diff --git a/config/servicewatchdog/servicewatchdog.xml b/config/servicewatchdog/servicewatchdog.xml index 685ba997..5a1aebbb 100644 --- a/config/servicewatchdog/servicewatchdog.xml +++ b/config/servicewatchdog/servicewatchdog.xml @@ -40,7 +40,7 @@ None Monitors for stopped services and restarts them. Service Watchdog - 1.6 + 1.7 Services: Service Watchdog /usr/local/pkg/servicewatchdog.inc diff --git a/config/servicewatchdog/servicewatchdog_cron.php b/config/servicewatchdog/servicewatchdog_cron.php index 004afd97..9979917e 100644 --- a/config/servicewatchdog/servicewatchdog_cron.php +++ b/config/servicewatchdog/servicewatchdog_cron.php @@ -6,8 +6,9 @@ require_once("servicewatchdog.inc"); global $g; /* Do nothing at bootup. */ -if ($g['booting'] || file_exists("{$g['varrun_path']}/booting")) +if ($g['booting'] || file_exists("{$g['varrun_path']}/booting")) { return; +} servicewatchdog_check_services(); ?> \ No newline at end of file -- cgit v1.2.3