MycroftOS: Finish refactoring wifi setup system.

This commit is contained in:
j1nx 2020-06-09 15:36:30 +02:00
parent 00482f6eed
commit 0b22ac3f40
13 changed files with 18 additions and 76 deletions

View File

@ -1,13 +0,0 @@
*nat
:PREROUTING ACCEPT [14:1672]
:INPUT ACCEPT [13:1640]
:OUTPUT ACCEPT [24:1440]
:POSTROUTING ACCEPT [24:1440]
-A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.127.1
-A PREROUTING -p tcp -m tcp --dport 443 -j DNAT --to-destination 172.16.127.1
COMMIT
*filter
:INPUT ACCEPT [60540:12954317]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [56210:7390098]
COMMIT

View File

@ -12,7 +12,7 @@ http {
keepalive_timeout 65;
server {
listen 80;
listen 172.16.127.1:80;
server_name MycroftOS;
root /opt/mycroft/wifisetup/templates;

View File

@ -41,8 +41,6 @@ def save_credentials():
@app.route('/skip_wifi')
def skip_wifi():
empty_wpa_supplicant()
# Call reconfigure_device() in a thread otherwise the reconfigure will prevent
# the response from getting to the browser
def sleep_and_reconfigure():
@ -89,25 +87,12 @@ def create_wpa_supplicant(ssid, wifi_key):
os.system('mv wpa_supplicant-wlan0.conf.tmp /etc/wpa_supplicant/wpa_supplicant-wlan0.conf')
def empty_wpa_supplicant():
temp_conf_file = open('wpa_supplicant-wlan0.conf.tmp', 'w')
temp_conf_file.write('ctrl_interface=DIR=/var/run/wpa_supplicant\n')
temp_conf_file.write('update_config=1\n')
temp_conf_file.write('\n')
temp_conf_file.write('network={\n')
temp_conf_file.write('}\n')
temp_conf_file.close
os.system('mv wpa_supplicant-wlan0.conf.tmp /etc/wpa_supplicant/wpa_supplicant-wlan0.conf')
def reconfigure_device():
os.system('systemctl disable wpa_supplicant@ap0.service')
os.system('systemctl enable wpa_supplicant@wlan0.service')
os.system('systemctl stop wpa_supplicant@ap0.service')
os.system('sleep 5')
os.system('systemctl start wpa_supplicant@wlan0.service')
if __name__ == '__main__':
app.run(host = '0.0.0.0', port = '88')
app.run(host = '172.16.127.1', port = '88')

View File

@ -2,7 +2,7 @@
{% block body %}
<div id="saveCredentialsOutput">
<p>Wifi connection skipped for now</p>
<p>Your device will now reboot without wifi.</p>
<p>Wifi connection cancelled</p>
<p>You can close this window now and reconnect again to your normal wifi network.</p>
</div>
{% endblock %}

View File

@ -7,8 +7,8 @@
<VersionHigh>2.0</VersionHigh>
<VersionLow>1.0</VersionLow>
<AccessProcedure>1.0</AccessProcedure>
<AccessLocation>MycroftOS-WiFiSetup Configuration</AccessLocation>
<LocationName>MycroftOS-WiFiSetup</LocationName>
<AccessLocation>MYCROFT</AccessLocation>
<LocationName>MYCROFT</LocationName>
<LoginURL>http://172.16.127.1:88/</LoginURL>
</Redirect>
</WISPAccessGatewayParam>

View File

@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='stylesheets/app.css') }}">
<title>MycroftOS-WiFiSetup</title>
<title>MYCROFT</title>
</head>
<body>
{% block body %}

View File

@ -4,6 +4,7 @@
<div id="saveCredentialsOutput">
<p>Wifi connection configured for:</p>
<span class="saveCredentialsSSID">{{ ssid }}</span>
<p>Your device will now reboot and should be connected to your access point soon.</p>
<p>Your device will now reconfigure and connect to your access point.</p>
<p>You can close this window now and reconnect again to your normal wifi network.</p>
</div>
{% endblock %}

View File

@ -5,10 +5,6 @@ After=sys-subsystem-net-devices-ap0.device
Before=network.target
Wants=network.target
# check existence of configuration file
ConditionPathExists= /etc/wpa_supplicant/wpa_supplicant-ap0.conf
ConditionPathExists=!/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
[Service]
ExecStart=/usr/sbin/dnsmasq -k --conf-file=/etc/dnsmasq.conf
ExecReload=/bin/kill -HUP $MAINPID

View File

@ -1,18 +0,0 @@
[Unit]
Description=Packet Filtering Framework
Before=network-pre.target
Wants=network-pre.target
# check existence of configuration file
ConditionPathExists= /etc/wpa_supplicant/wpa_supplicant-ap0.conf
ConditionPathExists=!/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
[Service]
Type=oneshot
ExecStart=/sbin/iptables-restore /etc/iptables.rules
ExecReload=/sbin/iptables-restore /etc/iptables.rules
ExecStop=/usr/lib/systemd/scripts/iptables-flush
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@ -1,16 +1,13 @@
[Unit]
Description=A high performance web server and a reverse proxy server
BindsTo=sys-subsystem-net-devices-ap0.device
After=sys-subsystem-net-devices-ap0.device syslog.target network.target
# check existence of configuration file
ConditionPathExists= /etc/wpa_supplicant/wpa_supplicant-ap0.conf
ConditionPathExists=!/etc/wpa_supplicant/wpa_supplicant-wlan0.conf
After=sys-subsystem-net-devices-ap0.device wpa_supplicant@ap0.service
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/bin/mkdir -p /var/log/nginx /var/tmp/nginx
ExecStartPre=/usr/bin/sleep 5
ExecStartPre=/usr/sbin/nginx -t -q -g 'pid /var/run/nginx.pid; daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'pid /var/run/nginx.pid; daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'pid /var/run/nginx.pid; daemon on; master_process on;' -s reload
@ -18,4 +15,4 @@ ExecStop=/usr/sbin/nginx -g 'pid /var/run/nginx.pid;' -s quit
PrivateDevices=yes
[Install]
WantedBy=multi-user.target
WantedBy=wpa_supplicant@ap0.service

View File

@ -17,18 +17,15 @@ define WIFI_AP_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 644 $(@D)/wpa_supplicant@ap0.service \
$(TARGET_DIR)/usr/lib/systemd/system/wpa_supplicant@ap0.service
$(INSTALL) -D -m 644 $(@D)/wifi-setup.service \
$(TARGET_DIR)/usr/lib/systemd/system/wifi-setup.service
$(INSTALL) -D -m 644 $(@D)/dnsmasq.service \
$(TARGET_DIR)/usr/lib/systemd/system/dnsmasq.service
$(INSTALL) -D -m 644 $(@D)/nginx.service \
$(TARGET_DIR)/usr/lib/systemd/system/nginx.service
$(INSTALL) -D -m 644 $(@D)/iptables.service \
$(TARGET_DIR)/usr/lib/systemd/system/iptables.service
endef
$(eval $(generic-package))

View File

@ -2,7 +2,6 @@
Description=MycroftOS WiFi Setup - webbased configurator
After=wpa_supplicant@ap0.service
Wants=wpa_supplicant@ap0.service
Conflicts=wpa_supplicant@wlan0.service
Before=network.target
Wants=network.target
@ -12,4 +11,4 @@ WorkingDirectory=/opt/mycroft/wifisetup
ExecStart=/usr/bin/python3 app.py > /dev/null 2>&1
[Install]
WantedBy=multi-user.target
WantedBy=wpa_supplicant@ap0.service

View File

@ -6,8 +6,6 @@ Conflicts=wpa_supplicant@wlan0.service
Before=network.target
Wants=network.target
# NetworkManager users will probably want the dbus version instead.
[Service]
Type=simple
ExecStartPre=/usr/sbin/iw dev wlan0 interface add ap0 type __ap