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() ...@@ -2682,7 +2682,7 @@ function services_get()
$pconfig['id'] = $id; $pconfig['id'] = $id;
$pconfig['vpnid'] = $setting['vpnid']; $pconfig['vpnid'] = $setting['vpnid'];
$pconfig['description'] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']); $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; $services[] = $pconfig;
} }
} }
...@@ -2757,18 +2757,7 @@ function services_get() ...@@ -2757,18 +2757,7 @@ function services_get()
return $services; return $services;
} }
function find_service_by_openvpn_vpnid($vpnid) function find_service_by_name($names, $filter = array())
{
$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)
{ {
if (!is_array($names)) { if (!is_array($names)) {
$names = array($names); $names = array($names);
...@@ -2778,11 +2767,25 @@ function find_service_by_name($names) ...@@ -2778,11 +2767,25 @@ function find_service_by_name($names)
foreach ($services as $service) { foreach ($services as $service) {
foreach ($names as $name) { foreach ($names as $name) {
if ($service['name'] == $name) { 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; return $service;
} }
} }
} }
}
return array(); return array();
} }
......
...@@ -183,15 +183,7 @@ if($need_alert_display == true) { ...@@ -183,15 +183,7 @@ if($need_alert_display == true) {
<li class="btn-group-container"> <li class="btn-group-container">
<?php <?php
if (isset($service_hook)) { 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); $ssvc = find_service_by_name($service_hook);
break;
}
if (!empty($ssvc)) { if (!empty($ssvc)) {
echo get_service_status_icon($ssvc, false); echo get_service_status_icon($ssvc, false);
echo get_service_control_links($ssvc, false); echo get_service_control_links($ssvc, false);
......
...@@ -175,7 +175,7 @@ $( document ).ready(function() { ...@@ -175,7 +175,7 @@ $( document ).ready(function() {
endforeach; ?> endforeach; ?>
<tr> <tr>
<td colspan="2"> <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_status_icon($ssvc, true, true); ?>
<?= get_service_control_links($ssvc, true); ?> <?= get_service_control_links($ssvc, true); ?>
</td> </td>
...@@ -254,7 +254,7 @@ $( document ).ready(function() { ...@@ -254,7 +254,7 @@ $( document ).ready(function() {
<td><?=$sk_server['status'];?></td> <td><?=$sk_server['status'];?></td>
<td> <td>
<div> <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_status_icon($ssvc, false, true); ?>
<?= get_service_control_links($ssvc, true); ?> <?= get_service_control_links($ssvc, true); ?>
</div> </div>
...@@ -294,7 +294,7 @@ $( document ).ready(function() { ...@@ -294,7 +294,7 @@ $( document ).ready(function() {
<td><?=$client['status'];?></td> <td><?=$client['status'];?></td>
<td> <td>
<div> <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_status_icon($ssvc, false, true); ?>
<?= get_service_control_links($ssvc, true); ?> <?= get_service_control_links($ssvc, true); ?>
</div> </div>
......
...@@ -118,17 +118,8 @@ function service_control_stop($name, $extras) ...@@ -118,17 +118,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));
switch ($name) { /* XXX openvpn is handled special at the moment */
case 'igmpproxy': if ($name == 'openvpn') {
killbyname("igmpproxy");
return $msg;
case 'miniupnpd':
upnp_action('stop');
return $msg;
case 'sshd':
killbyname("sshd");
return $msg;
case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']); $vpnmode = htmlspecialchars($extras['vpnmode']);
if (($vpnmode == "server") or ($vpnmode == "client")) { if (($vpnmode == "server") or ($vpnmode == "client")) {
$id = htmlspecialchars($extras['id']); $id = htmlspecialchars($extras['id']);
...@@ -136,11 +127,10 @@ function service_control_stop($name, $extras) ...@@ -136,11 +127,10 @@ function service_control_stop($name, $extras)
killbypid($pidfile); killbypid($pidfile);
} }
return $msg; return $msg;
case 'relayd': /* XXX extra argument is extra tricky */
killbyname('relayd'); } elseif ($name == 'miniupnpd') {
upnp_action('stop');
return $msg; return $msg;
default:
break;
} }
$service = find_service_by_name($name); $service = find_service_by_name($name);
...@@ -163,7 +153,8 @@ function service_control_stop($name, $extras) ...@@ -163,7 +153,8 @@ function service_control_stop($name, $extras)
} elseif (isset($service['pidfile'])) { } elseif (isset($service['pidfile'])) {
killbypid($service['pidfile']); killbypid($service['pidfile']);
} else { } else {
$msg = sprintf(gettext("Could not stop service `%s'"), htmlspecialchars($name)); /* last resort, but not very elegant */
killbyname($service['name']);
} }
return $msg; 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