diff --git a/app/js/custom.js b/app/js/custom.js index 1923b38d..adc019cb 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -143,6 +143,47 @@ $(document).on("submit", ".js-dhcp-settings-form", function(e) { $(".js-add-dhcp-static-lease").trigger("click"); }); +$(document).on("click", ".js-add-dhcp-upstream-server", function(e) { + e.preventDefault(); + + var field = $("#add-dhcp-upstream-server-field") + var row = $("#dhcp-upstream-server").html().replace("{{ server }}", field.val()) + + if (field.val().trim() == "") { return } + + $(".js-dhcp-upstream-servers").append(row) + + field.val("") +}); + +$(document).on("click", ".js-remove-dhcp-upstream-server", function(e) { + e.preventDefault(); + $(this).parents(".js-dhcp-upstream-server").remove(); +}); + +$(document).on("submit", ".js-dhcp-settings-form", function(e) { + $(".js-add-dhcp-upstream-server").trigger("click"); +}); + +/** + * mark a form field, e.g. a select box, with the class `.js-field-preset` + * and give it an attribute `data-field-preset-target` with a text field's + * css selector. + * + * now, if the element marked `.js-field-preset` receives a `change` event, + * its value will be copied to all elements matching the selector in + * data-field-preset-target. + */ +$(document).on("change", ".js-field-preset", function(e) { + var selector = this.getAttribute("data-field-preset-target") + var value = "" + this.value + var syncValue = function(el) { el.value = value } + + if (value.trim() === "") { return } + + document.querySelectorAll(selector).forEach(syncValue) +}); + $(document).on("click", "#gen_wpa_passphrase", function(e) { $('#txtwpapassphrase').val(genPassword(63)); }); diff --git a/config/dns-servers.json b/config/dns-servers.json new file mode 100644 index 00000000..40713e58 --- /dev/null +++ b/config/dns-servers.json @@ -0,0 +1,27 @@ +{ + "Cloudflare": [ + "1.0.0.1", + "1.1.1.1" + ], + "German Privacy Foundation": [ + "62.141.58.13", + "85.25.251.254", + "87.118.100.175", + "94.75.228.29" + ], + "Google": [ + "8.8.4.4", + "8.8.8.8" + ], + "OpenDNS": [ + "208.67.220.220", + "208.67.222.222" + ], + "Quad9": [ + "9.9.9.9" + ], + "Yandex.DNS": [ + "77.88.8.2", + "77.88.8.88" + ] +} diff --git a/includes/dhcp.php b/includes/dhcp.php index 82d084d7..007a89a8 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -59,6 +59,13 @@ function DisplayDHCPConfig() } } + if ($_POST['no-resolv'] == "1") { + $config .= "no-resolv".PHP_EOL; + } + foreach ($_POST['server'] as $server) { + $config .= "server=$server".PHP_EOL; + } + if ($_POST['DNS1']) { $config .= "dhcp-option=6," . $_POST['DNS1']; if ($_POST['DNS2']) { @@ -126,6 +133,8 @@ function DisplayDHCPConfig() $dhcpHost = $conf["dhcp-host"]; $dhcpHost = empty($dhcpHost) ? [] : $dhcpHost; $dhcpHost = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ]; + $upstreamServers = is_array($conf['server']) ? $conf['server'] : [ $conf['server'] ]; + $upstreamServers = array_filter($upstreamServers); $DNS1 = ''; $DNS2 = ''; @@ -173,6 +182,7 @@ function DisplayDHCPConfig() "RangeEnd", "DNS1", "DNS2", + "upstreamServers", "arrRangeLeaseTime", "mselected", "hselected", diff --git a/includes/functions.php b/includes/functions.php index b75cf170..c5ba1a47 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -346,3 +346,27 @@ function mb_escapeshellarg($arg) return "\"$escaped_arg\""; } +function dnsServers() +{ + $data = json_decode(file_get_contents("./config/dns-servers.json")); + return (array) $data; +} + +function optionsForSelect($options) +{ + $html = ""; + foreach ($options as $key => $value) { + // optgroup + if (is_array($value)) { + $html .= ""; + $html .= optionsForSelect($value); + $html .= ""; + } + // option + else { + $key = is_int($key) ? $value : $key; + $html .= ""; + } + } + return $html; +} diff --git a/templates/dhcp.php b/templates/dhcp.php index bc69bef7..5b15a23c 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -1,3 +1,14 @@ + + + " name="savedhcpdsettings" /> + + " name="stopdhcpd" /> + + " name="startdhcpd" /> + + + +
@@ -19,8 +30,9 @@
-
- - " name="savedhcpdsettings" /> - - " name="stopdhcpd" /> - - " name="startdhcpd" /> - - + +
+ + +
+ +
+
+
+ +
+ +
+ aria-describedby="no-resolv-description"> + +
+

+ send DNS queries to the servers configured below exclusively. By default RaspAP also uses its upstream DHCP server's name servers.") ?> +
no-resolv to the dnsmasq configuration.") ?> +

+
+ +
+ +
+ +
+ +
+
+ +
+ +
+ +
+ "> +
+ +
+
+

+ + + ]/[domain/]][[#][@|[#]]"); ?> + +

+ +
+
+ + +
+ + + +
+

Client list

@@ -175,16 +248,8 @@
- - " name="savedhcpdsettings" /> - '; - } else { - echo''; - } - ?> - + +