Skip to content

Commit

Permalink
wificontrol: Add check and response to hostname/password setting
Browse files Browse the repository at this point in the history
* Add methods to verify hostname/password
* Add return statement to set_hostname/password methods
  • Loading branch information
dskorykh authored and egorf committed Dec 8, 2017
1 parent 5a4033c commit b24571d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 9 additions & 4 deletions wificontrol/hostapd.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ def start(self):
def stop(self):
self.execute_command(self.hostapd_control("stop"))

def get_hostap_name(self):
return self.re_search("(?<=^ssid=).*", self.hostapd_path)

def set_hostap_name(self, name='reach'):
mac_addr = self.get_device_mac()[-6:]
self.replace("^ssid=.*", "ssid={}{}".format(name, mac_addr), self.hostapd_path)

def get_hostap_name(self):
return self.re_search("(?<=^ssid=).*", self.hostapd_path)

def set_hostap_password(self, password):
self.replace("^wpa_passphrase=.*", "wpa_passphrase={}".format(password), self.hostapd_path)
self.replace("^wpa_passphrase=.*",
"wpa_passphrase={}".format(password), self.hostapd_path)
return self.verify_hostap_password(password)

def verify_hostap_password(self, value):
return self.re_search("(?<=^wpa_passphrase=).*", self.hostapd_path) == value

def set_host_name(self, name='reach'):
try:
Expand Down
15 changes: 14 additions & 1 deletion wificontrol/wificontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_wifi_turned_on(self):
return (self.wpasupplicant.started() or self.hotspot.started())

def set_hostap_password(self, password):
self.hotspot.set_hostap_password(password)
return self.hotspot.set_hostap_password(password)

def get_device_name(self):
return self.hotspot.get_host_name()
Expand All @@ -92,6 +92,19 @@ def set_device_names(self, name):
self.hotspot.set_hostap_name(name)
self.hotspot.set_host_name(name)
self.wifi.restart_dns()
return self.verify_device_names(name)

def verify_hostap_name(self, name):
mac_addr = self.hotspot.get_device_mac()[-6:]
return "{}{}".format(name, mac_addr) == self.hotspot.get_hostap_name()

def verify_device_names(self, name):
verified = False
if name == self.hotspot.get_host_name():
if name == self.wpasupplicant.get_p2p_name():
if self.verify_hostap_name(name):
verified = True
return verified

def get_status(self):
state = self.get_state()
Expand Down

0 comments on commit b24571d

Please sign in to comment.