status_services.php 10.1 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
    Copyright (C) 2014-2015 Deciso B.V.
5 6
    Copyright (C) 2005-2006 Colin Smith <ethethlay@gmail.com>
    Copyright (C) 2004-2005 Scott Ullrich
Ad Schellevis's avatar
Ad Schellevis committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
*/

require_once("guiconfig.inc");
32
require_once("services.inc");
33
require_once("vslb.inc");
34 35
require_once("system.inc");
require_once("unbound.inc");
36
require_once("pfsense-utils.inc");
37
require_once("openvpn.inc");
38
require_once("filter.inc");
39
require_once("vpn.inc");
40
require_once("interfaces.inc");
41
require_once("rrd.inc");
Ad Schellevis's avatar
Ad Schellevis committed
42

43 44
function openvpn_restart_by_vpnid($mode, $vpnid)
{
45 46
    $settings = openvpn_get_settings($mode, $vpnid);
    openvpn_restart($mode, $settings);
47 48
}

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
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;
Ad Schellevis's avatar
Ad Schellevis committed
66 67
}

68
function service_control_start($name, $extras) {
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    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));
133 134 135 136
}


function service_control_stop($name, $extras) {
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    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));
202 203 204 205
}


function service_control_restart($name, $extras) {
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    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");
277 278
}

Ad Schellevis's avatar
Ad Schellevis committed
279 280 281 282
include("head.inc");

?>

283
<body>
284
<?php include("fbegin.inc"); ?>
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
  <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);?>
                    </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>
328
<?php include("foot.inc"); ?>