From e3cf528ecd6175d107c7930e0fb10a5ad3f8d94d Mon Sep 17 00:00:00 2001 From: bcyrill Date: Sat, 9 Jun 2012 22:02:39 +0200 Subject: Added Captiveportal to service status --- etc/inc/captiveportal.inc | 21 ++++++--- usr/local/www/status_services.php | 90 +++++++++++++++++++++++++-------------- 2 files changed, 74 insertions(+), 37 deletions(-) diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc index 45f1402..7ae3a18 100644 --- a/etc/inc/captiveportal.inc +++ b/etc/inc/captiveportal.inc @@ -368,7 +368,7 @@ EOD; captiveportal_write_elements(); /* start up the webserving daemon */ - captiveportal_init_webguis($cpcfg); + captiveportal_init_webgui_zone($cpcfg); /* Kill any existing prunecaptiveportal processes */ if(file_exists("{$g['varrun_path']}/cp_prunedb_{$cpzone}.pid")) @@ -429,17 +429,26 @@ function captiveportal_init_webgui() { global $config, $cpzone; if (is_array($config['captiveportal'])) { - foreach ($config['captiveportal'] as $cpkey => $cp) { + foreach ($config['captiveportal'] as $cpkey => $cp) { $cpzone = $cpkey; - captiveportal_init_webguis($cp); + captiveportal_init_webgui_zone($cp); } } } -function captiveportal_init_webguis($cpcfg) { +function captiveportal_init_webgui_zonename($zone) { + global $config, $cpzone; + + if (isset($config['captiveportal'][$zone])) { + $cpzone = $zone; + captiveportal_init_webgui_zone($config['captiveportal'][$zone]); + } +} + +function captiveportal_init_webgui_zone($cpcfg) { global $g, $config, $cpzone; - if (!isset($cpcfg['enable'])) + if (!isset($cpcfg['enable'])) return; $use_fastcgi = true; @@ -468,7 +477,7 @@ function captiveportal_init_webguis($cpcfg) { $res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-{$cpzone}-CaptivePortal.conf"); /* fire up https instance */ - if (isset($cpcfg['httpslogin'])) + if (isset($cpcfg['httpslogin']) && $cpcfg['httpslogin']) $res = mwexec("/usr/local/sbin/lighttpd -f {$g['varetc_path']}/lighty-{$cpzone}-CaptivePortal-SSL.conf"); } diff --git a/usr/local/www/status_services.php b/usr/local/www/status_services.php index ea0a261..4f90c46 100755 --- a/usr/local/www/status_services.php +++ b/usr/local/www/status_services.php @@ -63,9 +63,10 @@ function get_pkg_descr($package_name) { if($_GET['mode'] == "restartservice" and !empty($_GET['service'])) { switch($_GET['service']) { case 'captiveportal': - killbypid("{$g['varrun_path']}/lighty-CaptivePortal.pid"); - killbypid("{$g['varrun_path']}/lighty-CaptivePortal-SSL.pid"); - captiveportal_init_webgui(); + $zone = $_GET['zone']; + killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid"); + killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid"); + captiveportal_init_webgui_zonename($zone); break; case 'ntpd': case 'openntpd': @@ -116,12 +117,13 @@ if($_GET['mode'] == "restartservice" and !empty($_GET['service'])) { if($_GET['mode'] == "startservice" and !empty($_GET['service'])) { switch($_GET['service']) { case 'captiveportal': - captiveportal_init_webgui(); + $zone = $_GET['zone']; + captiveportal_init_webgui_zonename($zone); break; case 'ntpd': case 'openntpd': system_ntp_configure(); - break; + break; case 'bsnmpd': services_snmpd_configure(); break; @@ -164,8 +166,9 @@ if($_GET['mode'] == "startservice" and !empty($_GET['service'])) { if($_GET['mode'] == "stopservice" && !empty($_GET['service'])) { switch($_GET['service']) { case 'captiveportal': - killbypid("{$g['varrun_path']}/lighty-CaptivePortal.pid"); - killbypid("{$g['varrun_path']}/lighty-CaptivePortal-SSL.pid"); + $zone = $_GET['zone']; + killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal.pid"); + killbypid("{$g['varrun_path']}/lighty-{$zone}-CaptivePortal-SSL.pid"); break; case 'ntpd': killbyname("ntpd"); @@ -269,11 +272,16 @@ $pconfig['name'] = "ntpd"; $pconfig['description'] = gettext("NTP clock sync"); $services[] = $pconfig; -if(isset($config['captiveportal']['enable'])) { - $pconfig = array(); - $pconfig['name'] = "captiveportal"; - $pconfig['description'] = gettext("Captive Portal"); - $services[] = $pconfig; +if (is_array($config['captiveportal'])) { + foreach ($config['captiveportal'] as $id => $setting) { + if (isset($setting['enable'])) { + $pconfig = array(); + $pconfig['name'] = "captiveportal"; + $pconfig['zone'] = $setting['zone']; + $pconfig['description'] = gettext("Captive Portal") . ": ".htmlspecialchars($setting['zone']); + $services[] = $pconfig; + } + } } $iflist = array(); @@ -369,12 +377,18 @@ if (count($services) > 0) { $service['description'] = get_pkg_descr($service['name']); echo '' . $service['name'] . '' . "\n"; echo '' . $service['description'] . '' . "\n"; - if ($service['name'] == "openvpn") - $running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid"); - else if ($service['name'] == "captiveportal") - $running = is_pid_running("{$g['varrun_path']}/lighty-CaptivePortal.pid"); - else - $running = is_service_running($service['name']); + switch ($service['name']) { + case "openvpn": + $running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid"); + if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) + $running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid"); + break; + case "captiveportal": + $running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid"); + break; + default: + $running = is_service_running($service['name']); + } if($running) { echo "\n"; echo " " . gettext("Running") . "\n"; @@ -384,26 +398,40 @@ if (count($services) > 0) { } echo ''; if($running) { - if ($service['name'] == "openvpn") { - echo ""; - } else { - echo ""; + switch ($service['name']) { + case "openvpn": + echo ""; + break; + case "captiveportal": + echo ""; + break; + default: + echo ""; } echo "\n"; - if ($service['name'] == "openvpn") { - echo ""; - } else { - echo ""; + switch ($service['name']) { + case "openvpn": + echo ""; + break; + case "captiveportal": + echo ""; + break; + default: + echo ""; } echo ""; echo ""; } else { - if ($service['name'] == "openvpn") { - echo ""; - } else { - echo " "; + switch ($service['name']) { + case "openvpn": + echo ""; + break; + case "captiveportal": + echo ""; + break; + default: + echo ""; } - echo "\n"; } echo "\n"; -- cgit v1.1