Skip to content

Commit

Permalink
Support for firmware version V2.70 (not backwards-compatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbulica99 committed Jun 10, 2022
1 parent 003fa57 commit d721e58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 14 additions & 29 deletions poe-manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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')
Expand Down Expand Up @@ -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 = {
Expand All @@ -91,19 +85,15 @@ 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.
password = ""
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:
Expand All @@ -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.')
Expand All @@ -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())

0 comments on commit d721e58

Please sign in to comment.