diff --git a/README.md b/README.md index 670e445..faa3c10 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,12 @@ The only requirements are `requests` and `BeautifulSoup4` (for HTML parsing). Yo ```bash python3 -m pip install -r requirements.txt ``` -Furthermore the script was tested on the firmware versions `V2.40(AAZI.1)_20180705` and `V2.60(AAZI.2)_20200922` of my `GS1900-10HP` model rev `A1`. +This script is compatible with the latest firmware version `V2.70(AAZI.1)_20220111` of my `GS1900-10HP` model rev `A1`. There are absolutely no guarantees that it will work with your system. -**There is a separate release of this script for each firmware!** +**There is a separate release of this script for each firmware!** +For the previous versions `V2.40(AAZI.1)_20180705` and `V2.60(AAZI.2)_20200922` please use the older release +accordingly. ## Usage diff --git a/poe-manager.py b/poe-manager.py index ffbac66..6a4e0bf 100755 --- a/poe-manager.py +++ b/poe-manager.py @@ -4,7 +4,7 @@ import argparse import requests from random import random -from time import sleep, time +from time import sleep from bs4 import BeautifulSoup @@ -15,29 +15,23 @@ def main(args): s.verify = False login_data = { - "login": 1, "username": args.user, "password": encode(args.pwd), - "dummy": current_time() + "login": 'true', } + # print("Logging in...") + login_step1 = s.post(url, data=login_data) login_check_data = { - "login_chk": 1, - "dummy": current_time() + "authId": login_step1.text.strip(), + "login_chk": 'true', } - - # print("Logging in...") - s.get(url, params=login_data) # implicitly wait for login to occur sleep(1) - ret2 = s.get(url, params=login_check_data) - if 'OK' not in ret2.text: - raise Exception("Login failed: %s" % ret2.text) + login_step2 = s.post(url, data=login_check_data) + if 'OK' not in login_step2.text: + raise Exception("Login failed: %s" % login_step2.text) # print("Login successful, parsing cookie.") - cookie = parse_cookie(s.get(url, params={"cmd": 1})) - # print("Got COOKIE: %s" % cookie) - s.cookies.set("XSSID", cookie) - ret = s.get(url, params={"cmd": 773}) if ret.ok: soup = BeautifulSoup(ret.content, 'html.parser') @@ -69,7 +63,7 @@ def main(args): output = ret print(output) else: - xssid_content = soup.find('input', {'id': 'XSSID'}).get('value') + xssid_content = soup.find('input', {'name': 'XSSID'}).get('value') print("Executing command: Turn %s PoE Port %s." % ('on' if args.state else 'off', args.port)) command_data = { @@ -91,10 +85,6 @@ def main(args): raise Exception("Failed to execute command: %s" % ret.text) -def current_time(): - return int(time() * 1000.0) - - def encode(_input): # The python representation of the JS function with the same name. # This could be improved further, but I can't be bothered. @@ -102,8 +92,8 @@ def encode(_input): possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" _len = lenn = len(_input) i = 1 - while i <= (320 - _len): - if 0 == i % 7 and _len > 0: + while i <= (321 - _len): + if 0 == i % 5 and _len > 0: _len -= 1 password += _input[_len] elif i == 123: @@ -119,12 +109,6 @@ def encode(_input): return password -def parse_cookie(cmd_1): - for line in cmd_1.text.split("\n"): - if 'XSSID' in line: - return line.replace('setCookie("XSSID", "', '').replace('");', '').strip() - - if __name__ == "__main__": parser = argparse.ArgumentParser( description='Manage the PoE ports of a Zyxel GS1900-10HP switch.') @@ -138,7 +122,8 @@ def parse_cookie(cmd_1): help='The port number. When querying information, 0 means all ports.') parser.add_argument('--state', '-s', dest='state', type=int, choices=[0, 1], - help='Turn the port on (1) or off (0). To query the state, rather than set it, omit this parameter.') + help='Turn the port on (1) or off (0). To query the state, ' + 'rather than set it, omit this parameter.') parser.add_argument('--verbose', '-V', dest='verbose', action="store_true", help='Return detailed information when querying the specified port state.') main(parser.parse_args())