wip2
This commit is contained in:
39
load-hosts.php
Normal file
39
load-hosts.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once "load-conf.php";
|
||||
|
||||
$hosts = [];
|
||||
if (isset($conf["dhcp-hostsfile"]) && file_exists($conf["dhcp-hostsfile"])) {
|
||||
foreach(file($conf["dhcp-hostsfile"]) as $line) {
|
||||
if (preg_match(
|
||||
"/^(?<hwaddrs>$macPtn(,$macPtn)*)(id:[^,]+)*(?:,(?:tag|set):(?<tag>$namePtn))?(?:,(?<ipaddr>$ipPtn))?(?:,(?<hostnames>$domainPtn(,$domainPtn)*))?(?:,(?<lease_time>$timePtn|infinite))?([ \t]+#services:(?<services>\w[,\w]*))?$commentPtn$/",
|
||||
$line, $host, PREG_UNMATCHED_AS_NULL
|
||||
)) {
|
||||
$hosts[ip2long($host["ipaddr"])] = [
|
||||
"hwaddrs" => $host["hwaddrs"] ? explode(',', $host["hwaddrs"]) : [],
|
||||
"tag" => $host["tag"] ?? "local",
|
||||
"hostnames" => $host["hostnames"] ? explode(',', $host["hostnames"]) : [],
|
||||
"lease_time" => $host["lease_time"],
|
||||
"services" => $host["services"]? explode(',', $host["services"]) : [],
|
||||
"comment" => $host["comment"],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($conf["dhcp-leasefile"]) && file_exists($conf["dhcp-leasefile"])) {
|
||||
foreach(file($conf["dhcp-leasefile"]) as $line) {
|
||||
if (preg_match(
|
||||
"/^(?<expiry>\d+) (?<hwaddr>$macPtn) (?<ipaddr>$ipPtn) (?:\*|(?<hostname>\$domainPtn)) (?<duid>[^ ]+)(?: (?<tag>.*))?$/",
|
||||
$line, $lease, PREG_UNMATCHED_AS_NULL
|
||||
)) {
|
||||
$hosts[ip2long($lease["ipaddr"])] = [
|
||||
"hwaddrs" => [$lease["hwaddr"]],
|
||||
"tag" => $host["tag"] ?? "local",
|
||||
"hostnames" => [$lease["hostname"]],
|
||||
"lease_time" => null,
|
||||
"services" => [],
|
||||
"comment" => "DHCP dynamique",
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user