diff --git a/dist/css/custom.css b/dist/css/custom.css index 17126ae5..be1b60d1 100644 --- a/dist/css/custom.css +++ b/dist/css/custom.css @@ -53,3 +53,13 @@ width:100%; height:300px; } + +.dhcp-static-leases { + margin-top: 1em; + margin-bottom: 1em; +} + +.dhcp-static-lease-row { + margin-top: 0.5em; + margin-bottom: 0.5em; +} \ No newline at end of file diff --git a/includes/dhcp.php b/includes/dhcp.php index ec85419f..cc5133c1 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -47,7 +47,16 @@ function DisplayDHCPConfig() $config .= $_POST['RangeLeaseTime']; } - $config .= $_POST['RangeLeaseTimeUnits']; + $config .= $_POST['RangeLeaseTimeUnits'].PHP_EOL; + + for ($i=0; $i < count($_POST["static_leases"]["mac"]); $i++) { + $mac = trim($_POST["static_leases"]["mac"][$i]); + $ip = trim($_POST["static_leases"]["ip"][$i]); + if ($mac != "" && $ip != "") { + $config .= "dhcp-host=$mac,$ip".PHP_EOL; + } + } + file_put_contents("/tmp/dhcpddata", $config); system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return); } else { @@ -114,6 +123,9 @@ function DisplayDHCPConfig() $RangeEnd = $arrRange[1]; $RangeMask = $arrRange[2]; $leaseTime = $arrRange[3]; + $dhcpHost = $conf["dhcp-host"]; + $dhcpHost = empty($dhcpHost) ? [] : $dhcpHost; + $dhcpHost = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ]; $hselected = ''; $mselected = ''; @@ -144,10 +156,13 @@ function DisplayDHCPConfig()

showMessages(); ?>

+
+ @@ -155,8 +170,6 @@ function DisplayDHCPConfig()

DHCP server settings

- -
@@ -216,7 +229,6 @@ foreach ($interfaces as $inet) { echo''; } ?> -
@@ -256,7 +268,65 @@ foreach ($leases as $lease) {
+ +
+
+ + +
+
+ " class="form-control"> +
+
+ " class="form-control"> +
+
+ +
+
+ +
+ +
+
+
+ " class="form-control" autofocus="autofocus"> +
+
+ " class="form-control"> +
+
+ +
+
+ + + + " name="savedhcpdsettings" /> + '; + } else { + echo''; + } + ?> +
+
+
diff --git a/includes/functions.php b/includes/functions.php index 64b66f15..06ef2e0f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -145,9 +145,17 @@ function ParseConfig($arrConfig) $config = array(); foreach ($arrConfig as $line) { $line = trim($line); - if ($line != "" && $line[0] != "#") { - $arrLine = explode("=", $line); - $config[$arrLine[0]] = ( count($arrLine) > 1 ? $arrLine[1] : true ); + if ($line == "" || $line[0] == "#") { continue; } + + list($option, $value) = array_map("trim", explode("=", $line, 2)); + + if (empty($config[$option])) { + $config[$option] = $value ?: true; + } else { + if (!is_array($config[$option])) { + $config[$option] = [ $config[$option] ]; + } + $config[$option][] = $value; } } return $config; diff --git a/js/custom.js b/js/custom.js index d660f45e..7d8875bf 100644 --- a/js/custom.js +++ b/js/custom.js @@ -122,6 +122,33 @@ function applyNetworkSettings() { }); } +$(document).on("click", ".js-add-dhcp-static-lease", function(e) { + e.preventDefault(); + var container = $(".js-new-dhcp-static-lease"); + var mac = $("input[name=mac]", container).val().trim(); + var ip = $("input[name=ip]", container).val().trim(); + if (mac == "" || ip == "") { + return; + } + + var row = $("#js-dhcp-static-lease-row").html() + .replace("{{ mac }}", mac) + .replace("{{ ip }}", ip); + $(".js-dhcp-static-lease-container").append(row); + + $("input[name=mac]", container).val(""); + $("input[name=ip]", container).val(""); +}); + +$(document).on("click", ".js-remove-dhcp-static-lease", function(e) { + e.preventDefault(); + $(this).parents(".js-dhcp-static-lease-row").remove(); +}); + +$(document).on("submit", ".js-dhcp-settings-form", function(e) { + $(".js-add-dhcp-static-lease").trigger("click"); +}); + function setupBtns() { $('#btnSummaryRefresh').click(function(){getAllInterfaces();});