mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Merge pull request #969 from fareg/master
DHCP static leases w/ optional comment
This commit is contained in:
@@ -154,6 +154,20 @@ function validateDHCPInput()
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares to string IPs
|
||||
*
|
||||
* @param string $ip1
|
||||
* @param string $ip2
|
||||
* @return boolean $result
|
||||
*/
|
||||
function compareIPs($ip1, $ip2)
|
||||
{
|
||||
$ipu1 = sprintf('%u', ip2long($ip1["ip"])) + 0;
|
||||
$ipu2 = sprintf('%u', ip2long($ip2["ip"])) + 0;
|
||||
return $ipu1 > $ipu2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a dnsmasq configuration
|
||||
*
|
||||
@@ -171,13 +185,25 @@ function updateDnsmasqConfig($iface,$status)
|
||||
$config .= $_POST['RangeLeaseTime'];
|
||||
}
|
||||
$config .= $_POST['RangeLeaseTimeUnits'].PHP_EOL;
|
||||
// Static leases
|
||||
$staticLeases = array();
|
||||
for ($i=0; $i < count($_POST["static_leases"]["mac"]); $i++) {
|
||||
$mac = trim($_POST["static_leases"]["mac"][$i]);
|
||||
$ip = trim($_POST["static_leases"]["ip"][$i]);
|
||||
$comment = trim($_POST["static_leases"]["comment"][$i]);
|
||||
if ($mac != "" && $ip != "") {
|
||||
$config .= "dhcp-host=$mac,$ip".PHP_EOL;
|
||||
$staticLeases[] = array('mac' => $mac, 'ip' => $ip, 'comment' => $comment);
|
||||
}
|
||||
}
|
||||
// Sort ascending by IPs
|
||||
usort($staticLeases, "compareIPs");
|
||||
// Update config
|
||||
for ($i = 0; $i < count($staticLeases); $i++) {
|
||||
$mac = $staticLeases[$i]['mac'];
|
||||
$ip = $staticLeases[$i]['ip'];
|
||||
$comment = $staticLeases[$i]['comment'];
|
||||
$config .= "dhcp-host=$mac,$ip # $comment".PHP_EOL;
|
||||
}
|
||||
if ($_POST['no-resolv'] == "1") {
|
||||
$config .= "no-resolv".PHP_EOL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user