ipam/load-conf.php
2025-05-27 02:08:54 +02:00

30 lines
827 B
PHP

<?php
$conf_paths = [
"/etc/dnsmasq.d/ipam.conf",
__DIR__ . "/ipam.conf"
];
$default = [
"dhcp-optsfile" => "/var/lib/misc/dhcp.options",
"dhcp-hostsfile" => "/var/lib/misc/dhcp.hosts",
"dhcp-leasefile" => "/var/lib/misc/dnsmasq.leases",
"conf-file" => "/var/lib/misc/dhcp.ranges",
];
foreach($conf_paths as $path) {
if (file_exists($path)) {
$conf = array_merge($default, parse_ini_file($path, true, INI_SCANNER_TYPED));
break;
}
}
$namePtn = "[a-zA-Z_][\w-]*";
$ipPtn = "\d+\.\d+\.\d+\.\d+";
$macPtn = "[\da-f]{2}(?:[:-][\da-f]{2}){5}";
$domainPtn = "[\w-]+(\.[\w-]+)*";
$ifacePtn = "[\w,]+";
$modesPtn = "static|proxya-only|slaac|ra-names|ra-stateless|ra-advrouter|off-link";
$timePtn = "\d+[mhds]";
$commentPtn = "[ \t]*(?:# ?(?<comment>.*))?";