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");
function openvpn_restart_by_vpnid($mode, $vpnid)
{
$settings = openvpn_get_settings($mode, $vpnid);
openvpn_restart($mode, $settings);
$settings = openvpn_get_settings($mode, $vpnid);
openvpn_restart($mode, $settings);
}
$service_name = '';
if (isset($_GET['service'])) {
$service_name = htmlspecialchars($_GET['service']);
}
if (!empty($service_name)) {
switch ($_GET['mode']) {
case "restartservice":
$savemsg = service_control_restart($service_name, $_GET);
break;
case "startservice":
$savemsg = service_control_start($service_name, $_GET);
break;
case "stopservice":
$savemsg = service_control_stop($service_name, $_GET);
break;
}
sleep(5);
if (!empty($_GET['service'])) {
$service_name = htmlspecialchars($_GET['service']);
switch ($_GET['mode']) {
case "restartservice":
$savemsg = service_control_restart($service_name, $_GET);
break;
case "startservice":
$savemsg = service_control_start($service_name, $_GET);
break;
case "stopservice":
$savemsg = service_control_stop($service_name, $_GET);
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();
break;
case 'ntpd':
system_ntp_configure();
break;
case 'apinger':
setup_gateways_monitor();
break;
case 'bsnmpd':
services_snmpd_configure();
break;
case 'dhcrelay':
services_dhcrelay_configure();
break;
case 'dhcrelay6':
services_dhcrelay6_configure();
break;
case 'dnsmasq':
services_dnsmasq_configure();
break;
case 'unbound':
services_unbound_configure();
break;
case 'dhcpd':
services_dhcpd_configure();
break;
case 'igmpproxy':
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_action('start');
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'sshd':
configd_run("sshd restart");
break;
case 'openvpn':
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
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))
openvpn_restart_by_vpnid($vpnmode, $id);
}
break;
case 'relayd':
relayd_configure();
break;
case 'squid':
configd_run("proxy start");
break;
case 'suricata':
configd_run("ids start");
break;
default:
log_error(sprintf(gettext("Could not start unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been started."),htmlspecialchars($name));
switch($name) {
case 'radvd':
services_radvd_configure();
break;
case 'ntpd':
system_ntp_configure();
break;
case 'apinger':
setup_gateways_monitor();
break;
case 'bsnmpd':
services_snmpd_configure();
break;
case 'dhcrelay':
services_dhcrelay_configure();
break;
case 'dhcrelay6':
services_dhcrelay6_configure();
break;
case 'dnsmasq':
services_dnsmasq_configure();
break;
case 'unbound':
services_unbound_configure();
break;
case 'dhcpd':
services_dhcpd_configure();
break;
case 'igmpproxy':
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_action('start');
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'sshd':
configd_run("sshd restart");
break;
case 'openvpn':
$vpnmode = isset($extras['vpnmode']) ? htmlspecialchars($extras['vpnmode']) : htmlspecialchars($extras['mode']);
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)) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
break;
case 'relayd':
relayd_configure();
break;
case 'squid':
configd_run("proxy start");
break;
case 'suricata':
configd_run("ids start");
break;
default:
log_error(sprintf(gettext("Could not start unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been started."),htmlspecialchars($name));
}
function service_control_stop($name, $extras) {
global $g;
switch($name) {
case 'radvd':
killbypid("/var/run/radvd.pid");
break;
case 'ntpd':
killbyname("ntpd");
break;
case 'apinger':
killbypid("/var/run/apinger.pid");
break;
case 'bsnmpd':
killbypid("/var/run/snmpd.pid");
break;
case 'choparp':
killbyname("choparp");
break;
case 'dhcpd':
killbyname("dhcpd");
break;
case 'dhcrelay':
killbypid("/var/run/dhcrelay.pid");
break;
case 'dhcrelay6':
killbypid("/var/run/dhcrelay6.pid");
break;
case 'dnsmasq':
killbypid("/var/run/dnsmasq.pid");
break;
case 'unbound':
killbypid("/var/run/unbound.pid");
break;
case 'igmpproxy':
killbyname("igmpproxy");
break;
case 'miniupnpd':
upnp_action('stop');
break;
case 'sshd':
killbyname("sshd");
break;
case 'ipsec':
exec("/usr/local/sbin/ipsec stop");
break;
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);
}
break;
case 'relayd':
mwexec('pkill relayd');
break;
case 'squid':
configd_run("proxy stop");
break;
case 'suricata':
configd_run("ids stop");
break;
default:
log_error(sprintf(gettext("Could not stop unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
switch($name) {
case 'radvd':
killbypid("/var/run/radvd.pid");
break;
case 'ntpd':
killbyname("ntpd");
break;
case 'apinger':
killbypid("/var/run/apinger.pid");
break;
case 'bsnmpd':
killbypid("/var/run/snmpd.pid");
break;
case 'choparp':
killbyname("choparp");
break;
case 'dhcpd':
killbyname("dhcpd");
break;
case 'dhcrelay':
killbypid("/var/run/dhcrelay.pid");
break;
case 'dhcrelay6':
killbypid("/var/run/dhcrelay6.pid");
break;
case 'dnsmasq':
killbypid("/var/run/dnsmasq.pid");
break;
case 'unbound':
killbypid("/var/run/unbound.pid");
break;
case 'igmpproxy':
killbyname("igmpproxy");
break;
case 'miniupnpd':
upnp_action('stop');
break;
case 'sshd':
killbyname("sshd");
break;
case 'ipsec':
exec("/usr/local/sbin/ipsec stop");
break;
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);
}
break;
case 'relayd':
mwexec('pkill relayd');
break;
case 'squid':
configd_run("proxy stop");
break;
case 'suricata':
configd_run("ids stop");
break;
default:
log_error(sprintf(gettext("Could not stop unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
}
function service_control_restart($name, $extras) {
global $g;
switch($name) {
case 'radvd':
services_radvd_configure();
break;
case 'ntpd':
system_ntp_configure();
break;
case 'apinger':
killbypid("/var/run/apinger.pid");
setup_gateways_monitor();
break;
case 'bsnmpd':
services_snmpd_configure();
break;
case 'dhcrelay':
services_dhcrelay_configure();
break;
case 'dhcrelay6':
services_dhcrelay6_configure();
break;
case 'dnsmasq':
services_dnsmasq_configure();
break;
case 'unbound':
services_unbound_configure();
break;
case 'dhcpd':
services_dhcpd_configure();
break;
case 'igmpproxy':
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_action('restart');
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'sshd':
configd_run("sshd restart");
break;
case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']);
if ($vpnmode == "server" || $vpnmode == "client") {
$id = htmlspecialchars($extras['id']);
$configfile = "/var/etc/openvpn/{$vpnmode}{$id}.conf";
if (file_exists($configfile))
openvpn_restart_by_vpnid($vpnmode, $id);
}
break;
case 'relayd':
relayd_configure(true);
break;
case 'squid':
configd_run("proxy restart");
break;
case 'suricata':
configd_run("ids restart");
break;
default:
log_error(sprintf(gettext("Could not restart unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
switch($name) {
case 'radvd':
services_radvd_configure();
break;
case 'ntpd':
system_ntp_configure();
break;
case 'apinger':
killbypid("/var/run/apinger.pid");
setup_gateways_monitor();
break;
case 'bsnmpd':
services_snmpd_configure();
break;
case 'dhcrelay':
services_dhcrelay_configure();
break;
case 'dhcrelay6':
services_dhcrelay6_configure();
break;
case 'dnsmasq':
services_dnsmasq_configure();
break;
case 'unbound':
services_unbound_configure();
break;
case 'dhcpd':
services_dhcpd_configure();
break;
case 'igmpproxy':
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_action('restart');
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'sshd':
configd_run("sshd restart");
break;
case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']);
if ($vpnmode == "server" || $vpnmode == "client") {
$id = htmlspecialchars($extras['id']);
$configfile = "/var/etc/openvpn/{$vpnmode}{$id}.conf";
if (file_exists($configfile)) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
break;
case 'relayd':
relayd_configure(true);
break;
case 'squid':
configd_run("proxy restart");
break;
case 'suricata':
configd_run("ids restart");
break;
default:
log_error(sprintf(gettext("Could not restart unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
}
$services = get_services();
if (count($services) > 0) {
uasort($services, "service_name_compare");
}
include("head.inc");
......@@ -278,66 +282,48 @@ 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">
<thead>
<tr>
<td><?=gettext("Service");?></td>
<td><?=gettext("Description");?></td>
<td><?=gettext("Status");?></td>
</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";
}
?>
</tbody>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<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">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<td><?=gettext("Service");?></td>
<td><?=gettext("Description");?></td>
<td><?=gettext("Status");?></td>
</tr>
</thead>
<tbody>
<?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>
</div>
</section>
</div>
</div>
</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