Initial commit
This commit is contained in:
14
REAME.md
Normal file
14
REAME.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# DHCPAdmin
|
||||
|
||||
## Sudo setup
|
||||
There are two commands needed for this to work:
|
||||
- `systemctl status isc-dhcp-server.service` to check if service does work
|
||||
- `dhcp-lease-list --parsable` to get leases data
|
||||
|
||||
### Example sudoers configuration
|
||||
```
|
||||
Cmnd_Alias SYSTEMD_STATUS_DHCPD=/usr/bin/systemctl status isc-dhcp-server.service
|
||||
Cmnd_Alias DHCP_LEASE_LIST=/usr/sbin/dhcp-lease-list --parsable
|
||||
|
||||
www-data ALL= NOPASSWD: SYSTEMD_STATUS_DHCPD, DHCP_LEASE_LIST
|
||||
```
|
||||
69
index.php
Normal file
69
index.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>DHCPAdmin</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
$serviceStatusOKString = 'Active: active (running)';
|
||||
|
||||
$commandOutput = shell_exec("sudo /usr/bin/systemctl status isc-dhcp-server.service");
|
||||
$serviceStatus = false;
|
||||
|
||||
if(str_contains($commandOutput, $serviceStatusOKString)) $serviceStatus = true;
|
||||
?>
|
||||
<?php if ($serviceStatus): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<h4 class="alert-heading">Service is running</h4>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<h4 class="alert-heading">Service is stopped</h4>
|
||||
<?php endif; ?>
|
||||
<hr>
|
||||
<pre class="mb-0">
|
||||
<?php echo $commandOutput; ?>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">MAC</th>
|
||||
<th scope="col">IP</th>
|
||||
<th scope="col">HOSTNAME</th>
|
||||
<th scope="col">BEGIN</th>
|
||||
<th scope="col">END</th>
|
||||
<th scope="col">MANUFACTURER</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$sourceData = shell_exec("sudo /usr/sbin/dhcp-lease-list --parsable");
|
||||
$splittedData = explode(PHP_EOL, $sourceData);
|
||||
|
||||
for($i = 0; $i < count($splittedData); $i++)
|
||||
{
|
||||
$splittedDataRow = explode(' ', $splittedData[$i]);
|
||||
if(!isset($splittedDataRow[2])) continue;
|
||||
|
||||
echo "<tr>\n";
|
||||
echo "\t<th scope='row'>".$i."</th>\n";
|
||||
echo "\t<td>".$splittedDataRow[1]."</td>\n";
|
||||
echo "\t<td>".$splittedDataRow[3]."</td>\n";
|
||||
echo "\t<td>".$splittedDataRow[5]."</td>\n";
|
||||
echo "\t<td>".$splittedDataRow[7].' '.$splittedDataRow[8]."</td>\n";
|
||||
echo "\t<td>".$splittedDataRow[10].' '.$splittedDataRow[11]."</td>\n";
|
||||
echo "\t<td>".$splittedDataRow[13]."</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user