diff --git a/dist/css/custom.css b/dist/css/custom.css index 1b5795e4..8901c950 100644 --- a/dist/css/custom.css +++ b/dist/css/custom.css @@ -59,3 +59,13 @@ pre.unstyled { background-color: transparent; padding: 0; } + +.dhcp-static-leases { + margin-top: 1em; + margin-bottom: 1em; +} + +.dhcp-static-lease-row { + margin-top: 0.5em; + margin-bottom: 0.5em; +} 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/includes/hostapd.php b/includes/hostapd.php index 317642ab..b42f7147 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -11,7 +11,12 @@ function DisplayHostAPDConfig() $status = new StatusMessages(); $arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini'); $arrConfig = array(); - $arr80211Standard = array('a','b','g','n'); + $arr80211Standard = [ + 'a' => '802.11a - 5 GHz', + 'b' => '802.11b - 2.4 GHz', + 'g' => '802.11g - 2.4 GHz', + 'n' => '802.11n - 2.4 GHz' + ]; $arrSecurity = array(1 => 'WPA', 2 => 'WPA2', 3 => 'WPA+WPA2', 'none' => _("None")); $arrEncType = array('TKIP' => 'TKIP', 'CCMP' => 'CCMP', 'TKIP CCMP' => 'TKIP+CCMP'); exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces); 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();});