added ui to manage upstream dns servers

This commit is contained in:
glaszig 2020-02-28 23:37:52 +01:00
parent 2120b0e215
commit a3c8def120
3 changed files with 67 additions and 0 deletions

View file

@ -143,6 +143,28 @@ $(document).on("submit", ".js-dhcp-settings-form", function(e) {
$(".js-add-dhcp-static-lease").trigger("click"); $(".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) { $(document).on("click", "#gen_wpa_passphrase", function(e) {
$('#txtwpapassphrase').val(genPassword(63)); $('#txtwpapassphrase').val(genPassword(63));
}); });

View file

@ -59,6 +59,10 @@ function DisplayDHCPConfig()
} }
} }
foreach ($_POST['server'] as $server) {
$config .= "server=$server".PHP_EOL;
}
if ($_POST['DNS1']) { if ($_POST['DNS1']) {
$config .= "dhcp-option=6," . $_POST['DNS1']; $config .= "dhcp-option=6," . $_POST['DNS1'];
if ($_POST['DNS2']) { if ($_POST['DNS2']) {
@ -126,6 +130,7 @@ function DisplayDHCPConfig()
$dhcpHost = $conf["dhcp-host"]; $dhcpHost = $conf["dhcp-host"];
$dhcpHost = empty($dhcpHost) ? [] : $dhcpHost; $dhcpHost = empty($dhcpHost) ? [] : $dhcpHost;
$dhcpHost = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ]; $dhcpHost = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ];
$upstreamServers = is_array($conf['server']) ? $conf['server'] : [ $conf['server'] ];
$DNS1 = ''; $DNS1 = '';
$DNS2 = ''; $DNS2 = '';
@ -173,6 +178,7 @@ function DisplayDHCPConfig()
"RangeEnd", "RangeEnd",
"DNS1", "DNS1",
"DNS2", "DNS2",
"upstreamServers",
"arrRangeLeaseTime", "arrRangeLeaseTime",
"mselected", "mselected",
"hselected", "hselected",

View file

@ -84,6 +84,45 @@
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-6">
<label class="form-label"><?php echo _("Upstream DNS servers") ?></label>
<div class="js-dhcp-upstream-servers">
<?php foreach ($upstreamServers as $server): ?>
<div class="form-group input-group js-dhcp-upstream-server">
<input type="text" class="form-control" name="server[]" value="<?php echo $server ?>">
<div class="input-group-append">
<button class="btn btn-outline-secondary js-remove-dhcp-upstream-server" type="button"><i class="fas fa-minus"></i></button>
</div>
</div>
<?php endforeach ?>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" id="add-dhcp-upstream-server-field" aria-describedby="passwordHelpBlock">
<div class="input-group-append">
<button type="button" class="btn btn-outline-secondary js-add-dhcp-upstream-server"><i class="fas fa-plus"></i></button>
</div>
</div>
<code id="passwordHelpBlock" class="form-text text-muted">
<small><?php echo htmlspecialchars("[/[<domain>]/[domain/]][<ipaddr>[#<port>][@<source-ip>|<interface>[#<port>]]"); ?></small>
</code>
</div>
</div>
</div>
<template id="dhcp-upstream-server">
<div class="form-group input-group js-dhcp-upstream-server">
<input type="text" class="form-control" name="server[]" value="{{ server }}">
<div class="input-group-append">
<button class="btn btn-outline-secondary js-remove-dhcp-upstream-server" type="button"><i class="fas fa-minus"></i></button>
</div>
</div>
</template>
<?php if (!RASPI_MONITOR_ENABLED) : ?> <?php if (!RASPI_MONITOR_ENABLED) : ?>
<input type="submit" class="btn btn-outline btn-primary" value="<?php echo _("Save settings"); ?>" name="savedhcpdsettings" /> <input type="submit" class="btn btn-outline btn-primary" value="<?php echo _("Save settings"); ?>" name="savedhcpdsettings" />
<?php if ($dnsmasq_state) : ?> <?php if ($dnsmasq_state) : ?>