diff --git a/assets/App.js b/assets/App.js index 4ffa2b1..8cb2948 100644 --- a/assets/App.js +++ b/assets/App.js @@ -35,6 +35,10 @@ App.auth = async function () { this.fillNetworks(); $("#panel").show(); + + let invalidNetworks = await JSONRPC.__invoke("getInvalidNetworks"); + + $("body").append(`There are invalid networks ` +invalidNetworks.join("
")+`
`); } App.fillNetworks = function () { diff --git a/classes/IPv4Subnet.php b/classes/IPv4Subnet.php new file mode 100644 index 0000000..467907b --- /dev/null +++ b/classes/IPv4Subnet.php @@ -0,0 +1,46 @@ +address = $subnetAddress; + if (ip2long($subnetAddress) === false) { + throw new RuntimeException("Invalid subnet address: " . $subnetAddress); + } + $this->prefix = $prefix; + if ($prefix < 0 or $prefix > 32) { + throw new RuntimeException("Invalid subnet prefix: " . $prefix); + } + } + + public function getFirstAddress() + { + $a = ip2long($this->address); + $mask = ip2long($this->getNetMask()); + return long2ip($a & $mask); + } + + public function getLastAddress() + { + return long2ip(ip2long($this->getFirstAddress()) + $this->getAddressCount() - 1); + } + + public function getAddressCount() + { + return pow(2, 32 - $this->prefix); + } + + public function getNetMask() + { + return long2ip(-1 << (32 - $this->prefix)); + } +} \ No newline at end of file diff --git a/classes/RPC.php b/classes/RPC.php index 113d150..7acc246 100644 --- a/classes/RPC.php +++ b/classes/RPC.php @@ -88,6 +88,20 @@ class RPC return (new NetworkConfigReader())->getConfigs(); } + public function getInvalidNetworks(): array + { + $this->checkAuth(); + $invalid = []; + foreach ((new NetworkConfigReader())->getConfigs() as $config) { + foreach ($config["networks"] as $network) { + if (!RouteUtil::validateSubnet($network)) { + $invalid[] = $network; + } + } + } + return $invalid; + } + public function logout(): void { diff --git a/classes/RouteUtil.php b/classes/RouteUtil.php new file mode 100644 index 0000000..db9a83a --- /dev/null +++ b/classes/RouteUtil.php @@ -0,0 +1,18 @@ +getFirstAddress(); + } catch (Exception $e) { + return false; + } + } +} \ No newline at end of file