diff --git a/.gitignore b/.gitignore index 9577a63..22c3ba1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Python __pycache__ +dist/* +*.egg-info/* # Vim *.swp diff --git a/python_aternos/__init__.py b/python_aternos/__init__.py index 0df4f92..d476106 100644 --- a/python_aternos/__init__.py +++ b/python_aternos/__init__.py @@ -1,43 +1,40 @@ import hashlib import lxml.html -from typing import Optional, List +from typing import Optional, Union, List from . import atserver from . import atconnect from . import aterrors +from . import client_secrets class Client: - def __init__( - self, username:str, - password:Optional[str]=None, - md5:Optional[str]=None) -> None: + def __init__(self, atconn:atconnect.AternosConnect) -> None: - if (password == None) and (md5 == None): - raise AttributeError('Password was not specified') + self.atconn = atconn - if (password != None): - self.__init__( - username, - md5=hashlib.md5(password.encode('utf-8'))\ - .hexdigest().lower() - ) - return + # if google: + # flow = Flow.from_client_config\ + # ( + # json.loads( + # base64.standard_base64decode(client_secrets.CSJSON) + # ), + # scopes=['openid', 'email'] + # ) + # # localhost:8764 + # flow.run_local_server(port=8764, open_browser=False) - self.atconn = atconnect.AternosConnect() + @classmethod + def from_hashed(cls, username:str, md5:str): - self.token = self.atconn.parse_token() - self.sec = self.atconn.generate_sec() - - self.credentials = { - 'user': username, - 'password': md5 - } + atconn = atconnect.AternosConnect() + token = atconn.parse_token() + sec = atconn.generate_sec() loginreq = self.atconn.request_cloudflare( - f'https://aternos.org/panel/ajax/account/login.php?' + \ - f'SEC={self.sec}&TOKEN={self.token}', - atconnect.REQPOST, data=self.credentials + f'https://aternos.org/panel/ajax/account/login.php', + atconnect.REQPOST, data=self.credentials, + sendtoken=True ) if loginreq.cookies.get('ATERNOS_SESSION', None) == None: @@ -45,6 +42,20 @@ class Client: 'Check your username and password' ) + cls(atconn) + + @classmethod + def from_credentials(cls, username:str, password:str): + cls.from_hashed( + username, + hashlib.md5(password.encode('utf-8'))\ + .hexdigest().lower() + ) + + @classmethod + def with_google(cls): + pass + @property def servers(self) -> List[atserver.AternosServer]: serverspage = self.atconn.request_cloudflare( diff --git a/python_aternos/atconnect.py b/python_aternos/atconnect.py index 55b6bea..5d4b5a1 100644 --- a/python_aternos/atconnect.py +++ b/python_aternos/atconnect.py @@ -89,10 +89,7 @@ class AternosConnect: cftitle = 'Please Wait... | Cloudflare' if sendtoken: - if params == None: - params = {} - params['SEC'] = self.sec - params['TOKEN'] = self.token + url += f'?TOKEN={self.token}&SEC={self.sec}' if headers == None: headers = {} @@ -150,4 +147,12 @@ class AternosConnect: ) countdown -= 1 + print(sendtoken) + try: + print(self.sec, self.token) + except AttributeError: + pass + print(req.status_code) + print(req.cookies) + print(req.url, '', sep='\n---') return req diff --git a/python_aternos/atjsparse.py b/python_aternos/atjsparse.py index c6918fe..a7fc945 100644 --- a/python_aternos/atjsparse.py +++ b/python_aternos/atjsparse.py @@ -1,37 +1,37 @@ -import re -import js2py -import base64 - -brkregex = re.compile(r'\((?!\)|[\'\"])(.+?)(?' in f: - inner = parse_brackets(f) - while brkregex.match(inner) != None: - inner = parse_brackets(inner) - - func = re.sub( - r'(\w+)\s*=>\s*(.+)', - r'function(\1){return \2}', inner - ) - start = f.find(inner) - end = start + len(inner) - f = f[:start] + func + f[end:] - return f - -def exec(f): - ctx = js2py.EvalJs({'atob': atob}) - ctx.execute(to_ecma5_function(f)) - return ctx +import re +import js2py +import base64 + +brkregex = re.compile(r'\((?!\)|[\'\"])(.+?)(?' in f: + inner = parse_brackets(f) + while brkregex.match(inner) != None: + inner = parse_brackets(inner) + + func = re.sub( + r'(\w+)\s*=>\s*(.+)', + r'function(\1){return \2}', inner + ) + start = f.find(inner) + end = start + len(inner) + f = f[:start] + func + f[end:] + return f + +def exec(f): + ctx = js2py.EvalJs({'atob': atob}) + ctx.execute(to_ecma5_function(f)) + return ctx diff --git a/python_aternos/atserver.py b/python_aternos/atserver.py index 33f00b9..d68ad28 100644 --- a/python_aternos/atserver.py +++ b/python_aternos/atserver.py @@ -129,6 +129,7 @@ class AternosServer: headers:Optional[dict]=None, sendtoken:bool=False) -> Response: + print(sendtoken) return self.atconn.request_cloudflare( url=url, method=method, params=params, data=data, diff --git a/python_aternos/client_secrets.py b/python_aternos/client_secrets.py new file mode 100644 index 0000000..3a06fb3 --- /dev/null +++ b/python_aternos/client_secrets.py @@ -0,0 +1 @@ +CSJSON = 'eyJpbnN0YWxsZWQiOnsiY2xpZW50X2lkIjoiNjU4MTQyNjkxNjQxLXFnZ21sdGNmdXY0a2I1a2NwczdoZjBiaGlvN2Q0dnUzLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwicHJvamVjdF9pZCI6InB5dGhvbi1hdGVybm9zIiwiYXV0aF91cmkiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvYXV0aCIsInRva2VuX3VyaSI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiYXV0aF9wcm92aWRlcl94NTA5X2NlcnRfdXJsIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vb2F1dGgyL3YxL2NlcnRzIiwiY2xpZW50X3NlY3JldCI6IkdPQ1NQWC1XUUJsMjIzOTZxcHVLMDJIVXVpWUhhUXNmbC03IiwicmVkaXJlY3RfdXJpcyI6WyJ1cm46aWV0Zjp3ZzpvYXV0aDoyLjA6b29iIiwiaHR0cDovL2xvY2FsaG9zdCJdfX0='