From 88f86a3fba91442793cc705f54df177fe6a6388d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Wed, 15 Oct 2025 19:40:36 +0200 Subject: [PATCH] luci-mod-network: remove unused code from dhcp/dns MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Now that all options have been organized per view, remove unused code from both. Signed-off-by: David Härdeman --- .../resources/view/network/dhcp.js | 102 --------- .../luci-static/resources/view/network/dns.js | 199 +----------------- 2 files changed, 3 insertions(+), 298 deletions(-) diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js index 3f437fcbbe..07791ea048 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js @@ -158,65 +158,6 @@ function validateHostname(sid, s) { return true; } -function validateAddressList(sid, s) { - if (s == null || s == '') - return true; - - var m = s.match(/^\/(.+)\/$/), - names = m ? m[1].split(/\//) : [ s ]; - - for (var i = 0; i < names.length; i++) { - var res = validateHostname(sid, names[i]); - - if (res !== true) - return res; - } - - return true; -} - -function validateServerSpec(sid, s) { - if (s == null || s == '') - return true; - - var m = s.match(/^(\/.*\/)?(.*)$/); - if (!m) - return _('Expecting: %s').format(_('valid hostname')); - - if (m[1] != '//' && m[1] != '/#/') { - var res = validateAddressList(sid, m[1]); - if (res !== true) - return res; - } - - if (m[2] == '' || m[2] == '#') - return true; - - // ipaddr%scopeid#srvport@source@interface#srcport - - m = m[2].match(/^([0-9a-f:.]+)(?:%[^#@]+)?(?:#(\d+))?(?:@([0-9a-f:.]+)(?:@[^#]+)?(?:#(\d+))?)?$/); - - if (!m) - return _('Expecting: %s').format(_('valid IP address')); - - if (validation.parseIPv4(m[1])) { - if (m[3] != null && !validation.parseIPv4(m[3])) - return _('Expecting: %s').format(_('valid IPv4 address')); - } - else if (validation.parseIPv6(m[1])) { - if (m[3] != null && !validation.parseIPv6(m[3])) - return _('Expecting: %s').format(_('valid IPv6 address')); - } - else { - return _('Expecting: %s').format(_('valid IP address')); - } - - if ((m[2] != null && +m[2] > 65535) || (m[4] != null && +m[4] > 65535)) - return _('Expecting: %s').format(_('valid port value')); - - return true; -} - function expandAndFormatMAC(macs) { let result = []; @@ -296,52 +237,9 @@ return view.extend({ m, s, o, ss, so; let noi18nstrings = { - etc_hosts: '/etc/hosts', etc_ethers: '/etc/ethers', - localhost_v6: '::1', - loopback_slash_8_v4: '127.0.0.0/8', - not_found: 'Not found', - nxdomain: 'NXDOMAIN', - rfc_1918_link: 'RFC1918', - rfc_4193_link: 'RFC4193', - rfc_4291_link: 'RFC4291', - rfc_6303_link: 'RFC6303', - reverse_arpa: '*.IN-ADDR.ARPA,*.IP6.ARPA', - servers_file_entry01: 'server=1.2.3.4', - servers_file_entry02: 'server=/domain/1.2.3.4', - }; - const recordtypes = [ - 'ANY', - 'A', - 'AAAA', - 'ALIAS', - 'CAA', - 'CERT', - 'CNAME', - 'DS', - 'HINFO', - 'HIP', - 'HTTPS', - 'KEY', - 'LOC', - 'MX', - 'NAPTR', - 'NS', - 'OPENPGPKEY', - 'PTR', - 'RP', - 'SIG', - 'SOA', - 'SRV', - 'SSHFP', - 'SVCB', - 'TLSA', - 'TXT', - 'URI', - ] - function customi18n(template, values) { if (!values) values = noi18nstrings; diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dns.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dns.js index e10766f72a..006380a78f 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dns.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/dns.js @@ -10,8 +10,7 @@ 'require tools.widgets as widgets'; 'require tools.dnsrecordhandlers as drh'; -var callHostHints, callDUIDHints, callDHCPLeases, CBILeaseStatus, CBILease6Status; -var callUfpList; +var callHostHints; callHostHints = rpc.declare({ object: 'luci-rpc', @@ -19,130 +18,6 @@ callHostHints = rpc.declare({ expect: { '': {} } }); -callDUIDHints = rpc.declare({ - object: 'luci-rpc', - method: 'getDUIDHints', - expect: { '': {} } -}); - -callDHCPLeases = rpc.declare({ - object: 'luci-rpc', - method: 'getDHCPLeases', - expect: { '': {} } -}); - -callUfpList = rpc.declare({ - object: 'fingerprint', - method: 'fingerprint', - expect: { '': {} } -}); - -CBILeaseStatus = form.DummyValue.extend({ - renderWidget: function(section_id, option_id, cfgvalue) { - return E([ - E('h4', _('Active DHCP Leases')), - E('table', { 'id': 'lease_status_table', 'class': 'table' }, [ - E('tr', { 'class': 'tr table-titles' }, [ - E('th', { 'class': 'th' }, _('Hostname')), - E('th', { 'class': 'th' }, _('IPv4 address')), - E('th', { 'class': 'th' }, _('MAC address')), - E('th', { 'class': 'th' }, _('Lease time remaining')) - ]), - E('tr', { 'class': 'tr placeholder' }, [ - E('td', { 'class': 'td' }, E('em', _('Collecting data...'))) - ]) - ]) - ]); - } -}); - -CBILease6Status = form.DummyValue.extend({ - renderWidget: function(section_id, option_id, cfgvalue) { - return E([ - E('h4', _('Active DHCPv6 Leases')), - E('table', { 'id': 'lease6_status_table', 'class': 'table' }, [ - E('tr', { 'class': 'tr table-titles' }, [ - E('th', { 'class': 'th' }, _('Hostname')), - E('th', { 'class': 'th' }, _('IPv6 address')), - E('th', { 'class': 'th' }, _('DUID')), - E('th', { 'class': 'th' }, _('IAID')), - E('th', { 'class': 'th' }, _('Lease time remaining')) - ]), - E('tr', { 'class': 'tr placeholder' }, [ - E('td', { 'class': 'td' }, E('em', _('Collecting data...'))) - ]) - ]) - ]); - } -}); - -function calculateNetwork(addr, mask) { - addr = validation.parseIPv4(String(addr)); - - if (!isNaN(mask)) - mask = validation.parseIPv4(network.prefixToMask(+mask)); - else - mask = validation.parseIPv4(String(mask)); - - if (addr == null || mask == null) - return null; - - return [ - [ - addr[0] & (mask[0] >>> 0 & 255), - addr[1] & (mask[1] >>> 0 & 255), - addr[2] & (mask[2] >>> 0 & 255), - addr[3] & (mask[3] >>> 0 & 255) - ].join('.'), - mask.join('.') - ]; -} - -function generateDnsmasqInstanceEntry(data) { - const nameValueMap = new Map(Object.entries(data)); - let formatString = nameValueMap.get('.index') + ' (' + _('Name') + (nameValueMap.get('.anonymous') ? ': dnsmasq[' + nameValueMap.get('.index') + ']': ': ' + nameValueMap.get('.name')); - - if (data.domain) { - formatString += ', ' + _('Domain') + ': ' + data.domain; - } - if (data.local) { - formatString += ', ' + _('Local') + ': ' + data.local; - } - formatString += ')'; - - return [nameValueMap.get('.name'), formatString]; -} - -function getDHCPPools() { - return uci.load('dhcp').then(function() { - let sections = uci.sections('dhcp', 'dhcp'), - tasks = [], pools = []; - - for (var i = 0; i < sections.length; i++) { - if (sections[i].ignore == '1' || !sections[i].interface) - continue; - - tasks.push(network.getNetwork(sections[i].interface).then(L.bind(function(section_id, net) { - var cidr = net ? (net.getIPAddrs()[0] || '').split('/') : null; - - if (cidr && cidr.length == 2) { - var net_mask = calculateNetwork(cidr[0], cidr[1]); - - pools.push({ - section_id: section_id, - network: net_mask[0], - netmask: net_mask[1] - }); - } - }, null, sections[i]['.name']))); - } - - return Promise.all(tasks).then(function() { - return pools; - }); - }); -} - function validateHostname(sid, s) { if (s == null || s == '') return true; @@ -218,87 +93,19 @@ function validateServerSpec(sid, s) { return true; } -function expandAndFormatMAC(macs) { - let result = []; - - macs.forEach(mac => { - if (isValidMAC(mac)) { - const expandedMac = mac.split(':').map(part => { - return (part.length === 1 && part !== '*') ? '0' + part : part; - }).join(':').toUpperCase(); - result.push(expandedMac); - } - }); - - return result.length ? result : null; -} - -function isValidMAC(sid, s) { - if (!s) - return true; - - let macaddrs = L.toArray(s); - - for (var i = 0; i < macaddrs.length; i++) - if (!macaddrs[i].match(/^(([0-9a-f]{1,2}|\*)[:-]){5}([0-9a-f]{1,2}|\*)$/i)) - return _('Expecting a valid MAC address, optionally including wildcards') + _('; invalid MAC: ') + macaddrs[i]; - - return true; -} - -function validateMACAddr(pools, sid, s) { - if (s == null || s == '') - return true; - - var leases = uci.sections('dhcp', 'host'), - this_macs = L.toArray(s).map(function(m) { return m.toUpperCase() }); - - for (var i = 0; i < pools.length; i++) { - var this_net_mask = calculateNetwork(this.section.formvalue(sid, 'ip'), pools[i].netmask); - - if (!this_net_mask) - continue; - - for (var j = 0; j < leases.length; j++) { - if (leases[j]['.name'] == sid || !leases[j].ip) - continue; - - var lease_net_mask = calculateNetwork(leases[j].ip, pools[i].netmask); - - if (!lease_net_mask || this_net_mask[0] != lease_net_mask[0]) - continue; - - var lease_macs = L.toArray(leases[j].mac).map(function(m) { return m.toUpperCase() }); - - for (var k = 0; k < lease_macs.length; k++) - for (var l = 0; l < this_macs.length; l++) - if (lease_macs[k] == this_macs[l]) - return _('The MAC address %h is already used by another static lease in the same DHCP pool').format(this_macs[l]); - } - } - - return isValidMAC(sid, s); -} - return view.extend({ load: function() { return Promise.all([ callHostHints(), - callDUIDHints(), - getDHCPPools(), - network.getNetworks(), - L.hasSystemFeature('ufpd') ? callUfpList() : null, uci.load('firewall') ]); }, - render: function([hosts, duids, pools, networks, macdata]) { - var has_dhcpv6 = L.hasSystemFeature('dnsmasq', 'dhcpv6') || L.hasSystemFeature('odhcpd'), - m, s, o, ss, so, dnss; + render: function([hosts]) { + var m, s, o, ss, so, dnss; let noi18nstrings = { etc_hosts: '/etc/hosts', - etc_ethers: '/etc/ethers', localhost_v6: '::1', loopback_slash_8_v4: '127.0.0.0/8', not_found: 'Not found', -- 2.30.2