Commit f01b1953 authored by Franco Fichtner's avatar Franco Fichtner

services: simplify vpn service control and extend for pppoe servers

(cherry picked from commit 2223d5d2)
parent 333e92f6
...@@ -77,10 +77,10 @@ function vpn_services() ...@@ -77,10 +77,10 @@ function vpn_services()
'php' => array( 'php' => array(
'restart' => array('vpn_pppoe_configure_by_id'), 'restart' => array('vpn_pppoe_configure_by_id'),
'start' => array('vpn_pppoe_configure_by_id'), 'start' => array('vpn_pppoe_configure_by_id'),
'args' => array('pppoeid'), 'args' => array('id'),
), ),
'pidfile' => "/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid", 'pidfile' => "/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid",
'pppoeid' => $pppoecfg['pppoeid'], 'id' => $pppoecfg['pppoeid'],
'name' => 'pppoed', 'name' => 'pppoed',
); );
} }
......
...@@ -2627,18 +2627,17 @@ function services_get() ...@@ -2627,18 +2627,17 @@ function services_get()
foreach (array('server', 'client') as $mode) { foreach (array('server', 'client') as $mode) {
if (isset($config['openvpn']["openvpn-{$mode}"])) { if (isset($config['openvpn']["openvpn-{$mode}"])) {
foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) { foreach ($config['openvpn']["openvpn-{$mode}"] as $setting) {
if (!isset($setting['disable'])) { if (!isset($setting['disable'])) {
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "openvpn";
$pconfig['mode'] = $mode;
$pconfig['id'] = $id;
$pconfig['vpnid'] = $setting['vpnid'];
$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']); $pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
$pconfig['php']['restart'] = array('openvpn_restart_by_id'); $pconfig['php']['restart'] = array('openvpn_restart_by_id');
$pconfig['php']['start'] = array('openvpn_restart_by_id'); $pconfig['php']['start'] = array('openvpn_restart_by_id');
$pconfig['php']['args'] = array('mode', 'vpnid'); $pconfig['php']['args'] = array('mode', 'id');
$pconfig['pidfile'] = "/var/run/openvpn_{$mode}{$setting['vpnid']}.pid"; $pconfig['pidfile'] = "/var/run/openvpn_{$mode}{$setting['vpnid']}.pid";
$pconfig['id'] = $setting['vpnid'];
$pconfig['name'] = 'openvpn';
$pconfig['mode'] = $mode;
$services[] = $pconfig; $services[] = $pconfig;
} }
} }
...@@ -2792,38 +2791,35 @@ function get_service_status_icon($service, $withtext = true, $smallicon = false) ...@@ -2792,38 +2791,35 @@ function get_service_status_icon($service, $withtext = true, $smallicon = false)
function get_service_control_links($service, $addname = false) function get_service_control_links($service, $addname = false)
{ {
$output = ""; $stitle = $addname ? $service['name'] . ' ' : '';
$stitle = ($addname) ? $service['name'] . " " : ""; $output = '';
if (get_service_status($service)) { if (get_service_status($service)) {
switch ($service['name']) { /* restart service button */
case "openvpn": $output .= "<a href='status_services.php?action=restart&amp;service={$service['name']}";
$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}' class=\"btn btn-default\">"; if (isset($service['id'])) {
break; $output .= "&amp;id={$service['id']}";
default:
$output .= "<a href='status_services.php?mode=restartservice&amp;service={$service['name']}' class=\"btn btn-default\">";
} }
$output .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title='" . sprintf(gettext("Restart %sService"),$stitle) . "' class=\"glyphicon glyphicon-refresh\"> </span> </a>\n"; $output .= "' class=\"btn btn-default\">";
switch ($service['name']) { $output .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title='" . sprintf(gettext("Restart %sService"),$stitle) . "' class=\"glyphicon glyphicon-refresh\"></span></a>\n";
case "openvpn":
$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}' class=\"btn btn-default\">"; /* stop service button */
break; $output .= "<a href='status_services.php?action=stop&amp;service={$service['name']}";
default: if (isset($service['id'])) {
$output .= "<a href='status_services.php?mode=stopservice&amp;service={$service['name']}' class=\"btn btn-default\">"; $output .= "&amp;id={$service['id']}";
break;
} }
$output .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title='" . sprintf(gettext("Stop %sService"),$stitle) . "' class=\"glyphicon glyphicon-stop\" ></span>"; $output .= "' class=\"btn btn-default\">";
$output .= "</a>"; $output .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title='" . sprintf(gettext("Stop %sService"),$stitle) . "' class=\"glyphicon glyphicon-stop\"></span></a>";
} else { } else {
switch ($service['name']) { /* start service button */
case "openvpn": $output .= "<a href='status_services.php?action=start&amp;service={$service['name']}";
$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}&amp;vpnmode={$service['mode']}&amp;id={$service['vpnid']}' class=\"btn btn-default\">"; if (isset($service['id'])) {
break; $output .= "&amp;id={$service['id']}";
default:
$output .= "<a href='status_services.php?mode=startservice&amp;service={$service['name']}' class=\"btn btn-default\">";
break;
} }
$output .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title='" . sprintf(gettext("Start %sService"),$stitle) . "' alt='start' class=\"glyphicon glyphicon-play\"/></a>\n"; $output .= "' class=\"btn btn-default\">";
$output .= "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title='" . sprintf(gettext("Start %sService"),$stitle) . "' class=\"glyphicon glyphicon-play\"/></a>\n";
} }
return $output; return $output;
} }
......
...@@ -43,14 +43,14 @@ require_once("rrd.inc"); ...@@ -43,14 +43,14 @@ require_once("rrd.inc");
if (!empty($_GET['service'])) { if (!empty($_GET['service'])) {
$service_name = $_GET['service']; $service_name = $_GET['service'];
switch ($_GET['mode']) { switch ($_GET['action']) {
case "restartservice": case 'restart':
$savemsg = service_control_restart($service_name, $_GET); $savemsg = service_control_restart($service_name, $_GET);
break; break;
case "startservice": case 'start':
$savemsg = service_control_start($service_name, $_GET); $savemsg = service_control_start($service_name, $_GET);
break; break;
case "stopservice": case 'stop':
$savemsg = service_control_stop($service_name, $_GET); $savemsg = service_control_stop($service_name, $_GET);
break; break;
} }
...@@ -68,8 +68,8 @@ function service_control_start($name, $extras) ...@@ -68,8 +68,8 @@ function service_control_start($name, $extras)
{ {
$msg = sprintf(gettext('%s has been started.'), htmlspecialchars($name)); $msg = sprintf(gettext('%s has been started.'), htmlspecialchars($name));
if ($name == 'openvpn') { if (isset($extras['id'])) {
$filter['vpnid'] = $extras['id']; $filter['id'] = $extras['id'];
} }
$service = find_service_by_name($name, $filter); $service = find_service_by_name($name, $filter);
...@@ -107,8 +107,8 @@ function service_control_stop($name, $extras) ...@@ -107,8 +107,8 @@ function service_control_stop($name, $extras)
$msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name)); $msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
$filter = array(); $filter = array();
if ($name == 'openvpn') { if (isset($extras['id'])) {
$filter['vpnid'] = $extras['id']; $filter['id'] = $extras['id'];
} }
$service = find_service_by_name($name, $filter); $service = find_service_by_name($name, $filter);
...@@ -142,11 +142,11 @@ function service_control_restart($name, $extras) ...@@ -142,11 +142,11 @@ function service_control_restart($name, $extras)
{ {
$msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name)); $msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
if ($name == 'openvpn') { if (isset($extras['id'])) {
$filter['vpnid'] = $extras['id']; $filter['id'] = $extras['id'];
} }
$service = find_service_by_name($name); $service = find_service_by_name($name, $filter);
if (!isset($service['name'])) { if (!isset($service['name'])) {
return sprintf(gettext("Could not restart unknown service `%s'"), htmlspecialchars($name)); return sprintf(gettext("Could not restart unknown service `%s'"), htmlspecialchars($name));
} }
......
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