From d55675b1e9343bbd6825fb3072f6cf53dd3363ea Mon Sep 17 00:00:00 2001 From: Jason Burgett Date: Thu, 24 Jan 2019 09:10:57 -0600 Subject: [PATCH] WPA crentials entry form now in place and working. --- libs/configuration_app/app.py | 18 +++++++++++------- .../templates/wpa_settings.html | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libs/configuration_app/app.py b/libs/configuration_app/app.py index fe48a4c3..271c0336 100644 --- a/libs/configuration_app/app.py +++ b/libs/configuration_app/app.py @@ -22,7 +22,7 @@ def manual_ssid_entry(): @app.route('/wpa_settings') def wpa_settings(): config_hash = config_file_hash() - return render_template('wpa_settings.html', wpa_key = config_hash['wpa_key']) + return render_template('wpa_settings.html', wpa_enabled = config_hash['wpa_enabled'], wpa_key = config_hash['wpa_key']) @app.route('/save_credentials', methods = ['GET', 'POST']) @@ -46,10 +46,17 @@ def sleep_and_start_ap(): @app.route('/save_wpa_credentials', methods = ['GET', 'POST']) def save_wpa_credentials(): config_hash = config_file_hash() + wpa_enabled = request.form.get('wpa_enabled') + wpa_key = request.form['wpa_key'] + + if str(wpa_enabled) == '1': + update_wpa(1, wpa_key) + else: + update_wpa(0, wpa_key) def sleep_and_reboot_for_wpa(): time.sleep(2) - update_wpa() + print("REBOOT") t = Thread(target=sleep_and_reboot_for_wpa) t.start() @@ -103,16 +110,13 @@ def set_ap_client_mode(): os.system('mv /etc/dhcpcd.conf.original /etc/dhcpcd.conf') os.system('reboot') -def update_wpa(): - wpa_enabled = '0' - wpa_key = 'password' - +def update_wpa(wpa_enabled, wpa_key): with fileinput.FileInput('/etc/raspiwifi/raspiwifi.conf', inplace=True) as raspiwifi_conf: for line in raspiwifi_conf: if 'wpa_enabled=' in line: line_array = line.split('=') line_array[1] = wpa_enabled - print(line_array[0] + '=' + line_array[1]) + print(line_array[0] + '=' + str(line_array[1])) if 'wpa_key=' in line: line_array = line.split('=') diff --git a/libs/configuration_app/templates/wpa_settings.html b/libs/configuration_app/templates/wpa_settings.html index 462f3d0d..428af9d5 100644 --- a/libs/configuration_app/templates/wpa_settings.html +++ b/libs/configuration_app/templates/wpa_settings.html @@ -7,6 +7,12 @@

Configure WPA Settings