Commit a6253b14 authored by Franco Fichtner's avatar Franco Fichtner

services: adapt stop commands to new approach

(cherry picked from commit de888244)
parent 1942d1f0
......@@ -2547,7 +2547,7 @@ function is_apinger_enabled()
function services_get()
{
global $config;
global $config, $g;
$services = array();
......@@ -2556,6 +2556,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;
}
......@@ -2564,6 +2565,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;
}
......@@ -2572,6 +2574,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;
}
......@@ -2596,6 +2599,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;
}
......@@ -2603,8 +2607,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;
}
......@@ -2613,6 +2617,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;
}
......@@ -2621,6 +2626,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;
}
......@@ -2629,6 +2635,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;
}
......@@ -2653,6 +2660,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;
}
......@@ -2694,6 +2702,7 @@ function services_get()
'description' => gettext('Proxy server'),
'configd' => array(
'start' => array('proxy start'),
'stop' => array('proxy stop'),
),
'name' => 'squid',
);
......@@ -2704,6 +2713,7 @@ function services_get()
'description' => gettext('Intrusion Detection'),
'configd' => array(
'start' => array('ids start'),
'stop' => array('ids stop'),
),
'name' => 'suricata',
);
......@@ -2728,6 +2738,7 @@ function services_get()
'description' => gettext('Captive Portal'),
'confidg' => array(
'start' => array('captiveportal start'),
'stop' => array('captiveportal stop'),
),
'name' => 'captiveportal',
);
......
......@@ -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;
}
......
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