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