login done, but don't detects servers
This commit is contained in:
parent
d00762ae9e
commit
671a71d5cd
4 changed files with 211 additions and 108 deletions
11
connect_test.py
Normal file
11
connect_test.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from python_aternos import Client as AternosClient
|
||||||
|
|
||||||
|
aternos = AternosClient('', password='')
|
||||||
|
|
||||||
|
srvs = aternos.servers
|
||||||
|
|
||||||
|
print(srvs)
|
||||||
|
|
||||||
|
s = srvs[0]
|
||||||
|
|
||||||
|
s.start()
|
|
@ -8,6 +8,19 @@ from typing import Optional, Union
|
||||||
|
|
||||||
from . import aterrors
|
from . import aterrors
|
||||||
|
|
||||||
|
#TEST
|
||||||
|
from py_mini_racer import MiniRacer
|
||||||
|
import base64
|
||||||
|
|
||||||
|
presettings = """
|
||||||
|
let window = {1: null, 2: null, AJAX_TOKEN: null};
|
||||||
|
let i = 1;
|
||||||
|
function __log() { return {win_var: window["AJAX_TOKEN"], 1: window[1], 2: window[2]} };
|
||||||
|
function atob(arg) {window[i++] = arg;};
|
||||||
|
"""
|
||||||
|
postsettings = """__log();"""
|
||||||
|
|
||||||
|
|
||||||
REQGET = 0
|
REQGET = 0
|
||||||
REQPOST = 1
|
REQPOST = 1
|
||||||
REQUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Goanna/4.8 Firefox/68.0 PaleMoon/29.4.0.2'
|
REQUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Goanna/4.8 Firefox/68.0 PaleMoon/29.4.0.2'
|
||||||
|
@ -29,11 +42,44 @@ class AternosConnect:
|
||||||
pagetree = lxml.html.fromstring(response)
|
pagetree = lxml.html.fromstring(response)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# fetch text
|
||||||
pagehead = pagetree.head
|
pagehead = pagetree.head
|
||||||
|
text = pagehead.text_content()
|
||||||
|
#print(text)
|
||||||
|
|
||||||
|
#search
|
||||||
|
token_js_func = text[
|
||||||
|
text.index("const COOKIE_PREFIX = \"ATERNOS\";") +
|
||||||
|
len("const COOKIE_PREFIX = \"ATERNOS\";") :
|
||||||
|
text.index("(function(i,s,o,g,r,a,m)")
|
||||||
|
].strip()
|
||||||
|
print(token_js_func)
|
||||||
|
|
||||||
|
|
||||||
|
# run js
|
||||||
|
ctx = MiniRacer()
|
||||||
|
result = ctx.eval(presettings + token_js_func)
|
||||||
|
result = ctx.call('__log')
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
if 'win_var' in result and result['win_var']:
|
||||||
|
result = result['win_var']
|
||||||
|
elif '1' in result and ('2' in result and not result['2']):
|
||||||
|
result = base64.standard_b64decode(result['1'])
|
||||||
|
else:
|
||||||
|
result = base64.standard_b64decode(result['2'])
|
||||||
|
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
self.token = result
|
||||||
|
|
||||||
|
"""
|
||||||
self.token = re.search(
|
self.token = re.search(
|
||||||
r'const\s+AJAX_TOKEN\s*=\s*["\'](\w+)["\']',
|
r'const\s+AJAX_TOKEN\s*=\s*["\'](\w+)["\']',
|
||||||
pagehead.text_content()
|
text
|
||||||
)[1]
|
)[1]
|
||||||
|
"""
|
||||||
except (IndexError, TypeError):
|
except (IndexError, TypeError):
|
||||||
raise aterrors.AternosCredentialsError(
|
raise aterrors.AternosCredentialsError(
|
||||||
'Unable to parse TOKEN from the page'
|
'Unable to parse TOKEN from the page'
|
||||||
|
|
45
racer_test.py
Executable file
45
racer_test.py
Executable file
|
@ -0,0 +1,45 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from py_mini_racer import MiniRacer
|
||||||
|
import base64
|
||||||
|
|
||||||
|
# Set function for manage global vars
|
||||||
|
presettings = """
|
||||||
|
let window = {1: null, 2: null, AJAX_TOKEN: null};
|
||||||
|
let i = 1;
|
||||||
|
function __log() { return {win_var: window["AJAX_TOKEN"], 1: window[1], 2: window[2]} };
|
||||||
|
function atob(arg) {window[i++] = arg;};
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Test cases
|
||||||
|
tests = [
|
||||||
|
"""(() => {window[("A" + "J" + "AX_T" + "OKE" + "N")]=("2iXh5W5u" + "EYq" + "5fWJIa" + "zQ6");})();""",
|
||||||
|
""" (() => {window[["N","TOKE","AJAX_"].reverse().join('')]=["IazQ6","fWJ","h5W5uEYq5","2iX"].reverse().join('');})();""",
|
||||||
|
"""(() => {window["AJAX_TOKEN"] = atob("SGVsbG8sIHdvcmxk")})();""",
|
||||||
|
"""(() => {window[atob('QUpBWF9UT0tFTg==')]=atob('MmlYaDVXNXVFWXE1ZldKSWF6UTY=');})();""",
|
||||||
|
"""(() => {window["AJAX_TOKEN"] = "1234" })();""",
|
||||||
|
"""(() => {window[atob('QUpBWF9UT0tFTg==')]="2iXh5W5uEYq5fWJIazQ6";})();""",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Emulate 'atob' function
|
||||||
|
#print(base64.standard_b64decode('MmlYaDVXNXVFWXE1ZldKSWF6UTY='))
|
||||||
|
|
||||||
|
for js in tests:
|
||||||
|
ctx = MiniRacer()
|
||||||
|
result = ctx.eval(presettings + js)
|
||||||
|
result = ctx.call('__log')
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
'''
|
||||||
|
if 'win_var' in result and result['win_var']:
|
||||||
|
result = result['win_var']
|
||||||
|
elif '1' in result and ('2' in result and not result['2']):
|
||||||
|
result = base64.standard_b64decode(result['1'])
|
||||||
|
else:
|
||||||
|
result = base64.standard_b64decode(result['2'])
|
||||||
|
'''
|
||||||
|
print('Case:\n', js, '\n')
|
||||||
|
print('Result: \n', result, '\n')
|
||||||
|
print('-' * 30, '\n')
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
lxml==4.6.2
|
lxml==4.6.2
|
||||||
requests==2.25.1
|
requests==2.25.1
|
||||||
cloudscraper==1.2.58
|
cloudscraper==1.2.58
|
||||||
|
py-mini-racer==0.6.0
|
||||||
|
|
Reference in a new issue