Commit 9784c8b0 authored by Franco Fichtner's avatar Franco Fichtner

services: restructure restart, work in progress

parent f90e96f2
...@@ -2511,6 +2511,7 @@ function services_get() ...@@ -2511,6 +2511,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "radvd"; $pconfig['name'] = "radvd";
$pconfig['description'] = gettext("Router Advertisement Daemon"); $pconfig['description'] = gettext("Router Advertisement Daemon");
$pconfig['php']['restart'] = array('services_radvd_configure');
$pconfig['php']['start'] = array('services_radvd_configure'); $pconfig['php']['start'] = array('services_radvd_configure');
$pconfig['pidfile'] = '/var/run/radvd.pid'; $pconfig['pidfile'] = '/var/run/radvd.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2520,6 +2521,7 @@ function services_get() ...@@ -2520,6 +2521,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "dnsmasq"; $pconfig['name'] = "dnsmasq";
$pconfig['description'] = gettext("DNS Forwarder"); $pconfig['description'] = gettext("DNS Forwarder");
$pconfig['php']['restart'] = array('services_dnsmasq_configure');
$pconfig['php']['start'] = array('services_dnsmasq_configure'); $pconfig['php']['start'] = array('services_dnsmasq_configure');
$pconfig['pidfile'] = '/var/run/dnsmasq.pid'; $pconfig['pidfile'] = '/var/run/dnsmasq.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2529,6 +2531,7 @@ function services_get() ...@@ -2529,6 +2531,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "unbound"; $pconfig['name'] = "unbound";
$pconfig['description'] = gettext("Unbound DNS Resolver"); $pconfig['description'] = gettext("Unbound DNS Resolver");
$pconfig['php']['restart'] = array('services_unbound_configure');
$pconfig['php']['start'] = array('services_unbound_configure'); $pconfig['php']['start'] = array('services_unbound_configure');
$pconfig['pidfile'] = '/var/run/unbound.pid'; $pconfig['pidfile'] = '/var/run/unbound.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2537,6 +2540,7 @@ function services_get() ...@@ -2537,6 +2540,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "ntpd"; $pconfig['name'] = "ntpd";
$pconfig['description'] = gettext("NTP clock sync"); $pconfig['description'] = gettext("NTP clock sync");
$pconfig['php']['restart'] = array('system_ntp_configure');
$pconfig['php']['start'] = array('system_ntp_configure'); $pconfig['php']['start'] = array('system_ntp_configure');
$pconfig['pidfile'] = '/var/run/ntpd.pid'; $pconfig['pidfile'] = '/var/run/ntpd.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2554,6 +2558,7 @@ function services_get() ...@@ -2554,6 +2558,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "dhcrelay"; $pconfig['name'] = "dhcrelay";
$pconfig['description'] = gettext("DHCP Relay"); $pconfig['description'] = gettext("DHCP Relay");
$pconfig['php']['restart'] = array('services_dhcrelay_configure');
$pconfig['php']['start'] = array('services_dhcrelay_configure'); $pconfig['php']['start'] = array('services_dhcrelay_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay.pid'; $pconfig['pidfile'] = '/var/run/dhcrelay.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2563,6 +2568,7 @@ function services_get() ...@@ -2563,6 +2568,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "dhcrelay6"; $pconfig['name'] = "dhcrelay6";
$pconfig['description'] = gettext("DHCPv6 Relay"); $pconfig['description'] = gettext("DHCPv6 Relay");
$pconfig['php']['restart'] = array('services_dhcrelay6_configure');
$pconfig['php']['start'] = array('services_dhcrelay6_configure'); $pconfig['php']['start'] = array('services_dhcrelay6_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay6.pid'; $pconfig['pidfile'] = '/var/run/dhcrelay6.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2572,6 +2578,7 @@ function services_get() ...@@ -2572,6 +2578,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "dhcpd"; $pconfig['name'] = "dhcpd";
$pconfig['description'] = gettext("DHCP Service"); $pconfig['description'] = gettext("DHCP Service");
$pconfig['php']['restart'] = array('services_dhcpd_configure');
$pconfig['php']['start'] = array('services_dhcpd_configure'); $pconfig['php']['start'] = array('services_dhcpd_configure');
$pconfig['pidfile'] = "{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid"; $pconfig['pidfile'] = "{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid";
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2590,6 +2597,7 @@ function services_get() ...@@ -2590,6 +2597,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "bsnmpd"; $pconfig['name'] = "bsnmpd";
$pconfig['description'] = gettext("SNMP Service"); $pconfig['description'] = gettext("SNMP Service");
$pconfig['php']['restart'] = array('services_snmpd_configure');
$pconfig['php']['start'] = array('services_snmpd_configure'); $pconfig['php']['start'] = array('services_snmpd_configure');
$pconfig['pidfile'] = '/var/run/snmpd.pid'; $pconfig['pidfile'] = '/var/run/snmpd.pid';
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2599,6 +2607,7 @@ function services_get() ...@@ -2599,6 +2607,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "igmpproxy"; $pconfig['name'] = "igmpproxy";
$pconfig['description'] = gettext("IGMP proxy"); $pconfig['description'] = gettext("IGMP proxy");
$pconfig['php']['restart'] = array('services_igmpproxy_configure');
$pconfig['php']['start'] = array('services_igmpproxy_configure'); $pconfig['php']['start'] = array('services_igmpproxy_configure');
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2620,6 +2629,7 @@ function services_get() ...@@ -2620,6 +2629,7 @@ function services_get()
$pconfig['name'] = "ipsec"; $pconfig['name'] = "ipsec";
$pconfig['description'] = gettext("IPsec VPN"); $pconfig['description'] = gettext("IPsec VPN");
$pconfig['pidfile'] = '/var/run/charon.pid'; $pconfig['pidfile'] = '/var/run/charon.pid';
$pconfig['php']['restart'] = array('vpn_ipsec_force_reload');
$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'); $pconfig['mwexec']['stop'] = array('/usr/local/sbin/ipsec stop');
$services[] = $pconfig; $services[] = $pconfig;
...@@ -2629,6 +2639,7 @@ function services_get() ...@@ -2629,6 +2639,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = 'sshd'; $pconfig['name'] = 'sshd';
$pconfig['description'] = gettext('Secure Shell Daemon'); $pconfig['description'] = gettext('Secure Shell Daemon');
$pconfig['configd']['restart'] = array('sshd restart');
$pconfig['configd']['start'] = array('sshd restart'); $pconfig['configd']['start'] = array('sshd restart');
$services[] = $pconfig; $services[] = $pconfig;
} }
...@@ -2662,6 +2673,7 @@ function services_get() ...@@ -2662,6 +2673,7 @@ function services_get()
$services[] = array( $services[] = array(
'description' => gettext('Proxy server'), 'description' => gettext('Proxy server'),
'configd' => array( 'configd' => array(
'restart' => array('proxy restart'),
'start' => array('proxy start'), 'start' => array('proxy start'),
'stop' => array('proxy stop'), 'stop' => array('proxy stop'),
), ),
...@@ -2673,6 +2685,7 @@ function services_get() ...@@ -2673,6 +2685,7 @@ function services_get()
$services[] = array( $services[] = array(
'description' => gettext('Intrusion Detection'), 'description' => gettext('Intrusion Detection'),
'configd' => array( 'configd' => array(
'restart' => array('ids restart'),
'start' => array('ids start'), 'start' => array('ids start'),
'stop' => array('ids stop'), 'stop' => array('ids stop'),
), ),
...@@ -2698,6 +2711,7 @@ function services_get() ...@@ -2698,6 +2711,7 @@ function services_get()
'pidfile' => '/var/run/lighttpd-api-dispatcher.pid', 'pidfile' => '/var/run/lighttpd-api-dispatcher.pid',
'description' => gettext('Captive Portal'), 'description' => gettext('Captive Portal'),
'confidg' => array( 'confidg' => array(
'restart' => array('captiveportal restart'),
'start' => array('captiveportal start'), 'start' => array('captiveportal start'),
'stop' => array('captiveportal stop'), 'stop' => array('captiveportal stop'),
), ),
...@@ -2710,7 +2724,9 @@ function services_get() ...@@ -2710,7 +2724,9 @@ function services_get()
'description' => gettext('System Configuration Daemon'), 'description' => gettext('System Configuration Daemon'),
'pidfile' => '/var/run/configd.pid', 'pidfile' => '/var/run/configd.pid',
'mwexec' => array( 'mwexec' => array(
'restart' => array('/usr/local/etc/rc.d/configd restart'),
'start' => array('/usr/local/etc/rc.d/configd start'), 'start' => array('/usr/local/etc/rc.d/configd start'),
'stop' => array('/usr/local/etc/rc.d/configd stop'),
), ),
'name' => 'configd', 'name' => 'configd',
); );
......
...@@ -104,7 +104,7 @@ function service_control_start($name, $extras) ...@@ -104,7 +104,7 @@ function service_control_start($name, $extras)
mwexec($cmd); mwexec($cmd);
} }
} else { } else {
$msg = sprintf(gettext("Could not launch service `%s'"), htmlspecialchars($name)); $msg = sprintf(gettext("Could not start service `%s'"), htmlspecialchars($name));
} }
return $msg; return $msg;
...@@ -148,49 +148,16 @@ function service_control_stop($name, $extras) ...@@ -148,49 +148,16 @@ function service_control_stop($name, $extras)
} }
function service_control_restart($name, $extras) { function service_control_restart($name, $extras)
{
$msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
/* XXX clean this up */
switch($name) { switch($name) {
case 'radvd':
services_radvd_configure();
break;
case 'ntpd':
system_ntp_configure();
break;
case 'apinger': case 'apinger':
killbypid("/var/run/apinger.pid"); killbypid("/var/run/apinger.pid");
setup_gateways_monitor(); setup_gateways_monitor();
break; return $msg;
case 'bsnmpd':
services_snmpd_configure();
break;
case 'dhcrelay':
services_dhcrelay_configure();
break;
case 'dhcrelay6':
services_dhcrelay6_configure();
break;
case 'dnsmasq':
services_dnsmasq_configure();
break;
case 'unbound':
services_unbound_configure();
break;
case 'dhcpd':
services_dhcpd_configure();
break;
case 'igmpproxy':
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_stop();
upnp_start();
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'sshd':
configd_run("sshd restart");
break;
case 'openvpn': case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']); $vpnmode = htmlspecialchars($extras['vpnmode']);
if ($vpnmode == "server" || $vpnmode == "client") { if ($vpnmode == "server" || $vpnmode == "client") {
...@@ -200,28 +167,37 @@ function service_control_restart($name, $extras) { ...@@ -200,28 +167,37 @@ function service_control_restart($name, $extras) {
openvpn_restart_by_vpnid($vpnmode, $id); openvpn_restart_by_vpnid($vpnmode, $id);
} }
} }
break; return $msg;
case 'relayd': case 'relayd':
relayd_configure(true); relayd_configure(true);
filter_configure(); filter_configure();
break; return $msg;
case 'squid':
configd_run("proxy restart");
break;
case 'suricata':
configd_run("ids restart");
break;
case 'configd':
mwexec('/usr/local/etc/rc.d/configd restart');
break;
case 'captiveportal':
configd_run("captiveportal restart");
break;
default: default:
log_error(sprintf(gettext("Could not restart unknown service `%s'"), $name));
break; break;
} }
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
$service = find_service_by_name($name);
if (!isset($service['name'])) {
return sprintf(gettext("Could not restart unknown service `%s'"), htmlspecialchars($name));
}
if (isset($service['configd']['restart'])) {
foreach ($service['configd']['restart'] as $cmd) {
configd_run($cmd);
}
} elseif (isset($service['php']['restart'])) {
foreach ($service['php']['restart'] as $cmd) {
$cmd();
}
} elseif (isset($service['mwexec']['restart'])) {
foreach ($service['mwexec']['restart'] as $cmd) {
mwexec($cmd);
}
} else {
$msg = sprintf(gettext("Could not restart service `%s'"), htmlspecialchars($name));
}
return $msg;
} }
$services = services_get(); $services = services_get();
......
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