generated from libresource/pygenesis
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
798babb
commit dfdf882
Showing
11 changed files
with
399 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
TendaEverest package | ||
""" | ||
from .main import info | ||
from .main import login, get_info, MODULES, request_firmware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,160 @@ | ||
""" | ||
Main module | ||
""" | ||
from enum import Enum, verify, UNIQUE, auto | ||
|
||
DEFAULT_FIRMWARE = 'V02.03.01.125' | ||
|
||
def info(): | ||
def login(requests, host): | ||
""" | ||
Info | ||
""" | ||
return 'First steps with TendaEverest' | ||
session = requests.session() | ||
|
||
url = '/login/Auth' | ||
|
||
referer = f'{host}/login.html' | ||
|
||
headers = { | ||
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) ' | ||
'Gecko/20100101 Firefox/130.0', | ||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,' | ||
'image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8', | ||
'Accept-Language': 'en-US,en;q=0.5', | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Connection': 'keep-alive', | ||
'Referer': referer | ||
|
||
} | ||
|
||
data = { | ||
'password': "YWRtaW4=" # admin coded in base64 | ||
} | ||
|
||
request_url = f'{host}{url}' | ||
|
||
session.post( | ||
url=request_url, | ||
headers=headers, | ||
data=data | ||
) | ||
|
||
return session | ||
|
||
# pylint:disable=invalid-name | ||
@verify(UNIQUE) | ||
class MODULES(Enum): | ||
""" | ||
Available modules | ||
""" | ||
systemInfo = auto() | ||
wifiBasicCfg = auto() | ||
wanBasicCfg = auto() | ||
softWare = auto() | ||
wifiBeamforming = auto() | ||
onlineList = auto() | ||
hasNewSoftVersion = auto() | ||
portList = auto() | ||
sysTime = auto() | ||
wifiRelay = auto() | ||
parentAccessCtrl = auto() | ||
ipv6Status = auto() | ||
LEDControl = auto() | ||
ping = auto() | ||
wifiTime = auto() | ||
parentCtrlList = auto() | ||
macFilter = auto() | ||
internetStatus = auto() | ||
IPTV = auto() | ||
guestList = auto() | ||
lan6Cfg = auto() | ||
wan6BasicCfg = auto() | ||
ipv6Enable = auto() | ||
deviceStatistics = auto() | ||
lanCfg = auto() | ||
wanAdvCfg = auto() | ||
productInfo = auto() | ||
wpsModule = auto() | ||
upnp = auto() | ||
wifiAdvCfg = auto() | ||
staticIPList = auto() | ||
isWifiClients = auto() | ||
localhost = auto() | ||
wifiGuest = auto() | ||
wifiWPS = auto() | ||
remoteWeb = auto() | ||
dmz = auto() | ||
wifiPower = auto() | ||
loginAuth = auto() | ||
ddns = auto() | ||
|
||
|
||
def get_request_urls(firmware=DEFAULT_FIRMWARE, modules=None): | ||
""" | ||
get different urls for request | ||
""" | ||
if firmware == 'V12.01.01.33_multi': | ||
module_urls = { | ||
MODULES.systemInfo: 'getStatus', | ||
MODULES.wanBasicCfg: 'getWAN', | ||
MODULES.wifiBasicCfg: 'getWifi', | ||
MODULES.softWare: 'getSysTools', | ||
} | ||
result = [] | ||
if modules: | ||
for module in modules: | ||
if module in module_urls: | ||
result.append(module_urls[module]) | ||
else: | ||
result.append('getStatus') | ||
else: | ||
result.append('getStatus') | ||
return result | ||
|
||
return ['getStatus'] | ||
|
||
|
||
def get_info(host, session, modules=(MODULES.systemInfo,), firmware=DEFAULT_FIRMWARE): | ||
""" | ||
Get info using different modules | ||
""" | ||
available_modules = [module.name for module in modules] | ||
modules_str = ','.join(list(available_modules)) | ||
|
||
request_urls = get_request_urls(firmware, modules) | ||
|
||
result = {} | ||
for url_item in request_urls: | ||
|
||
url = f'/goform/{url_item}?modules={modules_str}' | ||
|
||
headers = { | ||
'User-Agent': | ||
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0', | ||
'Accept': '*/*', | ||
'Accept-Language': 'en-US,en;q=0.5', | ||
} | ||
|
||
request_url = f'{host}{url}' | ||
|
||
cookies = { | ||
'bLanguage': 'en', | ||
'ecos_pw': 'ecos_pw=YWRtaW4=wdv:language=cn' # admin in base64 | ||
} | ||
|
||
response = session.get( | ||
url=request_url, | ||
headers=headers, | ||
cookies=cookies, | ||
) | ||
|
||
result.update(response.json()) | ||
|
||
return result | ||
|
||
def request_firmware(host, session): | ||
""" | ||
Request router current firmware | ||
""" | ||
info = get_info(host, session, modules=(MODULES.systemInfo,)) | ||
return info['systemInfo']['softVersion'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
Package info | ||
""" | ||
name = 'tenda-everest' | ||
version = '0.1.0' | ||
version = '0.2.0' | ||
status = '3 - Alpha' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# import requests | ||
import testing.test_tenda_everest.mocks as mocks | ||
from pytest import fixture | ||
|
||
|
||
@fixture | ||
def requests_module(): | ||
# return requests | ||
return mocks | ||
|
||
@fixture | ||
def host(): | ||
return '9.9.9.9' | ||
# return 'http://10.173.1.142:8081' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from tenda_everest import MODULES | ||
from testing.test_tenda_everest.mocks.expected import expected_info | ||
|
||
class MockResponse: | ||
|
||
def __init__(self, url): | ||
self.modules = self.get_modules(url) | ||
|
||
def json(self): | ||
result = {} | ||
for module in self.modules: | ||
enum_module = MODULES[module] | ||
value = expected_info[enum_module] | ||
result.update(value) | ||
|
||
return result | ||
|
||
def get_modules(self, url): | ||
host, params = url.split('?') | ||
module, values = params.split('=') | ||
modules = values.split(',') | ||
return modules | ||
|
||
|
||
class MockSession: | ||
|
||
def get(self, url, *args, **kwargs): | ||
return MockResponse(url) | ||
|
||
def post(self, *args, **kwargs): | ||
pass | ||
|
||
def session(): | ||
return MockSession() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from tenda_everest import MODULES | ||
|
||
hidden_mac = 'XX:XX:XX:XX:XX:XX' | ||
hidden_dns = 'XX.XX.XXX.XXX' | ||
hidden_key = '********' | ||
hidden_user = 'user' | ||
hidden_ssid = 'SSID' | ||
|
||
expected_systemInfo = { | ||
'systemInfo': { | ||
'lanIP': '192.168.0.1', | ||
'lanMask': '255.255.255.0', | ||
'macHost': hidden_mac, | ||
'softVersion': 'V02.03.01.125', | ||
'statusWanDns1': hidden_dns, | ||
'statusWanDns2': '1.1.1.1', | ||
'statusWanGaterway': '10.173.255.1', | ||
'statusWanIP': '10.173.1.142', | ||
'statusWanMAC': hidden_mac, | ||
'statusWanMask': '255.255.255.254', | ||
'wanConnectTime': '66039', | ||
'wanType': 'pppoe' | ||
} | ||
} | ||
|
||
expected_wanBasicCfg = { | ||
'wanBasicCfg': { | ||
'wanDns1': hidden_dns, | ||
'wanDns2': '1.1.1.1', | ||
'wanGateway': '10.173.255.1', | ||
'wanIP': '10.173.1.142', | ||
'wanMask': '255.255.255.254', | ||
'wanPPPoEPwd': hidden_key, | ||
'wanPPPoEUser': hidden_user, | ||
'wanType': 'pppoe' | ||
} | ||
} | ||
|
||
expected_wifiBasicCfg = { | ||
'wifiBasicCfg': { | ||
'HasDoubleBandUnity': 'true', | ||
'doubleBandUnityEnable': 'false', | ||
'wifiEn': 'true', | ||
'wifiEn_5G': 'true', | ||
'wifiHideSSID': 'false', | ||
'wifiHideSSID_5G': 'false', | ||
'wifiNoPwd': 'false', | ||
'wifiNoPwd_5G': 'false', | ||
'wifiPwd': hidden_key, | ||
'wifiPwd_5G': hidden_key, | ||
'wifiSSID': hidden_ssid, | ||
'wifiSSID_5G': hidden_ssid, | ||
'wifiSecurityMode': 'WPAWPA2/AES', | ||
'wifiSecurityMode_5G': 'WPAWPA2/AES', | ||
'wifiTotalEn': 'true' | ||
} | ||
} | ||
|
||
expected_info = { | ||
MODULES.systemInfo: expected_systemInfo, | ||
MODULES.wanBasicCfg: expected_wanBasicCfg, | ||
MODULES.wifiBasicCfg: expected_wifiBasicCfg | ||
} |
Oops, something went wrong.