Commit de888244 authored by Franco Fichtner's avatar Franco Fichtner

services: adapt stop commands to new approach

parent 60f0f461
...@@ -2540,7 +2540,7 @@ function is_apinger_enabled() ...@@ -2540,7 +2540,7 @@ function is_apinger_enabled()
function services_get() function services_get()
{ {
global $config; global $config, $g;
$services = array(); $services = array();
...@@ -2549,6 +2549,7 @@ function services_get() ...@@ -2549,6 +2549,7 @@ function services_get()
$pconfig['name'] = "radvd"; $pconfig['name'] = "radvd";
$pconfig['description'] = gettext("Router Advertisement Daemon"); $pconfig['description'] = gettext("Router Advertisement Daemon");
$pconfig['php']['start'] = array('services_radvd_configure'); $pconfig['php']['start'] = array('services_radvd_configure');
$pconfig['pidfile'] = '/var/run/radvd.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2557,6 +2558,7 @@ function services_get() ...@@ -2557,6 +2558,7 @@ function services_get()
$pconfig['name'] = "dnsmasq"; $pconfig['name'] = "dnsmasq";
$pconfig['description'] = gettext("DNS Forwarder"); $pconfig['description'] = gettext("DNS Forwarder");
$pconfig['php']['start'] = array('services_dnsmasq_configure'); $pconfig['php']['start'] = array('services_dnsmasq_configure');
$pconfig['pidfile'] = '/var/run/dnsmasq.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2565,6 +2567,7 @@ function services_get() ...@@ -2565,6 +2567,7 @@ function services_get()
$pconfig['name'] = "unbound"; $pconfig['name'] = "unbound";
$pconfig['description'] = gettext("Unbound DNS Resolver"); $pconfig['description'] = gettext("Unbound DNS Resolver");
$pconfig['php']['start'] = array('services_unbound_configure'); $pconfig['php']['start'] = array('services_unbound_configure');
$pconfig['pidfile'] = '/var/run/unbound.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2589,6 +2592,7 @@ function services_get() ...@@ -2589,6 +2592,7 @@ function services_get()
$pconfig['name'] = "dhcrelay"; $pconfig['name'] = "dhcrelay";
$pconfig['description'] = gettext("DHCP Relay"); $pconfig['description'] = gettext("DHCP Relay");
$pconfig['php']['start'] = array('services_dhcrelay_configure'); $pconfig['php']['start'] = array('services_dhcrelay_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2596,8 +2600,8 @@ function services_get() ...@@ -2596,8 +2600,8 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "dhcrelay6"; $pconfig['name'] = "dhcrelay6";
$pconfig['description'] = gettext("DHCPv6 Relay"); $pconfig['description'] = gettext("DHCPv6 Relay");
$pconfig['pidfile'] = '/var/run/dhcrelay6.pid';
$pconfig['php']['start'] = array('services_dhcrelay6_configure'); $pconfig['php']['start'] = array('services_dhcrelay6_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay6.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2606,6 +2610,7 @@ function services_get() ...@@ -2606,6 +2610,7 @@ function services_get()
$pconfig['name'] = "dhcpd"; $pconfig['name'] = "dhcpd";
$pconfig['description'] = gettext("DHCP Service"); $pconfig['description'] = gettext("DHCP Service");
$pconfig['php']['start'] = array('services_dhcpd_configure'); $pconfig['php']['start'] = array('services_dhcpd_configure');
$pconfig['pidfile'] = "{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid";
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2614,6 +2619,7 @@ function services_get() ...@@ -2614,6 +2619,7 @@ function services_get()
$pconfig['name'] = "apinger"; $pconfig['name'] = "apinger";
$pconfig['description'] = gettext("Gateway Monitoring Daemon"); $pconfig['description'] = gettext("Gateway Monitoring Daemon");
$pconfig['php']['start'] = array('setup_gateways_monitor'); $pconfig['php']['start'] = array('setup_gateways_monitor');
$pconfig['pidfile'] = '/var/run/apinger.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2622,6 +2628,7 @@ function services_get() ...@@ -2622,6 +2628,7 @@ function services_get()
$pconfig['name'] = "bsnmpd"; $pconfig['name'] = "bsnmpd";
$pconfig['description'] = gettext("SNMP Service"); $pconfig['description'] = gettext("SNMP Service");
$pconfig['php']['start'] = array('services_snmpd_configure'); $pconfig['php']['start'] = array('services_snmpd_configure');
$pconfig['pidfile'] = '/var/run/snmpd.pid';
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2646,6 +2653,7 @@ function services_get() ...@@ -2646,6 +2653,7 @@ function services_get()
$pconfig['description'] = gettext("IPsec VPN"); $pconfig['description'] = gettext("IPsec VPN");
$pconfig['pidfile'] = '/var/run/charon.pid'; $pconfig['pidfile'] = '/var/run/charon.pid';
$pconfig['php']['start'] = array('vpn_ipsec_force_reload'); $pconfig['php']['start'] = array('vpn_ipsec_force_reload');
$pconfig['mwexec']['stop'] = array('/usr/local/sbin/ipsec stop');
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2687,6 +2695,7 @@ function services_get() ...@@ -2687,6 +2695,7 @@ function services_get()
'description' => gettext('Proxy server'), 'description' => gettext('Proxy server'),
'configd' => array( 'configd' => array(
'start' => array('proxy start'), 'start' => array('proxy start'),
'stop' => array('proxy stop'),
), ),
'name' => 'squid', 'name' => 'squid',
); );
...@@ -2697,6 +2706,7 @@ function services_get() ...@@ -2697,6 +2706,7 @@ function services_get()
'description' => gettext('Intrusion Detection'), 'description' => gettext('Intrusion Detection'),
'configd' => array( 'configd' => array(
'start' => array('ids start'), 'start' => array('ids start'),
'stop' => array('ids stop'),
), ),
'name' => 'suricata', 'name' => 'suricata',
); );
...@@ -2721,6 +2731,7 @@ function services_get() ...@@ -2721,6 +2731,7 @@ function services_get()
'description' => gettext('Captive Portal'), 'description' => gettext('Captive Portal'),
'confidg' => array( 'confidg' => array(
'start' => array('captiveportal start'), 'start' => array('captiveportal start'),
'stop' => array('captiveportal stop'),
), ),
'name' => 'captiveportal', 'name' => 'captiveportal',
); );
......
...@@ -108,57 +108,26 @@ function service_control_start($name, $extras) ...@@ -108,57 +108,26 @@ function service_control_start($name, $extras)
mwexec($cmd); mwexec($cmd);
} }
} else { } else {
$msg = printf(gettext("Could not launch service `%s'"), htmlspecialchars($name)); $msg = sprintf(gettext("Could not launch service `%s'"), htmlspecialchars($name));
} }
return $msg; 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) {
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;
case 'igmpproxy': case 'igmpproxy':
killbyname("igmpproxy"); killbyname("igmpproxy");
break; return $msg;
case 'miniupnpd': case 'miniupnpd':
upnp_action('stop'); upnp_action('stop');
break; return $msg;
case 'sshd': case 'sshd':
killbyname("sshd"); killbyname("sshd");
break; return $msg;
case 'ipsec':
exec("/usr/local/sbin/ipsec stop");
break;
case 'openvpn': case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']); $vpnmode = htmlspecialchars($extras['vpnmode']);
if (($vpnmode == "server") or ($vpnmode == "client")) { if (($vpnmode == "server") or ($vpnmode == "client")) {
...@@ -166,27 +135,38 @@ function service_control_stop($name, $extras) { ...@@ -166,27 +135,38 @@ function service_control_stop($name, $extras) {
$pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid"; $pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid";
killbypid($pidfile); killbypid($pidfile);
} }
break; return $msg;
case 'relayd': case 'relayd':
mwexec('pkill relayd'); killbyname('relayd');
break; return $msg;
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;
default: default:
log_error(sprintf(gettext("Could not stop unknown service `%s'"), $name));
break; 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;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment