diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js index d41b6e6..e90f662 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js @@ -1,6 +1,5 @@ 'use strict'; 'require baseclass'; -'require network'; function validateUrl(url, protocols = ['http:', 'https:']) { try { @@ -14,43 +13,6 @@ function validateUrl(url, protocols = ['http:', 'https:']) { } } -function getNetworkInterfaces(o, section_id, excludeInterfaces = []) { - return network.getDevices().then(devices => { - o.keylist = []; - o.vallist = []; - - devices.forEach(device => { - if (device.dev && device.dev.name) { - const deviceName = device.dev.name; - if (!excludeInterfaces.includes(deviceName)) { - o.value(deviceName, deviceName); - } - } - }); - }).catch(error => { - console.error('Failed to get network devices:', error); - }); -} - -function getNetworkNetworks(o, section_id, excludeInterfaces = []) { - return network.getNetworks().then(networks => { - o.keylist = []; - o.vallist = []; - - networks.forEach(net => { - const name = net.getName(); - const ifname = net.getIfname(); - if (name && !excludeInterfaces.includes(name)) { - o.value(name, ifname ? `${name} (${ifname})` : name); - } - }); - }).catch(error => { - console.error('Failed to get networks:', error); - }); -} - return baseclass.extend({ - getNetworkInterfaces, - getNetworkNetworks, validateUrl }); \ No newline at end of file diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js index d8aa332..cca414a 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js @@ -3,6 +3,7 @@ 'require baseclass'; 'require view.podkop.constants as constants'; 'require view.podkop.networkUtils as networkUtils'; +'require tools.widgets as widgets'; function createAdditionalSection(mainSection, network) { let o = mainSection.tab('additional', _('Additional Settings')); @@ -114,13 +115,28 @@ function createAdditionalSection(mainSection, network) { return true; }; - o = mainSection.taboption('additional', form.MultiValue, 'iface', _('Source Network Interface'), _('Select the network interface from which the traffic will originate')); + o = mainSection.taboption('additional', widgets.DeviceSelect, 'iface', _('Source Network Interface'), _('Select the network interface from which the traffic will originate')); o.ucisection = 'main'; o.default = 'br-lan'; - o.load = function (section_id) { - return networkUtils.getNetworkInterfaces(this, section_id, ['wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan']).then(() => { - return this.super('load', section_id); - }); + o.noaliases = true; + o.nobridges = false; + o.noinactive = false; + o.multiple = true; + o.filter = function (section_id, value) { + if (['wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan'].indexOf(value) !== -1) { + return false; + } + + var device = this.devices.filter(function (dev) { + return dev.getName() === value; + })[0]; + + if (device) { + var type = device.getType(); + return type !== 'wifi' && type !== 'wireless' && !type.includes('wlan'); + } + + return true; }; o = mainSection.taboption('additional', form.Flag, 'mon_restart_ifaces', _('Interface monitoring'), _('Interface monitoring for bad WAN')); @@ -128,13 +144,12 @@ function createAdditionalSection(mainSection, network) { o.rmempty = false; o.ucisection = 'main'; - o = mainSection.taboption('additional', form.MultiValue, 'restart_ifaces', _('Interface for monitoring'), _('Select the WAN interfaces to be monitored')); + o = mainSection.taboption('additional', widgets.NetworkSelect, 'restart_ifaces', _('Interface for monitoring'), _('Select the WAN interfaces to be monitored')); o.ucisection = 'main'; o.depends('mon_restart_ifaces', '1'); - o.load = function (section_id) { - return networkUtils.getNetworkNetworks(this, section_id, ['lan', 'loopback']).then(() => { - return this.super('load', section_id); - }); + o.multiple = true; + o.filter = function (section_id, value) { + return ['lan', 'loopback'].indexOf(value) === -1 && !value.startsWith('@'); }; o = mainSection.taboption('additional', form.Flag, 'dont_touch_dhcp', _('Dont touch my DHCP!'), _('Podkop will not change the DHCP config')); diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js index c239f10..54ba6f1 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js @@ -5,6 +5,7 @@ 'require network'; 'require view.podkop.constants as constants'; 'require view.podkop.networkUtils as networkUtils'; +'require tools.widgets as widgets'; function createConfigSection(section, map, network) { const s = section; @@ -203,13 +204,27 @@ function createConfigSection(section, map, network) { o.rmempty = false; o.ucisection = 'main'; - o = s.taboption('basic', form.ListValue, 'interface', _('Network Interface'), _('Select network interface for VPN connection')); + o = s.taboption('basic', widgets.DeviceSelect, 'interface', _('Network Interface'), _('Select network interface for VPN connection')); o.depends('mode', 'vpn'); o.ucisection = s.section; - o.load = function (section_id) { - return networkUtils.getNetworkInterfaces(this, section_id, ['br-lan', 'eth0', 'eth1', 'wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan', 'lan']).then(() => { - return this.super('load', section_id); - }); + o.noaliases = true; + o.nobridges = false; + o.noinactive = false; + o.filter = function (section_id, value) { + if (['br-lan', 'eth0', 'eth1', 'wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan', 'lan'].indexOf(value) !== -1) { + return false; + } + + var device = this.devices.filter(function (dev) { + return dev.getName() === value; + })[0]; + + if (device) { + var type = device.getType(); + return type !== 'wifi' && type !== 'wireless' && !type.includes('wlan'); + } + + return true; }; o = s.taboption('basic', form.Flag, 'domain_list_enabled', _('Community Lists'));