Commit d03b53b3 authored by Franco Fichtner's avatar Franco Fichtner

services: extent for openvpn's special arguments

parent 71bd852f
......@@ -807,6 +807,31 @@ function openvpn_reconfigure($mode, $settings)
@chmod("/var/etc/openvpn/{$mode_id}.conf", 0600);
}
function openvpn_restart_by_vpnid($mode, $vpnid)
{
global $config;
$found = null;
if (isset($config['openvpn']["openvpn-$mode"])) {
foreach ($config['openvpn']["openvpn-$mode"] as $settings) {
if (isset($settings['disable'])) {
continue;
}
if ($vpnid != 0 && $vpnid == $settings['vpnid']) {
$found = $settings;
break;
}
}
}
if ($found == null) {
return;
}
openvpn_restart($mode, $found);
}
function openvpn_restart($mode, $settings)
{
global $config;
......@@ -1362,37 +1387,6 @@ function openvpn_gen_route_ipv6($network, $iroute = false)
return "{$i}route-ipv6 ${ipv6}/${prefix}";
}
function openvpn_get_settings($mode, $vpnid)
{
global $config;
if (is_array($config['openvpn']['openvpn-server'])) {
foreach ($config['openvpn']['openvpn-server'] as $settings) {
if (isset($settings['disable'])) {
continue;
}
if ($vpnid != 0 && $vpnid == $settings['vpnid']) {
return $settings;
}
}
}
if (is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as $settings) {
if (isset($settings['disable'])) {
continue;
}
if ($vpnid != 0 && $vpnid == $settings['vpnid']) {
return $settings;
}
}
}
return array();
}
/**
* Retrieve a list of remote access servers, indexed by vpnid
*/
......
......@@ -2654,6 +2654,9 @@ function services_get()
$pconfig['id'] = $id;
$pconfig['vpnid'] = $setting['vpnid'];
$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
$pconfig['php']['restart'] = array('openvpn_restart_by_vpnid');
$pconfig['php']['start'] = array('openvpn_restart_by_vpnid');
$pconfig['php']['args'] = array('mode', 'vpnid');
$pconfig['pidfile'] = "/var/run/openvpn_{$mode}{$setting['vpnid']}.pid";
$services[] = $pconfig;
}
......
......@@ -40,12 +40,6 @@ require_once("vpn.inc");
require_once("interfaces.inc");
require_once("rrd.inc");
function openvpn_restart_by_vpnid($mode, $vpnid)
{
$settings = openvpn_get_settings($mode, $vpnid);
openvpn_restart($mode, $settings);
}
if (!empty($_GET['service'])) {
$service_name = $_GET['service'];
switch ($_GET['mode']) {
......@@ -73,20 +67,11 @@ 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']);
if (($vpnmode == "server") || ($vpnmode == "client")) {
$id = isset($extras['vpnid']) ? htmlspecialchars($extras['vpnid']) : htmlspecialchars($extras['id']);
$configfile = "/var/etc/openvpn/{$vpnmode}{$id}.conf";
if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
return $msg;
$filter['vpnid'] = $extras['id'];
}
$service = find_service_by_name($name);
$service = find_service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not start unknown service `%s'"), htmlspecialchars($name));
}
......@@ -97,7 +82,13 @@ function service_control_start($name, $extras)
}
} elseif (isset($service['php']['start'])) {
foreach ($service['php']['start'] as $cmd) {
$cmd();
$params = array();
if (isset($service['php']['args'])) {
foreach ($service['php']['args'] as $param) {
$params[] = $service[$param];
}
}
call_user_func_array($cmd, $params);
}
} elseif (isset($service['mwexec']['start'])) {
foreach ($service['mwexec']['start'] as $cmd) {
......@@ -116,7 +107,6 @@ function service_control_stop($name, $extras)
$filter = array();
if ($name == 'openvpn') {
$filter['mode'] = $extras['vpnmode']; /* XXX I think mode is spurious */
$filter['vpnid'] = $extras['id'];
}
......@@ -147,7 +137,6 @@ function service_control_stop($name, $extras)
return $msg;
}
function service_control_restart($name, $extras)
{
$msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
......@@ -158,16 +147,6 @@ function service_control_restart($name, $extras)
killbypid("/var/run/apinger.pid");
setup_gateways_monitor();
return $msg;
case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']);
if ($vpnmode == "server" || $vpnmode == "client") {
$id = htmlspecialchars($extras['id']);
$configfile = "/var/etc/openvpn/{$vpnmode}{$id}.conf";
if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
return $msg;
case 'relayd':
relayd_configure(true);
filter_configure();
......@@ -187,7 +166,13 @@ function service_control_restart($name, $extras)
}
} elseif (isset($service['php']['restart'])) {
foreach ($service['php']['restart'] as $cmd) {
$cmd();
$params = array();
if (isset($service['php']['args'])) {
foreach ($service['php']['args'] as $param) {
$params[] = $service[$param];
}
}
call_user_func_array($cmd, $params);
}
} elseif (isset($service['mwexec']['restart'])) {
foreach ($service['mwexec']['restart'] as $cmd) {
......
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