Skip to content

Commit

Permalink
WPA crentials entry form now in place and working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasbur committed Jan 24, 2019
1 parent b86fac7 commit d55675b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 11 additions & 7 deletions libs/configuration_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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()
Expand Down Expand Up @@ -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('=')
Expand Down
6 changes: 6 additions & 0 deletions libs/configuration_app/templates/wpa_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ <h1>Configure WPA Settings</h1>

<form action="{{ url_for('save_wpa_credentials') }}" method=post>
<ul>
{% if wpa_enabled == '1': %}
<li><input type="checkbox" name="wpa_enabled" value="1" checked> WPA On/Off</li>
{% else: %}
<li><input type="checkbox" name="wpa_enabled" value="1"> WPA On/Off</li>
{% endif %}

<li><label for="wpa_key">Current WPA Key</label></li>
<li><input type="text" name="wpa_key" value={{wpa_key}} class="wifiNetworkInputs"></li>

Expand Down

0 comments on commit d55675b

Please sign in to comment.