Changed way service status is checked, so it generate less output.
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
## Sudo setup
|
## Sudo setup
|
||||||
There are two commands needed for this to work:
|
There are two commands needed for this to work:
|
||||||
- `systemctl status isc-dhcp-server.service` to check if service does work
|
- `systemctl is-active isc-dhcp-server.service` to check if service does work
|
||||||
- `dhcp-lease-list --parsable` to get leases data
|
- `dhcp-lease-list --parsable` to get leases data
|
||||||
|
|
||||||
### Example sudoers configuration
|
### Example sudoers configuration
|
||||||
```
|
```
|
||||||
Cmnd_Alias SYSTEMD_STATUS_DHCPD=/usr/bin/systemctl status isc-dhcp-server.service
|
Cmnd_Alias SYSTEMD_STATUS_DHCPD=/usr/bin/systemctl is-active isc-dhcp-server.service
|
||||||
Cmnd_Alias DHCP_LEASE_LIST=/usr/sbin/dhcp-lease-list --parsable
|
Cmnd_Alias DHCP_LEASE_LIST=/usr/sbin/dhcp-lease-list --parsable
|
||||||
|
|
||||||
www-data ALL= NOPASSWD: SYSTEMD_STATUS_DHCPD, DHCP_LEASE_LIST
|
www-data ALL= NOPASSWD: SYSTEMD_STATUS_DHCPD, DHCP_LEASE_LIST
|
||||||
|
|||||||
11
index.php
11
index.php
@@ -8,13 +8,14 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
$serviceStatusOKString = 'Active: active (running)';
|
$serviceStatusOKString = 'active';
|
||||||
|
|
||||||
$commandOutput = shell_exec("sudo /usr/bin/systemctl status isc-dhcp-server.service");
|
$commandOutput = shell_exec("sudo /usr/bin/systemctl is-active isc-dhcp-server.service");
|
||||||
$serviceStatus = false;
|
$serviceStatus = false;
|
||||||
|
|
||||||
if(str_contains($commandOutput, $serviceStatusOKString)) $serviceStatus = true;
|
if($commandOutput == $serviceStatusOKString) $serviceStatus = true;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if ($serviceStatus): ?>
|
<?php if ($serviceStatus): ?>
|
||||||
<div class="alert alert-success" role="alert">
|
<div class="alert alert-success" role="alert">
|
||||||
<h4 class="alert-heading">Service is running</h4>
|
<h4 class="alert-heading">Service is running</h4>
|
||||||
@@ -22,10 +23,6 @@
|
|||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
<h4 class="alert-heading">Service is stopped</h4>
|
<h4 class="alert-heading">Service is stopped</h4>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<hr>
|
|
||||||
<pre class="mb-0">
|
|
||||||
<?php echo $commandOutput; ?>
|
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
|
|||||||
Reference in New Issue
Block a user