Commit 11c82822 authored by Franco Fichtner's avatar Franco Fichtner

services: shrink stop further and start fixing openvpn

(cherry picked from commit 3600c6a3)
parent a6253b14
......@@ -2682,7 +2682,7 @@ function services_get()
$pconfig['id'] = $id;
$pconfig['vpnid'] = $setting['vpnid'];
$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
$pconfig['pidfile'] = "/var/run/openvpn_{$mode}{$settings['vpnid']}.pid";
$pconfig['pidfile'] = "/var/run/openvpn_{$mode}{$setting['vpnid']}.pid";
$services[] = $pconfig;
}
}
......@@ -2757,18 +2757,7 @@ function services_get()
return $services;
}
function find_service_by_openvpn_vpnid($vpnid)
{
$services = services_get();
foreach ($services as $service) {
if (($service["name"] == "openvpn") && isset($service["vpnid"]) && ($service["vpnid"] == $vpnid)) {
return $service;
}
}
return array();
}
function find_service_by_name($names)
function find_service_by_name($names, $filter = array())
{
if (!is_array($names)) {
$names = array($names);
......@@ -2778,8 +2767,22 @@ function find_service_by_name($names)
foreach ($services as $service) {
foreach ($names as $name) {
if ($service['name'] == $name) {
return $service;
if ($service['name'] != $name) {
continue;
}
if (!count($filter)) {
/* force match if filter wasn't set (standard behaviour) */
$filter['name'] = $name;
}
foreach ($filter as $key => $value) {
if (isset($service[$key]) && $service[$key] == $value) {
/*
* First match wins, $names is only used
* to probe similar services that exclude
* each other.
*/
return $service;
}
}
}
}
......
......@@ -183,15 +183,7 @@ if($need_alert_display == true) {
<li class="btn-group-container">
<?php
if (isset($service_hook)) {
$ssvc = array();
switch ($service_hook) {
case 'openvpn':
$ssvc = find_service_by_openvpn_vpnid($vpnid);
break;
default:
$ssvc = find_service_by_name($service_hook);
break;
}
$ssvc = find_service_by_name($service_hook);
if (!empty($ssvc)) {
echo get_service_status_icon($ssvc, false);
echo get_service_control_links($ssvc, false);
......
......@@ -175,7 +175,7 @@ $( document ).ready(function() {
endforeach; ?>
<tr>
<td colspan="2">
<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
<?php $ssvc = find_service_by_name('openvpn', array('vpnid' => $server['vpnid'])); ?>
<?= get_service_status_icon($ssvc, true, true); ?>
<?= get_service_control_links($ssvc, true); ?>
</td>
......@@ -254,7 +254,7 @@ $( document ).ready(function() {
<td><?=$sk_server['status'];?></td>
<td>
<div>
<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
<?php $ssvc = find_service_by_name('openvpn', array('vpnid' => $sk_server['vpnid'])); ?>
<?= get_service_status_icon($ssvc, false, true); ?>
<?= get_service_control_links($ssvc, true); ?>
</div>
......@@ -294,7 +294,7 @@ $( document ).ready(function() {
<td><?=$client['status'];?></td>
<td>
<div>
<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
<?php $ssvc = find_service_by_name('openvpn', array('vpnid' => $client['vpnid'])); ?>
<?= get_service_status_icon($ssvc, false, true); ?>
<?= get_service_control_links($ssvc, true); ?>
</div>
......
......@@ -118,29 +118,19 @@ function service_control_stop($name, $extras)
{
$msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
switch ($name) {
case 'igmpproxy':
killbyname("igmpproxy");
return $msg;
case 'miniupnpd':
upnp_action('stop');
return $msg;
case 'sshd':
killbyname("sshd");
return $msg;
case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']);
if (($vpnmode == "server") or ($vpnmode == "client")) {
$id = htmlspecialchars($extras['id']);
$pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid";
killbypid($pidfile);
}
return $msg;
case 'relayd':
killbyname('relayd');
return $msg;
default:
break;
/* XXX openvpn is handled special at the moment */
if ($name == 'openvpn') {
$vpnmode = htmlspecialchars($extras['vpnmode']);
if (($vpnmode == "server") or ($vpnmode == "client")) {
$id = htmlspecialchars($extras['id']);
$pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid";
killbypid($pidfile);
}
return $msg;
/* XXX extra argument is extra tricky */
} elseif ($name == 'miniupnpd') {
upnp_action('stop');
return $msg;
}
$service = find_service_by_name($name);
......@@ -163,7 +153,8 @@ function service_control_stop($name, $extras)
} elseif (isset($service['pidfile'])) {
killbypid($service['pidfile']);
} else {
$msg = sprintf(gettext("Could not stop service `%s'"), htmlspecialchars($name));
/* last resort, but not very elegant */
killbyname($service['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