Commit 36b9cb78 authored by Franco Fichtner's avatar Franco Fichtner

inc: remove more legacy package service glue

parent c4782349
...@@ -34,166 +34,6 @@ require_once("vpn.inc"); ...@@ -34,166 +34,6 @@ require_once("vpn.inc");
require_once("vslb.inc"); require_once("vslb.inc");
require_once("gwlb.inc"); require_once("gwlb.inc");
define("RCFILEPREFIX", "/usr/local/etc/rc.d/");
if (!function_exists('write_rcfile')) {
function write_rcfile($params) {
global $g;
safe_mkdir(RCFILEPREFIX);
$rcfile_fullname = RCFILEPREFIX . $params['file'];
if (!file_exists($rcfile_fullname) && !is_link($rcfile_fullname) && !touch($rcfile_fullname))
return false;
if (!is_writable($rcfile_fullname) || empty($params['start']))
return false;
$towrite = "#!/bin/sh\n";
$towrite .= "# This file was automatically generated\n# by the {$g['product_name']} service handler.\n\n";
/* write our rc functions */
$towrite .= "rc_start() {\n";
$towrite .= "\t{$params['start']}\n";
$towrite .= "}\n\n";
if(!empty($params['stop'])) {
$tokill =& $params['stop'];
} else if(!empty($params['executable'])) {
/* just nuke the executable */
$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
} else {
/* make an educated guess (bad) */
$tokill = array_pop(explode('/', array_shift(explode(' ', $params['start']))));
}
$towrite .= "rc_stop() {\n";
$towrite .= "\t{$tokill}\n";
$towrite .= "}\n\n";
/* begin rcfile logic */
$towrite .= "case \$1 in\n\tstart)\n\t\trc_start\n\t\t;;\n\tstop)\n\t\trc_stop\n\t\t;;\n\trestart)\n\t\trc_stop\n\t\trc_start\n\t\t;;\nesac\n\n";
@file_put_contents($rcfile_fullname, $towrite);
unset($towrite);
@chmod("{$rcfile_fullname}", 0755);
return;
}
}
if (!function_exists('start_service')) {
function start_service($name) {
global $config;
if (empty($name))
return;
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
foreach($config['installedpackages']['service'] as $service) {
if(strtolower($service['name']) == strtolower($name)) {
if($service['rcfile']) {
$prefix = RCFILEPREFIX;
if (!empty($service['prefix'])) {
$prefix =& $service['prefix'];
}
if(file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
mwexec_bg("{$prefix}{$service['rcfile']} start");
}
}
if (!empty($service['startcmd']))
eval($service['startcmd']);
break;
}
}
}
}
}
if (!function_exists('stop_service')) {
function stop_service($name) {
global $config;
if (empty($name))
return;
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
foreach($config['installedpackages']['service'] as $service) {
if(strtolower($service['name']) == strtolower($name)) {
if($service['rcfile']) {
$prefix = RCFILEPREFIX;
if(!empty($service['prefix'])) {
$prefix =& $service['prefix'];
}
if(file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
mwexec("{$prefix}{$service['rcfile']} stop");
}
return;
}
if (!empty($service['stopcmd']))
eval($service['stopcmd']);
break;
}
}
}
}
}
if (!function_exists('restart_service')) {
function restart_service($name) {
global $config;
if (empty($name))
return;
stop_service($name);
start_service($name);
if (is_array($config['installedpackages']) && is_array($config['installedpackages']['service'])) {
foreach($config['installedpackages']['service'] as $service) {
if(strtolower($service['name']) == strtolower($name)) {
if($service['restartcmd']) {
eval($service['restartcmd']);
}
break;
}
}
}
}
}
if (!function_exists('is_pid_running')) {
function is_pid_running($pidfile) {
if (!file_exists($pidfile))
return false;
return (isvalidpid($pidfile));
}
}
if (!function_exists('is_dhcp_running')) {
function is_dhcp_running($interface) {
$status = find_dhclient_process($interface);
if($status != 0)
return true;
return false;
}
}
if (!function_exists('restart_service_if_running')) {
function restart_service_if_running($service) {
global $config;
if(is_service_running($service))
restart_service($service);
return;
}
}
if (!function_exists('is_service_enabled')) { if (!function_exists('is_service_enabled')) {
function is_service_enabled($service_name) { function is_service_enabled($service_name) {
...@@ -473,21 +313,21 @@ if (!function_exists('get_service_status')) { ...@@ -473,21 +313,21 @@ if (!function_exists('get_service_status')) {
global $g; global $g;
switch ($service['name']) { switch ($service['name']) {
case "openvpn": case "openvpn":
$running = is_pid_running("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid"); $running = isvalidpid("{$g['varrun_path']}/openvpn_{$service['mode']}{$service['vpnid']}.pid");
break; break;
case "captiveportal": case "captiveportal":
$running = is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid"); $running = isvalidpid("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal.pid");
if (isset($config['captiveportal'][$service['zone']]['httpslogin'])) if (isset($config['captiveportal'][$service['zone']]['httpslogin']))
$running = $running && is_pid_running("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid"); $running = $running && isvalidpid("{$g['varrun_path']}/lighty-{$service['zone']}-CaptivePortal-SSL.pid");
break; break;
case "vhosts-http": case "vhosts-http":
$running = is_pid_running("{$g['varrun_path']}/vhosts-http.pid"); $running = isvalidpid("{$g['varrun_path']}/vhosts-http.pid");
break; break;
case "dhcrelay6": case "dhcrelay6":
$running = is_pid_running("{$g['varrun_path']}/dhcrelay6.pid"); $running = isvalidpid("{$g['varrun_path']}/dhcrelay6.pid");
break; break;
case 'ipsec': case 'ipsec':
$running = is_pid_running("{$g['varrun_path']}/charon.pid"); $running = isvalidpid("{$g['varrun_path']}/charon.pid");
break; break;
default: default:
$running = is_service_running($service['name']); $running = is_service_running($service['name']);
...@@ -592,7 +432,6 @@ if (!function_exists('service_control_start')) { ...@@ -592,7 +432,6 @@ if (!function_exists('service_control_start')) {
captiveportal_init_webgui_zonename($zone); captiveportal_init_webgui_zonename($zone);
break; break;
case 'ntpd': case 'ntpd':
case 'openntpd':
system_ntp_configure(); system_ntp_configure();
break; break;
case 'apinger': case 'apinger':
...@@ -638,7 +477,7 @@ if (!function_exists('service_control_start')) { ...@@ -638,7 +477,7 @@ if (!function_exists('service_control_start')) {
relayd_configure(); relayd_configure();
break; break;
default: default:
start_service($name); log_error(gettext("Could not start unknown service `%s'", $name));
break; break;
} }
return sprintf(gettext("%s has been started."),htmlspecialchars($name)); return sprintf(gettext("%s has been started."),htmlspecialchars($name));
...@@ -663,9 +502,6 @@ if (!function_exists('service_control_stop')) { ...@@ -663,9 +502,6 @@ if (!function_exists('service_control_stop')) {
case 'ntpd': case 'ntpd':
killbyname("ntpd"); killbyname("ntpd");
break; break;
case 'openntpd':
killbyname("openntpd");
break;
case 'apinger': case 'apinger':
killbypid("{$g['varrun_path']}/apinger.pid"); killbypid("{$g['varrun_path']}/apinger.pid");
break; break;
...@@ -714,7 +550,7 @@ if (!function_exists('service_control_stop')) { ...@@ -714,7 +550,7 @@ if (!function_exists('service_control_stop')) {
mwexec('pkill relayd'); mwexec('pkill relayd');
break; break;
default: default:
stop_service($name); log_error(gettext("Could not stop unknown service `%s'", $name));
break; break;
} }
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name)); return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
...@@ -740,7 +576,6 @@ if (!function_exists('service_control_restart')) { ...@@ -740,7 +576,6 @@ if (!function_exists('service_control_restart')) {
captiveportal_configure(); captiveportal_configure();
break; break;
case 'ntpd': case 'ntpd':
case 'openntpd':
system_ntp_configure(); system_ntp_configure();
break; break;
case 'apinger': case 'apinger':
...@@ -790,11 +625,9 @@ if (!function_exists('service_control_restart')) { ...@@ -790,11 +625,9 @@ if (!function_exists('service_control_restart')) {
relayd_configure(true); relayd_configure(true);
break; break;
default: default:
restart_service($name); log_error(gettext("Could not restart unknown service `%s'", $name));
break; break;
} }
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name)); return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
} }
} }
?>
...@@ -1588,13 +1588,10 @@ function system_ntp_configure($start_ntpd = true) ...@@ -1588,13 +1588,10 @@ function system_ntp_configure($start_ntpd = true)
} }
if (empty($config['ntpd']['interface'])) $interfaces = array();
if (is_array($config['installedpackages']['openntpd']) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) if (isset($config['ntpd']['interface'])) {
$interfaces = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']); $interfaces = explode(',', $config['ntpd']['interface']);
else }
$interfaces = array();
else
$interfaces = explode(",", $config['ntpd']['interface']);
if (is_array($interfaces) && count($interfaces)) { if (is_array($interfaces) && count($interfaces)) {
$ntpcfg .= "interface ignore all\n"; $ntpcfg .= "interface ignore all\n";
......
<?php
require_once('config.inc');
require_once('globals.inc');
require_once('service-utils.inc');
function openntpd_install() {
global $g;
$config_file = $g['varetc_path'] . '/openntpd.conf';
$rcfile = array();
$rcfile['file'] = 'openntpd.sh';
$rcfile['start'] = <<<EOD
if [ -f $config_file ]; then
ntpd -f $config_file
fi
EOD;
$rcfile['stop'] = "killall ntpd";
write_rcfile($rcfile);
}
function openntpd_get_iface_ip($iface) {
$iface = convert_friendly_interface_to_real_interface_name($iface);
$line = trim(shell_exec("ifconfig " . escapeshellarg($iface) . " | grep inet | grep -v inet6"));
list($dummy, $ip, $dummy2, $dummy3) = explode(' ', $line);
return $ip;
}
function openntpd_resync() {
global $g, $config;
$settings = $config['installedpackages']['openntpd']['config'][0];
$config_file = $g['varetc_path'] . '/openntpd.conf';
if ($settings['enable'] == 'on') {
$conf = '';
$ifaces = explode(',', $settings['interface']);
$ips = array_map('openntpd_get_iface_ip', $ifaces);
foreach ($ips as $ip)
$conf .= "listen on $ip\n";
$servers = explode(',', $config['system']['timeservers']);
foreach ($servers as $server)
$conf .= "servers $server\n";
file_put_contents($config_file, $conf);
}
else {
if (file_exists($config_file))
unlink($config_file);
}
restart_service('openntpd');
}
<?xml version="1.0" encoding="utf-8"?>
<packagegui>
<include_file>system.inc</include_file>
<name>openntpd</name>
<title>NTP server</title>
<fields>
<field>
<fieldname>enable</fieldname>
<fielddescr>Enable</fielddescr>
<description>Check this to enable the NTP server.</description>
<type>checkbox</type>
</field>
<field>
<fieldname>interface</fieldname>
<fielddescr>Interface</fielddescr>
<description>Select the interface(s) the NTP server will listen on.</description>
<default_value>lan</default_value>
<multiple/>
<type>select_source</type>
<source><![CDATA[get_possible_listen_ips()]]></source>
<source_name>name</source_name>
<source_value>value</source_value>
</field>
</fields>
<custom_php_resync_config_command>
system_ntp_configure();
</custom_php_resync_config_command>
</packagegui>
...@@ -35,18 +35,12 @@ if (!is_array($config['ntpd'])) ...@@ -35,18 +35,12 @@ if (!is_array($config['ntpd']))
$config['ntpd'] = array(); $config['ntpd'] = array();
if (empty($config['ntpd']['interface'])) { if (empty($config['ntpd']['interface'])) {
if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) && $pconfig['interface'] = array();
is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) { } else {
$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
unset($config['installedpackages']['openntpd']);
write_config("Upgraded settings from openttpd");
} else
$pconfig['interface'] = array();
} else
$pconfig['interface'] = explode(",", $config['ntpd']['interface']); $pconfig['interface'] = explode(",", $config['ntpd']['interface']);
}
if ($_POST) { if ($_POST) {
unset($input_errors); unset($input_errors);
$pconfig = $_POST; $pconfig = $_POST;
......
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