Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added capture/disable_guest_wifi
Empty file.
45 changes: 45 additions & 0 deletions capture/enable_guest_wifi.request
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
POST /soap/server_sa/ HTTP/1.0
SOAPAction: urn:NETGEAR-ROUTER:service:WLANConfiguration:1#SetGuestAccessEnabled2
content-type: text/xml;charset=utf-8
HOST: www.routerlogin.com
User-Agent: SOAP Toolkit 3.0
connection: keep-Alive
Cache-Control: no-cache
Pragma: no-cache
Cookie: sess_id=595c7d4dbd5cd58a94352588a87c6c3295464a3e7ac5262592e08799820c3e01830a65a0e60a540d47582e1850a861e25b003af85315d2ab8a0104ee2cdab661; SameSite=Strict
content-length: 752

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header><SessionID>session_ID</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<M1:SetGuestAccessEnabled2 xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>1</NewGuestAccessEnabled>
<NewKey1>GUEST_SSID_key</NewKey1>
<NewKey2>0</NewKey2>
<NewKey3>0</NewKey3>
<NewKey4>0</NewKey4>
<NewSSID>GUEST_SSID</NewSSID>
<NewSecurityMode>WPA2-PSK</NewSecurityMode>
</M1:SetGuestAccessEnabled2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 200 OK
CONTENT-LENGTH:460
CONTENT-TYPE: text/xml; charset="UTF-8"
SERVER: "OS/version" UPnP/1.0 "product/version"

<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
soap-env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>
<soap-env:Body>
<m:SetGuestAccessEnabled2Response
xmlns:m="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
</m:SetGuestAccessEnabled2Response>
<ResponseCode>000</ResponseCode>
</soap-env:Body>
</soap-env:Envelope>
103 changes: 103 additions & 0 deletions pynetgear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,67 @@ def tofloats(lst): return (float(t) for t in lst)
trafficdict = {t.tag: parse_text(t.text) for t in data}
return trafficdict

def set_guest_wifi_enable(self,SSID,SSID_KEY):
"""
Turn on Guest WIFI

Returns None if error occurred.
"""
_LOGGER.info("Enable Guest Wifi")

def parse_response(response):
try:
result = re.search(REGEX_ENABLE_GUEST_WIFI, response).group(1)
except (AttributeError):
_LOGGER.error("Error parsing respone: %s", response)
return False, None
else:
return True, result
# Right now key should be 16 characters are less, key is broken down into key1,key2..key4
# So the assumption is you have breack it down into 16 byte chunks
success, response = self._make_request(
ACTION_ENABLE_GUEST_WIFI,
SOAP_ENABLE_GUEST_WIFI.format(session_id=SESSION_ID,ssid=SSID,ssid_key=SSID_KEY))

if not success:
return None

parsable, raw = parse_response(response)

if not parsable:
return None
return success, response

def set_guest_wifi_disable(self):
"""
Turn off Guest WIFI

Returns None if error occurred.
"""
_LOGGER.info("Disable Guest Wifi")

def parse_response(response):
try:
result = re.search(REGEX_ENABLE_GUEST_WIFI, response).group(1)
except (AttributeError):
_LOGGER.error("Error parsing respone: %s", response)
return False, None
else:
return True, result

success, response = self._make_request(
ACTION_DISABLE_GUEST_WIFI,
SOAP_DISABLE_GUEST_WIFI.format(session_id=SESSION_ID))

if not success:
return None

parsable, raw = parse_response(response)

if not parsable:
return None
return success, response

def _make_request(self, action, message, try_login_after_failure=True):
"""Make an API request to the router."""
# If we are not logged in, the request will fail for sure.
Expand Down Expand Up @@ -217,9 +278,15 @@ def convert(value, to_type, default=None):
"urn:NETGEAR-ROUTER:service:DeviceInfo:1#GetAttachDevice"
ACTION_GET_TRAFFIC_METER = \
"urn:NETGEAR-ROUTER:service:DeviceConfig:1#GetTrafficMeterStatistics"
ACTION_ENABLE_GUEST_WIFI = \
"SOAPAction: urn:NETGEAR-ROUTER:service:WLANConfiguration:1#SetGuestAccessEnabled2"
ACTION_DISABLE_GUEST_WIFI = \
"urn:NETGEAR-ROUTER:service:WLANConfiguration:1#SetGuestAccessEnabled"

REGEX_ATTACHED_DEVICES = r"<NewAttachDevice>(.*)</NewAttachDevice>"

REGEX_ENABLE_GUEST_WIFI =r".*(WLANConfiguration:1).*"

# Until we know how to generate it, give the one we captured
SESSION_ID = "A7D88AE69687E58D9A00"

Expand Down Expand Up @@ -268,5 +335,41 @@ def convert(value, to_type, default=None):
</SOAP-ENV:Envelope>
"""

SOAP_ENABLE_GUEST_WIFI = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID> <SOAP-ENV:Header><SessionID>{session_id}</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<M1:SetGuestAccessEnabled2 xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1">
<NewGuestAccessEnabled>1</NewGuestAccessEnabled>
<NewKey1>{ssid_key}</NewKey1>
<NewKey2>0</NewKey2>
<NewKey3>0</NewKey3>
<NewKey4>0</NewKey4>
<NewSSID>{ssid}</NewSSID>
<NewSecurityMode>WPA2-PSK</NewSecurityMode>
</M1:SetGuestAccessEnabled2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
"""

SOAP_DISABLE_GUEST_WIFI = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header><SessionID>{session_id}</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<M1:SetGuestAccessEnabled xmlns:M1="urn:NETGEAR-ROUTER:service:WLANConfiguration:1"><NewGuestAccessEnabled>0</NewGuestAccessEnabled>
</M1:SetGuestAccessEnabled>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
"""


UNKNOWN_DEVICE_DECODED = '<unknown>'
UNKNOWN_DEVICE_ENCODED = '&lt;unknown&gt;'