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

(legacy) refactor status_services.php

parent 44a6e81e
...@@ -42,234 +42,238 @@ require_once("rrd.inc"); ...@@ -42,234 +42,238 @@ require_once("rrd.inc");
function openvpn_restart_by_vpnid($mode, $vpnid) function openvpn_restart_by_vpnid($mode, $vpnid)
{ {
$settings = openvpn_get_settings($mode, $vpnid); $settings = openvpn_get_settings($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']); switch ($_GET['mode']) {
} case "restartservice":
$savemsg = service_control_restart($service_name, $_GET);
if (!empty($service_name)) { break;
switch ($_GET['mode']) { case "startservice":
case "restartservice": $savemsg = service_control_start($service_name, $_GET);
$savemsg = service_control_restart($service_name, $_GET); break;
break; case "stopservice":
case "startservice": $savemsg = service_control_stop($service_name, $_GET);
$savemsg = service_control_start($service_name, $_GET); break;
break; }
case "stopservice": sleep(5);
$savemsg = service_control_stop($service_name, $_GET); // redirect after performing action, removing the action parameters from request.
break; header("Location: status_services.php");
} exit;
sleep(5);
} }
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(); break;
break; case 'ntpd':
case 'ntpd': system_ntp_configure();
system_ntp_configure(); break;
break; case 'apinger':
case 'apinger': setup_gateways_monitor();
setup_gateways_monitor(); break;
break; case 'bsnmpd':
case 'bsnmpd': services_snmpd_configure();
services_snmpd_configure(); break;
break; case 'dhcrelay':
case 'dhcrelay': services_dhcrelay_configure();
services_dhcrelay_configure(); break;
break; case 'dhcrelay6':
case 'dhcrelay6': services_dhcrelay6_configure();
services_dhcrelay6_configure(); break;
break; case 'dnsmasq':
case 'dnsmasq': services_dnsmasq_configure();
services_dnsmasq_configure(); break;
break; case 'unbound':
case 'unbound': services_unbound_configure();
services_unbound_configure(); break;
break; case 'dhcpd':
case 'dhcpd': services_dhcpd_configure();
services_dhcpd_configure(); break;
break; case 'igmpproxy':
case 'igmpproxy': services_igmpproxy_configure();
services_igmpproxy_configure(); break;
break; case 'miniupnpd':
case 'miniupnpd': upnp_action('start');
upnp_action('start'); break;
break; case 'ipsec':
case 'ipsec': vpn_ipsec_force_reload();
vpn_ipsec_force_reload(); break;
break; case 'sshd':
case 'sshd': configd_run("sshd restart");
configd_run("sshd restart"); break;
break; case 'openvpn':
case 'openvpn': $vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']); 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();
break; break;
case 'squid': case 'squid':
configd_run("proxy start"); configd_run("proxy start");
break; break;
case 'suricata': case 'suricata':
configd_run("ids start"); configd_run("ids start");
break; break;
default: default:
log_error(sprintf(gettext("Could not start unknown service `%s'"), $name)); log_error(sprintf(gettext("Could not start unknown service `%s'"), $name));
break; break;
} }
return sprintf(gettext("%s has been started."),htmlspecialchars($name)); return sprintf(gettext("%s has been started."),htmlspecialchars($name));
} }
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"); break;
break; case 'ntpd':
case 'ntpd': killbyname("ntpd");
killbyname("ntpd"); break;
break; case 'apinger':
case 'apinger': killbypid("/var/run/apinger.pid");
killbypid("/var/run/apinger.pid"); break;
break; case 'bsnmpd':
case 'bsnmpd': killbypid("/var/run/snmpd.pid");
killbypid("/var/run/snmpd.pid"); break;
break; case 'choparp':
case 'choparp': killbyname("choparp");
killbyname("choparp"); break;
break; case 'dhcpd':
case 'dhcpd': killbyname("dhcpd");
killbyname("dhcpd"); break;
break; case 'dhcrelay':
case 'dhcrelay': killbypid("/var/run/dhcrelay.pid");
killbypid("/var/run/dhcrelay.pid"); break;
break; case 'dhcrelay6':
case 'dhcrelay6': killbypid("/var/run/dhcrelay6.pid");
killbypid("/var/run/dhcrelay6.pid"); break;
break; case 'dnsmasq':
case 'dnsmasq': killbypid("/var/run/dnsmasq.pid");
killbypid("/var/run/dnsmasq.pid"); break;
break; case 'unbound':
case 'unbound': killbypid("/var/run/unbound.pid");
killbypid("/var/run/unbound.pid"); break;
break; case 'igmpproxy':
case 'igmpproxy': killbyname("igmpproxy");
killbyname("igmpproxy"); break;
break; case 'miniupnpd':
case 'miniupnpd': upnp_action('stop');
upnp_action('stop'); break;
break; case 'sshd':
case 'sshd': killbyname("sshd");
killbyname("sshd"); break;
break; case 'ipsec':
case 'ipsec': exec("/usr/local/sbin/ipsec stop");
exec("/usr/local/sbin/ipsec stop"); break;
break; case 'openvpn':
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']); $pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid";
$pidfile = "/var/run/openvpn_{$vpnmode}{$id}.pid"; killbypid($pidfile);
killbypid($pidfile); }
} break;
break; case 'relayd':
case 'relayd': mwexec('pkill relayd');
mwexec('pkill relayd'); break;
break; case 'squid':
case 'squid': configd_run("proxy stop");
configd_run("proxy stop"); break;
break; case 'suricata':
case 'suricata': configd_run("ids stop");
configd_run("ids stop"); break;
break; default:
default: log_error(sprintf(gettext("Could not stop unknown service `%s'"), $name));
log_error(sprintf(gettext("Could not stop unknown service `%s'"), $name)); break;
break; }
} return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
} }
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(); break;
break; case 'ntpd':
case 'ntpd': system_ntp_configure();
system_ntp_configure(); break;
break; case 'apinger':
case 'apinger': killbypid("/var/run/apinger.pid");
killbypid("/var/run/apinger.pid"); setup_gateways_monitor();
setup_gateways_monitor(); break;
break; case 'bsnmpd':
case 'bsnmpd': services_snmpd_configure();
services_snmpd_configure(); break;
break; case 'dhcrelay':
case 'dhcrelay': services_dhcrelay_configure();
services_dhcrelay_configure(); break;
break; case 'dhcrelay6':
case 'dhcrelay6': services_dhcrelay6_configure();
services_dhcrelay6_configure(); break;
break; case 'dnsmasq':
case 'dnsmasq': services_dnsmasq_configure();
services_dnsmasq_configure(); break;
break; case 'unbound':
case 'unbound': services_unbound_configure();
services_unbound_configure(); break;
break; case 'dhcpd':
case 'dhcpd': services_dhcpd_configure();
services_dhcpd_configure(); break;
break; case 'igmpproxy':
case 'igmpproxy': services_igmpproxy_configure();
services_igmpproxy_configure(); break;
break; case 'miniupnpd':
case 'miniupnpd': upnp_action('restart');
upnp_action('restart'); break;
break; case 'ipsec':
case 'ipsec': vpn_ipsec_force_reload();
vpn_ipsec_force_reload(); break;
break; case 'sshd':
case 'sshd': configd_run("sshd restart");
configd_run("sshd restart"); break;
break; case 'openvpn':
case 'openvpn': $vpnmode = htmlspecialchars($extras['vpnmode']);
$vpnmode = htmlspecialchars($extras['vpnmode']); 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);
break; break;
case 'squid': case 'squid':
configd_run("proxy restart"); configd_run("proxy restart");
break; break;
case 'suricata': case 'suricata':
configd_run("ids restart"); configd_run("ids restart");
break; break;
default: default:
log_error(sprintf(gettext("Could not restart unknown service `%s'"), $name)); log_error(sprintf(gettext("Could not restart unknown service `%s'"), $name));
break; break;
} }
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");
...@@ -278,66 +282,48 @@ include("head.inc"); ...@@ -278,66 +282,48 @@ 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); ?>
<section class="col-xs-12">
<?php if (isset($savemsg)) print_info_box($savemsg); ?> <div class="content-box">
<div class="table-responsive">
<section class="col-xs-12"> <table class="table table-striped">
<thead>
<div class="content-box"> <tr>
<form action="status_services.php" method="post"> <td><?=gettext("Service");?></td>
<td><?=gettext("Description");?></td>
<div class="table-responsive"> <td><?=gettext("Status");?></td>
<table class="table table-striped table-sort"> </tr>
<thead> </thead>
<tr> <tbody>
<td><?=gettext("Service");?></td> <?php
<td><?=gettext("Description");?></td> if (count($services) > 0):
<td><?=gettext("Status");?></td> foreach($services as $service):?>
</tr> <tr>
</thead> <td><?=$service['name'];?></td>
<tbody> <td><?=$service['description'];?></td>
<?php <td>
<?=get_service_status_icon($service, true, true);?>
$services = get_services(); <?=get_service_control_links($service);?>
<?=!empty(get_shortcut_by_service_name($service['name'])) ? get_shortcut_log_link($scut, true) :"";?>
if (count($services) > 0) { </td>
uasort($services, "service_name_compare"); </tr>
foreach($services as $service) { <?php
if (empty($service['name'])) endforeach;
continue; else:?>
echo "<tr><td class=\"listlr\" >" . $service['name'] . "</td>\n"; <tr>
echo "<td class=\"listr\">" . $service['description'] . "</td>\n"; <td colspan="3"> <?=gettext("No services found");?></td>
// if service is running then listr else listbg </tr>
$bgclass = null; <?php
if (get_service_status($service)) endif;?>
$bgclass = "listr"; </tbody>
else </table>
$bgclass = "listbg"; </div>
echo "<td class=\"" . $bgclass . "\">" . get_service_status_icon($service, true, true) . "</td>\n"; </div>
echo "<td valign=\"middle\" class=\"list nowrap\">" . get_service_control_links($service); </section>
$scut = get_shortcut_by_service_name($service['name']); </div>
if (!empty($scut)) { </div>
echo get_shortcut_log_link($scut, true); </section>
}
echo "</td></tr>\n";
}
} else {
echo "<tr><td colspan=\"3\">" . gettext("No services found") . " . </td></tr>\n";
}
?>
</tbody>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</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