luci-mod-network: merge hosts with dns settings
authorVladislav Grigoryev <vg.aetera@gmail.com>
Sat, 7 Aug 2021 02:23:20 +0000 (05:23 +0300)
committerJo-Philipp Wich <jo@mein.io>
Mon, 9 Aug 2021 17:56:50 +0000 (19:56 +0200)
The current location for "Network > Hostnames" is confusing.
It is provided by Dnsmasq and partly overlaps with static leases.

Merge "Hostnames" with "Network > DHCP and DNS" as an extra tab.
Also add a simple explanation of the use case.

Signed-off-by: Vladislav Grigoryev <vg.aetera@gmail.com>
[Fix typo in label description string]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js
modules/luci-mod-network/htdocs/luci-static/resources/view/network/hosts.js [deleted file]
modules/luci-mod-network/root/usr/share/luci/menu.d/luci-mod-network.json

index cb1aa994725af43e49a509fdf585a4ff8824c65d..dd19c51286a21566617387a9e4987af97f9678b6 100644 (file)
@@ -252,6 +252,7 @@ return view.extend({
                s.tab('tftp', _('TFTP Settings'));
                s.tab('advanced', _('Advanced Settings'));
                s.tab('leases', _('Static Leases'));
+               s.tab('hosts', _('Hostnames'));
 
                s.taboption('general', form.Flag, 'domainneeded',
                        _('Domain required'),
@@ -496,6 +497,36 @@ return view.extend({
                        _('Prevent listening on these interfaces.'));
                o.optional = true;
 
+               o = s.taboption('hosts', form.SectionValue, '__hosts__', form.GridSection, 'domain', null,
+                       _('Hostnames are used to bind a domain name to an IP address. This setting is redundant for hostnames already configured with static leases, but it can be useful to rebind an FQDN.'));
+
+               ss = o.subsection;
+
+               ss.addremove = true;
+               ss.anonymous = true;
+               ss.sortable  = true;
+
+               so = ss.option(form.Value, 'name', _('Hostname'));
+               so.datatype = 'hostname';
+               so.rmempty = true;
+
+               so = ss.option(form.Value, 'ip', _('IP address'));
+               so.datatype = 'ipaddr';
+               so.rmempty = true;
+
+               var ipaddrs = {};
+
+               Object.keys(hosts).forEach(function(mac) {
+                       var addrs = L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4);
+
+                       for (var i = 0; i < addrs.length; i++)
+                               ipaddrs[addrs[i]] = hosts[mac].name || mac;
+               });
+
+               L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
+                       so.value(ipv4, '%s (%s)'.format(ipv4, ipaddrs[ipv4]));
+               });
+
                o = s.taboption('leases', form.SectionValue, '__leases__', form.GridSection, 'host', null,
                        _('Static leases are used to assign fixed IP addresses and symbolic hostnames to DHCP clients. They are also required for non-dynamic interface configurations where only hosts with a corresponding lease are served.') + '<br />' +
                        _('Use the <em>Add</em> Button to add a new lease entry. The <em>MAC address</em> identifies the host, the <em>IPv4 address</em> specifies the fixed address to use, and the <em>Hostname</em> is assigned as a symbolic name to the requesting host. The optional <em>Lease time</em> can be used to set non-standard host-specific lease time, e.g. 12h, 3d or infinite.'));
@@ -592,15 +623,6 @@ return view.extend({
                        return _('The IP address is outside of any DHCP pool address range');
                };
 
-               var ipaddrs = {};
-
-               Object.keys(hosts).forEach(function(mac) {
-                       var addrs = L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4);
-
-                       for (var i = 0; i < addrs.length; i++)
-                               ipaddrs[addrs[i]] = hosts[mac].name;
-               });
-
                L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
                        so.value(ipv4, ipaddrs[ipv4] ? '%s (%s)'.format(ipv4, ipaddrs[ipv4]) : ipv4);
                });
diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/hosts.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/hosts.js
deleted file mode 100644 (file)
index 93ebf5b..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-'use strict';
-'require view';
-'require rpc';
-'require form';
-
-return view.extend({
-       callHostHints: rpc.declare({
-               object: 'luci-rpc',
-               method: 'getHostHints',
-               expect: { '': {} }
-       }),
-
-       load: function() {
-               return this.callHostHints();
-       },
-
-       render: function(hosts) {
-               var m, s, o;
-
-               m = new form.Map('dhcp', _('Hostnames'));
-
-               s = m.section(form.GridSection, 'domain', _('Host entries'));
-               s.addremove = true;
-               s.anonymous = true;
-               s.sortable  = true;
-
-               o = s.option(form.Value, 'name', _('Hostname'));
-               o.datatype = 'hostname';
-               o.rmempty = true;
-
-               o = s.option(form.Value, 'ip', _('IP address'));
-               o.datatype = 'ipaddr';
-               o.rmempty = true;
-
-               var ipaddrs = {};
-
-               Object.keys(hosts).forEach(function(mac) {
-                       var addrs = L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4);
-
-                       for (var i = 0; i < addrs.length; i++)
-                               ipaddrs[addrs[i]] = hosts[mac].name || mac;
-               });
-
-               L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ipv4) {
-                       o.value(ipv4, '%s (%s)'.format(ipv4, ipaddrs[ipv4]));
-               });
-
-               return m.render();
-       }
-});
index 188c695f3fb95e8ae7e726d44aa1c66e33b8e551..844f8cc752466de51c7ef8f41abfdfecfb06bb59 100644 (file)
                }
        },
 
-       "admin/network/hosts": {
-               "title": "Hostnames",
-               "order": 40,
-               "action": {
-                       "type": "view",
-                       "path": "network/hosts"
-               },
-               "depends": {
-                       "acl": [ "luci-mod-network-dhcp" ],
-                       "uci": { "dhcp": true }
-               }
-       },
-
        "admin/network/routes": {
                "title": "Static Routes",
-               "order": 50,
+               "order": 40,
                "action": {
                        "type": "view",
                        "path": "network/routes"
@@ -86,7 +73,7 @@
 
        "admin/network/diagnostics": {
                "title": "Diagnostics",
-               "order": 60,
+               "order": 50,
                "action": {
                        "type": "view",
                        "path": "network/diagnostics"