Skip to content

Commit

Permalink
Add validSubnetMask function
Browse files Browse the repository at this point in the history
This function is used to validate a subnetmask

Signed-off-by: biodigitalfish <[email protected]>
  • Loading branch information
biodigitalfish authored Nov 2, 2023
1 parent 2589542 commit 60c8103
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/pi-hole/php/func.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ function validIP($address)
return !filter_var($address, FILTER_VALIDATE_IP) === false;
}

function validSubnetMask($subnetMask)
{
$octets = explode('.', $subnetMask);
if (count($octets) != 4) {
return false;
}

$subnetBinary = '';
foreach ($octets as $octet) {
if (!is_numeric($octet) || $octet < 0 || $octet > 255) {
return false;
}
$subnetBinary .= str_pad(decbin($octet), 8, '0', STR_PAD_LEFT);
}

if (strpos($subnetBinary, '01') !== false) {
return false;
}

return true;
}

function validCIDRIP($address)
{
// This validation strategy has been taken from ../js/groups-common.js
Expand Down

0 comments on commit 60c8103

Please sign in to comment.