mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2026-04-28 09:53:06 -07:00
feat(fix_services): add interface name validation helper
Add _IFACE_RE regex and _validate_iface() classmethod that validates Linux network interface names (max 15 chars, alphanumeric plus dash and underscore). Provides a safety net against malformed names if interface configuration is ever externalized.
This commit is contained in:
@@ -25,6 +25,15 @@ class FixServices(plugins.Plugin):
|
||||
Automatically disables itself when an external WiFi adapter is detected instead of the onboard brcmfmac chip.
|
||||
"""
|
||||
|
||||
_IFACE_RE = re.compile(r'^[a-zA-Z0-9_-]{1,15}$')
|
||||
|
||||
@classmethod
|
||||
def _validate_iface(cls, name):
|
||||
"""Validate a Linux network interface name."""
|
||||
if not cls._IFACE_RE.match(name):
|
||||
raise ValueError('Invalid interface name: %r' % name)
|
||||
return name
|
||||
|
||||
def __init__(self):
|
||||
self.options = dict()
|
||||
self.pattern = re.compile(r'ieee80211 phy0: brcmf_cfg80211_add_iface: iface validation failed: err=-95')
|
||||
@@ -103,6 +112,7 @@ class FixServices(plugins.Plugin):
|
||||
if self.is_disabled:
|
||||
return
|
||||
try:
|
||||
self._validate_iface("wlan0mon")
|
||||
cmd_output = subprocess.check_output("ip link show wlan0mon", shell=True)
|
||||
logging.debug("[Fix_Services ip link show wlan0mon]: %s" % repr(cmd_output))
|
||||
if ",UP," in str(cmd_output):
|
||||
|
||||
Reference in New Issue
Block a user