Commit 1942d1f0 authored by Franco Fichtner's avatar Franco Fichtner

services: migrate service start commands to array

(cherry picked from commit 60f0f461)
parent ebf076e1
......@@ -2555,6 +2555,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "radvd";
$pconfig['description'] = gettext("Router Advertisement Daemon");
$pconfig['php']['start'] = array('services_radvd_configure');
$services[] = $pconfig;
}
......@@ -2562,6 +2563,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dnsmasq";
$pconfig['description'] = gettext("DNS Forwarder");
$pconfig['php']['start'] = array('services_dnsmasq_configure');
$services[] = $pconfig;
}
......@@ -2569,12 +2571,14 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "unbound";
$pconfig['description'] = gettext("Unbound DNS Resolver");
$pconfig['php']['start'] = array('services_unbound_configure');
$services[] = $pconfig;
}
$pconfig = array();
$pconfig['name'] = "ntpd";
$pconfig['description'] = gettext("NTP clock sync");
$pconfig['php']['start'] = array('system_ntp_configure');
$pconfig['pidfile'] = '/var/run/ntpd.pid';
$services[] = $pconfig;
......@@ -2591,6 +2595,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dhcrelay";
$pconfig['description'] = gettext("DHCP Relay");
$pconfig['php']['start'] = array('services_dhcrelay_configure');
$services[] = $pconfig;
}
......@@ -2599,6 +2604,7 @@ function services_get()
$pconfig['name'] = "dhcrelay6";
$pconfig['description'] = gettext("DHCPv6 Relay");
$pconfig['pidfile'] = '/var/run/dhcrelay6.pid';
$pconfig['php']['start'] = array('services_dhcrelay6_configure');
$services[] = $pconfig;
}
......@@ -2606,6 +2612,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dhcpd";
$pconfig['description'] = gettext("DHCP Service");
$pconfig['php']['start'] = array('services_dhcpd_configure');
$services[] = $pconfig;
}
......@@ -2621,6 +2628,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "bsnmpd";
$pconfig['description'] = gettext("SNMP Service");
$pconfig['php']['start'] = array('services_snmpd_configure');
$services[] = $pconfig;
}
......@@ -2628,6 +2636,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "igmpproxy";
$pconfig['description'] = gettext("IGMP proxy");
$pconfig['php']['start'] = array('services_igmpproxy_configure');
$services[] = $pconfig;
}
......@@ -2643,6 +2652,7 @@ function services_get()
$pconfig['name'] = "ipsec";
$pconfig['description'] = gettext("IPsec VPN");
$pconfig['pidfile'] = '/var/run/charon.pid';
$pconfig['php']['start'] = array('vpn_ipsec_force_reload');
$services[] = $pconfig;
}
......@@ -2675,15 +2685,30 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "relayd";
$pconfig['description'] = gettext("Server load balancing daemon");
$pconfig['php']['start'] = array('relayd_configure', 'filter_configure');
$services[] = $pconfig;
}
if (isset($config['OPNsense']['proxy']['general']['enabled']) && $config['OPNsense']['proxy']['general']['enabled'] == 1) {
$services[] = array('name'=>'squid', 'description' => gettext("Proxy server"));
$services[] = array(
'description' => gettext('Proxy server'),
'configd' => array(
'start' => array('proxy start'),
),
'name' => 'squid',
);
}
if (isset($config['OPNsense']['IDS']['general']['enabled']) && $config['OPNsense']['IDS']['general']['enabled'] == 1) {
$services[] = array('name'=>'suricata', 'description' => gettext("Intrusion Detection"));
$services[] = array(
'description' => gettext('Intrusion Detection'),
'configd' => array(
'start' => array('ids start'),
),
'name' => 'suricata',
);
}
if (isset($config['OPNsense']['captiveportal']['zones']['zone'])) {
$enabled = false;
if (!empty($config['OPNsense']['captiveportal']['zones']['zone']['enabled'])) {
......@@ -2701,6 +2726,9 @@ function services_get()
$services[] = array(
'pidfile' => '/var/run/lighttpd-api-dispatcher.pid',
'description' => gettext('Captive Portal'),
'confidg' => array(
'start' => array('captiveportal start'),
),
'name' => 'captiveportal',
);
}
......
......@@ -71,6 +71,8 @@ if (!empty($_GET['service'])) {
function service_control_start($name, $extras)
{
$msg = sprintf(gettext('%s has been started.'), htmlspecialchars($name));
/* XXX openvpn is handled special at the moment */
if ($name == 'openvpn') {
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
......@@ -81,8 +83,11 @@ function service_control_start($name, $extras)
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
return sprintf(gettext('%s has been started.'), htmlspecialchars($name));
return $msg;
/* XXX extra argument is extra tricky */
} elseif ($name == 'miniupnpd') {
upnp_action('start');
return $msg;
}
$service = find_service_by_name($name);
......@@ -94,75 +99,19 @@ function service_control_start($name, $extras)
foreach ($service['configd']['start'] as $cmd) {
configd_run($cmd);
}
/* XXX fall through later */
return sprintf(gettext('%s has been started via configd.'), htmlspecialchars($name));
} elseif (isset($service['php']['start'])) {
foreach ($service['php']['start'] as $cmd) {
$cmd();
}
/* XXX fall through later */
return sprintf(gettext('%s has been started via php.'), htmlspecialchars($name));
} elseif (isset($service['mwexec']['start'])) {
foreach ($service['mwexec']['start'] as $cmd) {
mwexec($cmd);
}
/* XXX fall through later */
return sprintf(gettext('%s has been started via mwexec.'), htmlspecialchars($name));
}
/* XXX migrate all of those */
switch ($service['name']) {
case 'radvd':
services_radvd_configure();
break;
case 'ntpd':
system_ntp_configure();
break;
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_action('start');
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'relayd':
relayd_configure();
filter_configure();
break;
case 'squid':
configd_run("proxy start");
break;
case 'suricata':
configd_run("ids start");
break;
case 'captiveportal':
configd_run("captiveportal start");
break;
default:
return sprintf(gettext("Could not launch service `%s'"), htmlspecialchars($name));
} else {
$msg = printf(gettext("Could not launch service `%s'"), htmlspecialchars($name));
}
return sprintf(gettext('%s has been started.'), 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