refactor: change Source Network Interface filter logic

This commit is contained in:
divocat
2025-10-02 23:30:28 +03:00
parent 3988588c9f
commit b71c7b379d

View File

@@ -131,20 +131,29 @@ function createAdditionalSection(mainSection) {
o.noinactive = false; o.noinactive = false;
o.multiple = true; o.multiple = true;
o.filter = function (section_id, value) { o.filter = function (section_id, value) {
if (['wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan'].indexOf(value) !== -1) { // Block specific interface names from being selectable
const blocked = ['wan', 'phy0-ap0', 'phy1-ap0', 'pppoe-wan'];
if (blocked.includes(value)) {
return false; return false;
} }
var device = this.devices.filter(function (dev) { // Try to find the device object by its name
return dev.getName() === value; const device = this.devices.find(dev => dev.getName() === value);
})[0];
if (device) { // If no device is found, allow the value
var type = device.getType(); if (!device) {
return type !== 'wifi' && type !== 'wireless' && !type.includes('wlan'); return true;
} }
return true; // Check the type of the device
const type = device.getType();
// Consider any Wi-Fi / wireless / wlan device as invalid
const isWireless =
type === 'wifi' || type === 'wireless' || type.includes('wlan');
// Allow only non-wireless devices
return !isWireless;
}; };
o = mainSection.taboption('additional', form.Flag, 'mon_restart_ifaces', _('Interface monitoring'), _('Interface monitoring for bad WAN')); o = mainSection.taboption('additional', form.Flag, 'mon_restart_ifaces', _('Interface monitoring'), _('Interface monitoring for bad WAN'));