40 lines
1.7 KiB
PHP
40 lines
1.7 KiB
PHP
<?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",
|
|
];
|
|
}
|
|
}
|
|
}
|