Check for network bridge configuration before attaching daynaport (#428)

This commit is contained in:
Daniel Markstedt 2021-11-08 18:34:49 -08:00 committed by GitHub
parent 988a2ffe1a
commit 59e9d8584c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -81,3 +81,19 @@ def disk_space():
from shutil import disk_usage
total, used, free = disk_usage(__file__)
return {"total": total, "used": used, "free": free}
def introspect_file(file_path, re_term):
"""
Takes a (str) file_path and (str) re_term in regex format
Will introspect file_path for the existance of re_term
and return True if found, False if not found
"""
from re import match
try:
ifile = open(file_path, "r")
except:
return False
for line in ifile:
if match(re_term, line):
return True
return False

View File

@ -39,6 +39,7 @@ from pi_cmds import (
running_netatalk,
is_bridge_setup,
disk_space,
introspect_file,
)
from ractl_cmds import (
attach_image,
@ -366,6 +367,24 @@ def daynaport_attach():
ip_addr = request.form.get("ip")
mask = request.form.get("mask")
error_msg = ("Please follow the instructions at "
"https://github.com/akuker/RASCSI/wiki/Dayna-Port-SCSI-Link")
if interface.startswith("wlan"):
if not introspect_file("/etc/sysctl.conf", "^net\.ipv4\.ip_forward=1$"):
flash("IPv4 forwarding is not enabled. " + error_msg, "error")
return redirect(url_for("index"))
if not Path("/etc/iptables/rules.v4").is_file():
flash("NAT has not been configured. " + error_msg, "error")
return redirect(url_for("index"))
else:
if not introspect_file("/etc/dhcpcd.conf", "^denyinterfaces " + interface + "$"):
flash("The network bridge hasn't been configured. " + error_msg, "error")
return redirect(url_for("index"))
if not Path("/etc/network/interfaces.d/rascsi_bridge").is_file():
flash(f"The network bridge hasn't been configured. " + error_msg, "error")
return redirect(url_for("index"))
kwargs = {"device_type": "SCDP"}
if interface != "":
arg = interface