diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index e5937fb1a..6154099d9 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -2540,7 +2540,7 @@ function is_apinger_enabled() function services_get() { - global $config; + global $config, $g; $services = array(); @@ -2549,6 +2549,7 @@ function services_get() $pconfig['name'] = "radvd"; $pconfig['description'] = gettext("Router Advertisement Daemon"); $pconfig['php']['start'] = array('services_radvd_configure'); + $pconfig['pidfile'] = '/var/run/radvd.pid'; $services[] = $pconfig; } @@ -2557,6 +2558,7 @@ function services_get() $pconfig['name'] = "dnsmasq"; $pconfig['description'] = gettext("DNS Forwarder"); $pconfig['php']['start'] = array('services_dnsmasq_configure'); + $pconfig['pidfile'] = '/var/run/dnsmasq.pid'; $services[] = $pconfig; } @@ -2565,6 +2567,7 @@ function services_get() $pconfig['name'] = "unbound"; $pconfig['description'] = gettext("Unbound DNS Resolver"); $pconfig['php']['start'] = array('services_unbound_configure'); + $pconfig['pidfile'] = '/var/run/unbound.pid'; $services[] = $pconfig; } @@ -2589,6 +2592,7 @@ function services_get() $pconfig['name'] = "dhcrelay"; $pconfig['description'] = gettext("DHCP Relay"); $pconfig['php']['start'] = array('services_dhcrelay_configure'); + $pconfig['pidfile'] = '/var/run/dhcrelay.pid'; $services[] = $pconfig; } @@ -2596,8 +2600,8 @@ function services_get() $pconfig = array(); $pconfig['name'] = "dhcrelay6"; $pconfig['description'] = gettext("DHCPv6 Relay"); - $pconfig['pidfile'] = '/var/run/dhcrelay6.pid'; $pconfig['php']['start'] = array('services_dhcrelay6_configure'); + $pconfig['pidfile'] = '/var/run/dhcrelay6.pid'; $services[] = $pconfig; } @@ -2606,6 +2610,7 @@ function services_get() $pconfig['name'] = "dhcpd"; $pconfig['description'] = gettext("DHCP Service"); $pconfig['php']['start'] = array('services_dhcpd_configure'); + $pconfig['pidfile'] = "{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid"; $services[] = $pconfig; } @@ -2614,6 +2619,7 @@ function services_get() $pconfig['name'] = "apinger"; $pconfig['description'] = gettext("Gateway Monitoring Daemon"); $pconfig['php']['start'] = array('setup_gateways_monitor'); + $pconfig['pidfile'] = '/var/run/apinger.pid'; $services[] = $pconfig; } @@ -2622,6 +2628,7 @@ function services_get() $pconfig['name'] = "bsnmpd"; $pconfig['description'] = gettext("SNMP Service"); $pconfig['php']['start'] = array('services_snmpd_configure'); + $pconfig['pidfile'] = '/var/run/snmpd.pid'; $services[] = $pconfig; } @@ -2646,6 +2653,7 @@ function services_get() $pconfig['description'] = gettext("IPsec VPN"); $pconfig['pidfile'] = '/var/run/charon.pid'; $pconfig['php']['start'] = array('vpn_ipsec_force_reload'); + $pconfig['mwexec']['stop'] = array('/usr/local/sbin/ipsec stop'); $services[] = $pconfig; } @@ -2687,6 +2695,7 @@ function services_get() 'description' => gettext('Proxy server'), 'configd' => array( 'start' => array('proxy start'), + 'stop' => array('proxy stop'), ), 'name' => 'squid', ); @@ -2697,6 +2706,7 @@ function services_get() 'description' => gettext('Intrusion Detection'), 'configd' => array( 'start' => array('ids start'), + 'stop' => array('ids stop'), ), 'name' => 'suricata', ); @@ -2721,6 +2731,7 @@ function services_get() 'description' => gettext('Captive Portal'), 'confidg' => array( 'start' => array('captiveportal start'), + 'stop' => array('captiveportal stop'), ), 'name' => 'captiveportal', ); diff --git a/src/www/status_services.php b/src/www/status_services.php index 2fd3e88a1..ebc201690 100644 --- a/src/www/status_services.php +++ b/src/www/status_services.php @@ -108,57 +108,26 @@ function service_control_start($name, $extras) mwexec($cmd); } } else { - $msg = printf(gettext("Could not launch service `%s'"), htmlspecialchars($name)); + $msg = sprintf(gettext("Could not launch service `%s'"), htmlspecialchars($name)); } return $msg; } +function service_control_stop($name, $extras) +{ + $msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name)); -function service_control_stop($name, $extras) { - switch($name) { - case 'radvd': - killbypid("/var/run/radvd.pid"); - break; - case 'ntpd': - killbyname("ntpd"); - break; - case 'apinger': - killbypid("/var/run/apinger.pid"); - break; - case 'bsnmpd': - killbypid("/var/run/snmpd.pid"); - break; - case 'choparp': - killbyname("choparp"); - break; - case 'dhcpd': - killbyname("dhcpd"); - break; - case 'dhcrelay': - killbypid("/var/run/dhcrelay.pid"); - break; - case 'dhcrelay6': - killbypid("/var/run/dhcrelay6.pid"); - break; - case 'dnsmasq': - killbypid("/var/run/dnsmasq.pid"); - break; - case 'unbound': - killbypid("/var/run/unbound.pid"); - break; + switch ($name) { case 'igmpproxy': killbyname("igmpproxy"); - break; + return $msg; case 'miniupnpd': upnp_action('stop'); - break; + return $msg; case 'sshd': killbyname("sshd"); - break; - case 'ipsec': - exec("/usr/local/sbin/ipsec stop"); - break; + return $msg; case 'openvpn': $vpnmode = htmlspecialchars($extras['vpnmode']); if (($vpnmode == "server") or ($vpnmode == "client")) { @@ -166,27 +135,38 @@ function service_control_stop($name, $extras) { $pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid"; killbypid($pidfile); } - break; + return $msg; case 'relayd': - mwexec('pkill relayd'); - break; - case 'squid': - configd_run("proxy stop"); - break; - case 'suricata': - configd_run("ids stop"); - break; - case 'configd': - killbypid("/var/run/configd.pid"); - break; - case 'captiveportal': - configd_run("captiveportal stop"); - break; + killbyname('relayd'); + return $msg; default: - log_error(sprintf(gettext("Could not stop unknown service `%s'"), $name)); break; } - return sprintf(gettext("%s has been stopped."), htmlspecialchars($name)); + + $service = find_service_by_name($name); + if (!isset($service['name'])) { + return sprintf(gettext("Could not stop unknown service `%s'"), htmlspecialchars($name)); + } + + if (isset($service['configd']['stop'])) { + foreach ($service['configd']['stop'] as $cmd) { + configd_run($cmd); + } + } elseif (isset($service['php']['stop'])) { + foreach ($service['php']['stop'] as $cmd) { + $cmd(); + } + } elseif (isset($service['mwexec']['stop'])) { + foreach ($service['mwexec']['stop'] as $cmd) { + mwexec($cmd); + } + } elseif (isset($service['pidfile'])) { + killbypid($service['pidfile']); + } else { + $msg = sprintf(gettext("Could not stop service `%s'"), htmlspecialchars($name)); + } + + return $msg; }