Skip to content

Commit

Permalink
Check that wpa_supplicant.conf exists before accessing it
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanSara authored Jun 1, 2022
1 parent 66693f7 commit 85b0b31
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions zanzocam/web_ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ def read_network_data():
ssid = ""
password = ""

with open("/etc/wpa_supplicant/wpa_supplicant.conf", 'r') as conf:
for line in conf.readlines():
if ssid == "":
match = re.findall(r'ssid="(.*)"', line)
if match:
ssid = match[0]
if password == "":
match = re.findall(r'psk="(.*)"', line)
if match:
password = match[0]

return {"type": "WiFi", "ssid": ssid, "password":password}
if os.path.isfile("/etc/wpa_supplicant/wpa_supplicant.conf"):
with open("/etc/wpa_supplicant/wpa_supplicant.conf", 'r') as conf:
for line in conf.readlines():
if ssid == "":
match = re.findall(r'ssid="(.*)"', line)
if match:
ssid = match[0]
if password == "":
match = re.findall(r'psk="(.*)"', line)
if match:
password = match[0]

return {"type": "WiFi", "ssid": ssid, "password": password}


def _read_data_file(path: Path, default: str, action: Callable, catch_errors: bool=True):
Expand Down

0 comments on commit 85b0b31

Please sign in to comment.