diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php
index b345ca87d..cac5dd7be 100644
--- a/scripts/pi-hole/php/func.php
+++ b/scripts/pi-hole/php/func.php
@@ -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
diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php
index 8b528d24e..6afae2b2d 100644
--- a/scripts/pi-hole/php/savesettings.php
+++ b/scripts/pi-hole/php/savesettings.php
@@ -496,6 +496,12 @@ function addStaticDHCPLease($mac, $ip, $hostname)
$error .= 'To IP ('.htmlspecialchars($to).') is invalid!
';
}
+ // Validate to Subnet Mask
+ $subnetMask = $_POST['subnetMask'];
+ if (!validSubnetMask($subnetMask)) {
+ $error .= 'Subnet Mask ('.htmlspecialchars($subnetMask).') is invalid!
';
+ }
+
// Validate router IP
$router = $_POST['router'];
if (!validIP($router)) {
@@ -531,7 +537,7 @@ function addStaticDHCPLease($mac, $ip, $hostname)
}
if (!strlen($error)) {
- pihole_execute('-a enabledhcp '.$from.' '.$to.' '.$router.' '.$leasetime.' '.$domain.' '.$ipv6.' '.$rapidcommit);
+ pihole_execute('-a enabledhcp '.$from.' '.$to.' '.$subnetMask.' '.$router.' '.$leasetime.' '.$domain.' '.$ipv6.' '.$rapidcommit);
$success .= 'The DHCP server has been activated '.htmlspecialchars($type);
}
} else {
diff --git a/settings.php b/settings.php
index 6ad968d97..5d59baa7d 100644
--- a/settings.php
+++ b/settings.php
@@ -412,6 +412,11 @@
} else {
$DHCPend = '';
}
+ if (isset($setupVars['DHCP_SUBNET_MASK'])) {
+ $DHCPSubnetMask = $setupVars['DHCP_SUBNET_MASK'];
+ } else {
+ $DHCPSubnetMask = '255.255.255.0'; // Setting default value here
+ }
if (isset($setupVars['DHCP_ROUTER'])) {
$DHCProuter = $setupVars['DHCP_ROUTER'];
} else {
@@ -442,6 +447,7 @@
$DHCP = false;
$DHCPstart = '';
$DHCPend = '';
+ $DHCPsubnetMask = '255.255.255.0';
$DHCProuter = '';
// Try to guess initial settings
@@ -506,7 +512,19 @@