Improve the logic for checking the network bridge configuration (#894)

* Improve the logic for checking the network bridge configuration
This commit is contained in:
Daniel Markstedt 2022-10-05 14:14:48 -07:00 committed by GitHub
parent efbfb54d26
commit 52259c374f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -610,11 +610,10 @@ def attach_device():
error_msg = _("Please follow the instructions at %(url)s", url=error_url) error_msg = _("Please follow the instructions at %(url)s", url=error_url)
if "interface" in params.keys(): if "interface" in params.keys():
# Note: is_bridge_configured returns False if the bridge is configured
bridge_status = is_bridge_configured(params["interface"]) bridge_status = is_bridge_configured(params["interface"])
if bridge_status: if not bridge_status["status"]:
return response(error=True, message=[ return response(error=True, message=[
(bridge_status, "error"), (bridge_status["msg"], "error"),
(error_msg, "error") (error_msg, "error")
]) ])

View File

@ -192,24 +192,30 @@ def auth_active(group):
def is_bridge_configured(interface): def is_bridge_configured(interface):
""" """
Takes (str) interface of a network device being attached. Takes (str) interface of a network device being attached.
Returns (bool) False if the network bridge is configured. Returns a (dict) with (bool) status and (str) msg
Returns (str) with an error message if the network bridge is not configured.
""" """
status = True
return_msg = ""
sys_cmd = SysCmds() sys_cmd = SysCmds()
if interface.startswith("wlan"): if interface.startswith("wlan"):
if not sys_cmd.introspect_file("/etc/sysctl.conf", r"^net\.ipv4\.ip_forward=1$"): if not sys_cmd.introspect_file("/etc/sysctl.conf", r"^net\.ipv4\.ip_forward=1$"):
return _("Configure IPv4 forwarding before using a wireless network device.") status = False
if not Path("/etc/iptables/rules.v4").is_file(): return_msg = _("Configure IPv4 forwarding before using a wireless network device.")
return _("Configure NAT before using a wireless network device.") elif not Path("/etc/iptables/rules.v4").is_file():
status = False
return_msg = _("Configure NAT before using a wireless network device.")
else: else:
if not sys_cmd.introspect_file( if not sys_cmd.introspect_file(
"/etc/dhcpcd.conf", "/etc/dhcpcd.conf",
r"^denyinterfaces " + interface + r"$", r"^denyinterfaces " + interface + r"$",
): ):
return _("Configure the network bridge before using a wired network device.") status = False
if not Path("/etc/network/interfaces.d/rascsi_bridge").is_file(): return_msg = _("Configure the network bridge before using a wired network device.")
return _("Configure the network bridge before using a wired network device.") elif not Path("/etc/network/interfaces.d/rascsi_bridge").is_file():
return False status = False
return_msg = _("Configure the network bridge before using a wired network device.")
return {"status": status, "msg": return_msg + f" ({interface})"}
def upload_with_dropzonejs(image_dir): def upload_with_dropzonejs(image_dir):