diff --git a/db.php b/db.php deleted file mode 100644 index 1446121..0000000 --- a/db.php +++ /dev/null @@ -1,18 +0,0 @@ -getMessage(); - exit(); -} - -$db->exec(<<[a-z0-9]+) inet (?$ipPtn)\/(?\d+) brd (?$ipPtn)/", `ip -o -4 a`, $network); + $ip_addr = ip2long($network["ipaddr"]); + $network["cidr_mask"] = $network["mask"]; + $mask = $long_mask[(int)$network["mask"]]; + $tag = "local"; + $network["network-addr"] = $ip_addr & $netmask; + $network["netmask"] = long2ip($mask); + $network["broadcast"] = ip2long($network["broadcast"]); + if (preg_match("/default via ($ipPtn)/", `ip -4 route`, $router)) { + $network["router"] = $router[1]; + } +} +?> + + + + + + IPAM + + + + + + + +
+

Éditer un réseau

+
+ +
+ + +
+
+
+ +
+ " + value=""/> +
+
+
+ + + +
+
+
+ + " + value=""/> +
+
+ + + +
+

DHCP dynamique

+
+
+ +
+ " + value=""/> +
+
+
+ +
+ " + value=""/> +
+
+
+ +
+
+ + diff --git a/index.php b/index.php index c9220bb..c1ddfc3 100644 --- a/index.php +++ b/index.php @@ -1,100 +1,46 @@ + - - - - IPAM - - - - - - -
-
-
-
- - -
-
-
- -
- -
.
- -
.
- -
.
- -
-
- -
- -
-
/
- -
-
- -
- -
-
-
- - \ No newline at end of file + + + + IPAM + + + + + + + +
+

Réseaux

+ +
+ + diff --git a/ipam.conf b/ipam.conf new file mode 100644 index 0000000..eb601b1 --- /dev/null +++ b/ipam.conf @@ -0,0 +1,4 @@ +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 diff --git a/load-conf.php b/load-conf.php new file mode 100644 index 0000000..797b249 --- /dev/null +++ b/load-conf.php @@ -0,0 +1,29 @@ + "/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]*(?:# ?(?.*))?"; diff --git a/load-hosts.php b/load-hosts.php new file mode 100644 index 0000000..146eb49 --- /dev/null +++ b/load-hosts.php @@ -0,0 +1,39 @@ +$macPtn(,$macPtn)*)(id:[^,]+)*(?:,(?:tag|set):(?$namePtn))?(?:,(?$ipPtn))?(?:,(?$domainPtn(,$domainPtn)*))?(?:,(?$timePtn|infinite))?([ \t]+#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( + "/^(?\d+) (?$macPtn) (?$ipPtn) (?:\*|(?\$domainPtn)) (?[^ ]+)(?: (?.*))?$/", + $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", + ]; + } + } +} diff --git a/load-networks.php b/load-networks.php new file mode 100644 index 0000000..7bc6a21 --- /dev/null +++ b/load-networks.php @@ -0,0 +1,78 @@ +$namePtn),)?option:(?