Skip to content

Commit

Permalink
Moved WPA key update into the wpa_check_activate function and refoact…
Browse files Browse the repository at this point in the history
…ored
  • Loading branch information
jasbur committed Jan 24, 2019
1 parent 5c8cba3 commit edc212c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions libs/reset_device/reset_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ def config_file_hash():

return config_hash

def update_wpa_key(wpa_key):
with fileinput.FileInput('/etc/hostapd/hostapd.conf', inplace=True) as hostapd_conf:
for line in hostapd_conf:
if 'wpa_passphrase' in line:
print('wpa_passphrase=' + wpa_key)
else:
print(line, end = '')

def wpa_check_activate(wpa_enabled, wpa_key):
wpa_active = False
reboot_required = False
Expand All @@ -33,7 +25,18 @@ def wpa_check_activate(wpa_enabled, wpa_key):
if wpa_enabled == '1' and wpa_active == False:
reboot_required = True
os.system('cp /usr/lib/raspiwifi/reset_device/static_files/hostapd.conf.wpa /etc/hostapd/hostapd.conf')
update_wpa_key(wpa_key)

if wpa_enabled == '1':
with fileinput.FileInput('/etc/hostapd/hostapd.conf', inplace=True) as hostapd_conf:
for line in hostapd_conf:
if 'wpa_passphrase' in line:
if 'wpa_passphrase=' + wpa_key not in line:
print('wpa_passphrase=' + wpa_key)
os.system('reboot')
else:
print(line, end = '')
else:
print(line, end = '')

if wpa_enabled == '0' and wpa_active == True:
reboot_required = True
Expand Down

0 comments on commit edc212c

Please sign in to comment.