Skip to content

Commit d721e58

Browse files
committed
Support for firmware version V2.70 (not backwards-compatible)
1 parent 003fa57 commit d721e58

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ The only requirements are `requests` and `BeautifulSoup4` (for HTML parsing). Yo
1515
```bash
1616
python3 -m pip install -r requirements.txt
1717
```
18-
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`.
18+
This script is compatible with the latest firmware version `V2.70(AAZI.1)_20220111` of my `GS1900-10HP` model rev `A1`.
1919
There are absolutely no guarantees that it will work with your system.
2020

21-
**There is a separate release of this script for each firmware!**
21+
**There is a separate release of this script for each firmware!**
22+
For the previous versions `V2.40(AAZI.1)_20180705` and `V2.60(AAZI.2)_20200922` please use the older release
23+
accordingly.
2224

2325

2426
## Usage

poe-manager.py

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import argparse
55
import requests
66
from random import random
7-
from time import sleep, time
7+
from time import sleep
88
from bs4 import BeautifulSoup
99

1010

@@ -15,29 +15,23 @@ def main(args):
1515
s.verify = False
1616

1717
login_data = {
18-
"login": 1,
1918
"username": args.user,
2019
"password": encode(args.pwd),
21-
"dummy": current_time()
20+
"login": 'true',
2221
}
22+
# print("Logging in...")
23+
login_step1 = s.post(url, data=login_data)
2324
login_check_data = {
24-
"login_chk": 1,
25-
"dummy": current_time()
25+
"authId": login_step1.text.strip(),
26+
"login_chk": 'true',
2627
}
27-
28-
# print("Logging in...")
29-
s.get(url, params=login_data)
3028
# implicitly wait for login to occur
3129
sleep(1)
32-
ret2 = s.get(url, params=login_check_data)
33-
if 'OK' not in ret2.text:
34-
raise Exception("Login failed: %s" % ret2.text)
30+
login_step2 = s.post(url, data=login_check_data)
31+
if 'OK' not in login_step2.text:
32+
raise Exception("Login failed: %s" % login_step2.text)
3533

3634
# print("Login successful, parsing cookie.")
37-
cookie = parse_cookie(s.get(url, params={"cmd": 1}))
38-
# print("Got COOKIE: %s" % cookie)
39-
s.cookies.set("XSSID", cookie)
40-
4135
ret = s.get(url, params={"cmd": 773})
4236
if ret.ok:
4337
soup = BeautifulSoup(ret.content, 'html.parser')
@@ -69,7 +63,7 @@ def main(args):
6963
output = ret
7064
print(output)
7165
else:
72-
xssid_content = soup.find('input', {'id': 'XSSID'}).get('value')
66+
xssid_content = soup.find('input', {'name': 'XSSID'}).get('value')
7367
print("Executing command: Turn %s PoE Port %s." %
7468
('on' if args.state else 'off', args.port))
7569
command_data = {
@@ -91,19 +85,15 @@ def main(args):
9185
raise Exception("Failed to execute command: %s" % ret.text)
9286

9387

94-
def current_time():
95-
return int(time() * 1000.0)
96-
97-
9888
def encode(_input):
9989
# The python representation of the JS function with the same name.
10090
# This could be improved further, but I can't be bothered.
10191
password = ""
10292
possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
10393
_len = lenn = len(_input)
10494
i = 1
105-
while i <= (320 - _len):
106-
if 0 == i % 7 and _len > 0:
95+
while i <= (321 - _len):
96+
if 0 == i % 5 and _len > 0:
10797
_len -= 1
10898
password += _input[_len]
10999
elif i == 123:
@@ -119,12 +109,6 @@ def encode(_input):
119109
return password
120110

121111

122-
def parse_cookie(cmd_1):
123-
for line in cmd_1.text.split("\n"):
124-
if 'XSSID' in line:
125-
return line.replace('setCookie("XSSID", "', '').replace('");', '').strip()
126-
127-
128112
if __name__ == "__main__":
129113
parser = argparse.ArgumentParser(
130114
description='Manage the PoE ports of a Zyxel GS1900-10HP switch.')
@@ -138,7 +122,8 @@ def parse_cookie(cmd_1):
138122
help='The port number. When querying information, 0 means all ports.')
139123
parser.add_argument('--state', '-s', dest='state', type=int,
140124
choices=[0, 1],
141-
help='Turn the port on (1) or off (0). To query the state, rather than set it, omit this parameter.')
125+
help='Turn the port on (1) or off (0). To query the state, '
126+
'rather than set it, omit this parameter.')
142127
parser.add_argument('--verbose', '-V', dest='verbose', action="store_true",
143128
help='Return detailed information when querying the specified port state.')
144129
main(parser.parse_args())

0 commit comments

Comments
 (0)