Commit 72a32731 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor status_services.php

parent 44a6e81e
......@@ -46,12 +46,8 @@ function openvpn_restart_by_vpnid($mode, $vpnid)
openvpn_restart($mode, $settings);
}
$service_name = '';
if (isset($_GET['service'])) {
if (!empty($_GET['service'])) {
$service_name = htmlspecialchars($_GET['service']);
}
if (!empty($service_name)) {
switch ($_GET['mode']) {
case "restartservice":
$savemsg = service_control_restart($service_name, $_GET);
......@@ -64,10 +60,12 @@ if (!empty($service_name)) {
break;
}
sleep(5);
// redirect after performing action, removing the action parameters from request.
header("Location: status_services.php");
exit;
}
function service_control_start($name, $extras) {
global $g;
switch($name) {
case 'radvd':
services_radvd_configure();
......@@ -113,9 +111,10 @@ function service_control_start($name, $extras) {
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))
if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
break;
case 'relayd':
relayd_configure();
......@@ -135,7 +134,6 @@ function service_control_start($name, $extras) {
function service_control_stop($name, $extras) {
global $g;
switch($name) {
case 'radvd':
killbypid("/var/run/radvd.pid");
......@@ -205,7 +203,6 @@ function service_control_stop($name, $extras) {
function service_control_restart($name, $extras) {
global $g;
switch($name) {
case 'radvd':
services_radvd_configure();
......@@ -252,9 +249,10 @@ function service_control_restart($name, $extras) {
if ($vpnmode == "server" || $vpnmode == "client") {
$id = htmlspecialchars($extras['id']);
$configfile = "/var/etc/openvpn/{$vpnmode}{$id}.conf";
if (file_exists($configfile))
if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
break;
case 'relayd':
relayd_configure(true);
......@@ -272,26 +270,26 @@ function service_control_restart($name, $extras) {
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
}
$services = get_services();
if (count($services) > 0) {
uasort($services, "service_name_compare");
}
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12">
<div class="content-box">
<form action="status_services.php" method="post">
<div class="table-responsive">
<table class="table table-striped table-sort">
<table class="table table-striped">
<thead>
<tr>
<td><?=gettext("Service");?></td>
......@@ -300,44 +298,32 @@ include("head.inc");
</tr>
</thead>
<tbody>
<?php
$services = get_services();
if (count($services) > 0) {
uasort($services, "service_name_compare");
foreach($services as $service) {
if (empty($service['name']))
continue;
echo "<tr><td class=\"listlr\" >" . $service['name'] . "</td>\n";
echo "<td class=\"listr\">" . $service['description'] . "</td>\n";
// if service is running then listr else listbg
$bgclass = null;
if (get_service_status($service))
$bgclass = "listr";
else
$bgclass = "listbg";
echo "<td class=\"" . $bgclass . "\">" . get_service_status_icon($service, true, true) . "</td>\n";
echo "<td valign=\"middle\" class=\"list nowrap\">" . get_service_control_links($service);
$scut = get_shortcut_by_service_name($service['name']);
if (!empty($scut)) {
echo get_shortcut_log_link($scut, true);
}
echo "</td></tr>\n";
}
} else {
echo "<tr><td colspan=\"3\">" . gettext("No services found") . " . </td></tr>\n";
}
?>
<?php
if (count($services) > 0):
foreach($services as $service):?>
<tr>
<td><?=$service['name'];?></td>
<td><?=$service['description'];?></td>
<td>
<?=get_service_status_icon($service, true, true);?>
<?=get_service_control_links($service);?>
<?=!empty(get_shortcut_by_service_name($service['name'])) ? get_shortcut_log_link($scut, true) :"";?>
</td>
</tr>
<?php
endforeach;
else:?>
<tr>
<td colspan="3"> <?=gettext("No services found");?></td>
</tr>
<?php
endif;?>
</tbody>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
</section>
<?php include("foot.inc"); ?>
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