From cfa3f9cfd3f6da203b1cb784096f002b102ca5c5 Mon Sep 17 00:00:00 2001 From: glaszig Date: Wed, 4 Mar 2020 19:43:22 +0100 Subject: [PATCH] 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 @@ +
+ +