forked from balena-labs-research/python-wifi-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
84 lines (71 loc) · 2.33 KB
/
Copy pathconfig.py
File metadata and controls
84 lines (71 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
from dotenv import dotenv_values
# Set dev env variables
if (
"FLASK_ENV" in os.environ
and os.environ["FLASK_ENV"].lower() == "production"
):
dev_mode = False
else:
dev_mode = True
# Check db directory exists
if not os.path.exists("db"):
os.makedirs("db")
# Import database file
env_file = dotenv_values("db/.db")
# Set default Wi-Fi SSID.
if "PWC_HOTSPOT_SSID" in env_file:
hotspot_ssid = env_file["PWC_HOTSPOT_SSID"]
elif "PWC_HOTSPOT_SSID" in os.environ:
hotspot_ssid = os.environ["PWC_HOTSPOT_SSID"]
else:
hotspot_ssid = "Python Wi-Fi Connect"
if "$UNIQUE_ID" in hotspot_ssid:
with open("/proc/cpuinfo") as f:
for line in f:
if "Serial" in line:
serial = line.replace(" ", "").split(":")[1]
hotspot_ssid = hotspot_ssid.replace(
"$UNIQUE_ID", serial[-5:-1]
)
# Set default hotspot password.
if "PWC_HOTSPOT_PASSWORD" in env_file:
hotspot_password = env_file["PWC_HOTSPOT_PASSWORD"]
elif "PWC_HOTSPOT_PASSWORD" in os.environ:
hotspot_password = os.environ["PWC_HOTSPOT_PASSWORD"]
else:
hotspot_password = None
# Set default host.
if "PWC_HOST" in os.environ and os.environ["PWC_HOST"].lower() == "bridge":
host = os.environ["BRIDGE_NETWORK_IP"]
elif "PWC_HOST" in os.environ:
host = os.environ["PWC_HOST"]
else:
host = "0.0.0.0"
# Set default port.
if "PWC_PORT" in os.environ:
port = os.environ["PWC_PORT"]
else:
port = 9090
# Compile kwargs for automatic connection
if "PWC_AC_SSID" in os.environ:
auto_connect_kargs = {"ssid": os.environ["PWC_AC_SSID"]}
if "PWC_AC_USERNAME" in os.environ:
auto_connect_kargs.update(username=os.environ["PWC_AC_USERNAME"])
if "PWC_AC_PASSWORD" in os.environ:
auto_connect_kargs.update(password=os.environ["PWC_AC_PASSWORD"])
else:
auto_connect_kargs = False
# Default access point name. No need to change these under usual operation as
# they are for use inside the app only. PWC is acronym for 'Python Wi-Fi Connect'.
ap_name = "PWC"
# dnsmasq variables
DEFAULT_GATEWAY = "192.168.42.1"
DEFAULT_DHCP_RANGE = "192.168.42.2,192.168.42.254"
# Wi-Fi modes. No need to rename these, they are used only as labels.
type_hotspot = "HOTSPOT"
type_none = "NONE"
type_wep = "WEP"
type_wpa = "WPA"
type_wpa2 = "WPA2"
type_enterprise = "ENTERPRISE"