From a3c8def1200d58d8ff16c8815e0c6d727e523404 Mon Sep 17 00:00:00 2001 From: glaszig Date: Fri, 28 Feb 2020 23:37:52 +0100 Subject: [PATCH 01/19] added ui to manage upstream dns servers --- app/js/custom.js | 22 ++++++++++++++++++++++ includes/dhcp.php | 6 ++++++ templates/dhcp.php | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/app/js/custom.js b/app/js/custom.js index 1923b38d..3638ed4d 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -143,6 +143,28 @@ $(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"); +}); + $(document).on("click", "#gen_wpa_passphrase", function(e) { $('#txtwpapassphrase').val(genPassword(63)); }); diff --git a/includes/dhcp.php b/includes/dhcp.php index 82d084d7..63b56831 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -59,6 +59,10 @@ function DisplayDHCPConfig() } } + foreach ($_POST['server'] as $server) { + $config .= "server=$server".PHP_EOL; + } + if ($_POST['DNS1']) { $config .= "dhcp-option=6," . $_POST['DNS1']; if ($_POST['DNS2']) { @@ -126,6 +130,7 @@ 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'] ]; $DNS1 = ''; $DNS2 = ''; @@ -173,6 +178,7 @@ function DisplayDHCPConfig() "RangeEnd", "DNS1", "DNS2", + "upstreamServers", "arrRangeLeaseTime", "mselected", "hselected", diff --git a/templates/dhcp.php b/templates/dhcp.php index 3b06e531..133e76dd 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -84,6 +84,45 @@ +
+
+ + +
+ +
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ + ]/[domain/]][[#][@|[#]]"); ?> + +
+
+
+ + + + " name="savedhcpdsettings" /> From 6bb4abac560f8e96f19acbc635988d5c2169eec1 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:33:51 +0100 Subject: [PATCH 02/19] added checkbox for no-resolv option in dnsmasq.conf --- includes/dhcp.php | 3 +++ templates/dhcp.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/includes/dhcp.php b/includes/dhcp.php index 63b56831..26625416 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -59,6 +59,9 @@ function DisplayDHCPConfig() } } + if ($_POST['no-resolv'] == "1") { + $config .= "no-resolv".PHP_EOL; + } foreach ($_POST['server'] as $server) { $config .= "server=$server".PHP_EOL; } diff --git a/templates/dhcp.php b/templates/dhcp.php index 133e76dd..9088d155 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -88,6 +88,15 @@
+
+ + 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.") ?> +

+
+
From 835d2f2a426346125e93d9dc7a9eab8545054f2d Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:34:20 +0100 Subject: [PATCH 03/19] removed superfluous class attribute --- templates/dhcp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 9088d155..5941ad6c 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -86,7 +86,7 @@
- +
From 896797a6d60735f74ff07c5080f2a6593b15a626 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:35:23 +0100 Subject: [PATCH 04/19] fixed aria label --- templates/dhcp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 5941ad6c..7fc4c5e7 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -110,12 +110,12 @@
- +
- + ]/[domain/]][[#][@|[#]]"); ?>
From 56d7a748794e957dc049f38d59a6bc1243be2c43 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:37:23 +0100 Subject: [PATCH 05/19] improved upstream dns server help text --- templates/dhcp.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 7fc4c5e7..e2aa9854 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -115,9 +115,12 @@
- - ]/[domain/]][[#][@|[#]]"); ?> - +

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

From dc77f304bf64fdf8b7f7c9a67afadc1c6a0db2a2 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:43:23 +0100 Subject: [PATCH 06/19] added note about no-resolv dnsmasq option --- templates/dhcp.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/dhcp.php b/templates/dhcp.php index e2aa9854..8114198f 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -94,6 +94,7 @@

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.") ?>

From f3e8f0e64d63d4e17036806d475548591e0c7505 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:49:59 +0100 Subject: [PATCH 07/19] fixed heading --- templates/dhcp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 8114198f..fd14058b 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -86,7 +86,7 @@
- +
From 9f672549f2e2a29199353937108bc204f3d32078 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:50:06 +0100 Subject: [PATCH 08/19] added placeholder --- templates/dhcp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index fd14058b..708f54d6 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -111,7 +111,7 @@
- + ">
From 1efbb5273860b1a7ac9449dc1898ecbf3abb437e Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 18:55:57 +0100 Subject: [PATCH 09/19] added label for new upstream dhcp server field --- templates/dhcp.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/dhcp.php b/templates/dhcp.php index 708f54d6..cc40cb74 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -110,6 +110,7 @@
+
">
From 0db3d151ee421f06d3ee3586d9d79f7236736d30 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 19:02:27 +0100 Subject: [PATCH 10/19] use bootstrap's pretty custom-switch --- templates/dhcp.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index cc40cb74..62bb8b68 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -88,10 +88,12 @@
-
+
- aria-describedby="no-resolv-description"> - +
+ 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.") ?> From 3ce99eeaa70e5e660bfc1e12053e769f5e25d8fa Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 19:03:49 +0100 Subject: [PATCH 11/19] improved checkbox label --- templates/dhcp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 62bb8b68..a9eda449 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -92,7 +92,7 @@

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.") ?> From 9c3c27cb715afc78b0030d7fe2fcba7451422f34 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 29 Feb 2020 19:07:31 +0100 Subject: [PATCH 12/19] small input groups for upstream dns servers --- templates/dhcp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index a9eda449..c85a1589 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -102,7 +102,7 @@

-
+
@@ -130,7 +130,7 @@
+ +
@@ -236,16 +243,8 @@
- - " name="savedhcpdsettings" /> - '; - } else { - echo''; - } - ?> - + +
From e037bd92e710b3d43e54f3e936388671087590cc Mon Sep 17 00:00:00 2001 From: glaszig Date: Wed, 4 Mar 2020 18:23:51 +0100 Subject: [PATCH 16/19] prevent empty upstream server field if non is set --- includes/dhcp.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/dhcp.php b/includes/dhcp.php index 26625416..007a89a8 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -134,6 +134,7 @@ function DisplayDHCPConfig() $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 = ''; From 6c6de51a45927e5d7130903060fb7a94f7da32b4 Mon Sep 17 00:00:00 2001 From: glaszig Date: Wed, 4 Mar 2020 18:26:21 +0100 Subject: [PATCH 17/19] improved dhcp tab label "advanced" --- templates/dhcp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 4df6698b..e40015d1 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -32,7 +32,7 @@ From cfa3f9cfd3f6da203b1cb784096f002b102ca5c5 Mon Sep 17 00:00:00 2001 From: glaszig Date: Wed, 4 Mar 2020 19:43:22 +0100 Subject: [PATCH 18/19] added selectable hosted dns servers --- app/js/custom.js | 19 +++++++++++++++++++ config/dns-servers.json | 27 +++++++++++++++++++++++++++ includes/functions.php | 24 ++++++++++++++++++++++++ templates/dhcp.php | 7 +++++++ 4 files changed, 77 insertions(+) create mode 100644 config/dns-servers.json diff --git a/app/js/custom.js b/app/js/custom.js index 3638ed4d..adc019cb 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -165,6 +165,25 @@ $(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/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 e40015d1..50f9b4f1 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -139,6 +139,13 @@
+
+ +

From 5259102b1853a969427c630794caf9ee8d66ea8e Mon Sep 17 00:00:00 2001 From: glaszig Date: Wed, 4 Mar 2020 19:49:07 +0100 Subject: [PATCH 19/19] optimized select box position --- templates/dhcp.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/templates/dhcp.php b/templates/dhcp.php index 50f9b4f1..254ed1e7 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -139,19 +139,17 @@

-
- -

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

+