Trying to add Google authorization
This commit is contained in:
parent
0aace40e2c
commit
ca9cda3b51
6 changed files with 86 additions and 66 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
||||||
# Python
|
# Python
|
||||||
__pycache__
|
__pycache__
|
||||||
|
dist/*
|
||||||
|
*.egg-info/*
|
||||||
|
|
||||||
# Vim
|
# Vim
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
@ -1,43 +1,40 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import lxml.html
|
import lxml.html
|
||||||
from typing import Optional, List
|
from typing import Optional, Union, List
|
||||||
|
|
||||||
from . import atserver
|
from . import atserver
|
||||||
from . import atconnect
|
from . import atconnect
|
||||||
from . import aterrors
|
from . import aterrors
|
||||||
|
from . import client_secrets
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, atconn:atconnect.AternosConnect) -> None:
|
||||||
self, username:str,
|
|
||||||
password:Optional[str]=None,
|
|
||||||
md5:Optional[str]=None) -> None:
|
|
||||||
|
|
||||||
if (password == None) and (md5 == None):
|
self.atconn = atconn
|
||||||
raise AttributeError('Password was not specified')
|
|
||||||
|
|
||||||
if (password != None):
|
# if google:
|
||||||
self.__init__(
|
# flow = Flow.from_client_config\
|
||||||
username,
|
# (
|
||||||
md5=hashlib.md5(password.encode('utf-8'))\
|
# json.loads(
|
||||||
.hexdigest().lower()
|
# base64.standard_base64decode(client_secrets.CSJSON)
|
||||||
)
|
# ),
|
||||||
return
|
# 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()
|
atconn = atconnect.AternosConnect()
|
||||||
self.sec = self.atconn.generate_sec()
|
token = atconn.parse_token()
|
||||||
|
sec = atconn.generate_sec()
|
||||||
self.credentials = {
|
|
||||||
'user': username,
|
|
||||||
'password': md5
|
|
||||||
}
|
|
||||||
|
|
||||||
loginreq = self.atconn.request_cloudflare(
|
loginreq = self.atconn.request_cloudflare(
|
||||||
f'https://aternos.org/panel/ajax/account/login.php?' + \
|
f'https://aternos.org/panel/ajax/account/login.php',
|
||||||
f'SEC={self.sec}&TOKEN={self.token}',
|
atconnect.REQPOST, data=self.credentials,
|
||||||
atconnect.REQPOST, data=self.credentials
|
sendtoken=True
|
||||||
)
|
)
|
||||||
|
|
||||||
if loginreq.cookies.get('ATERNOS_SESSION', None) == None:
|
if loginreq.cookies.get('ATERNOS_SESSION', None) == None:
|
||||||
|
@ -45,6 +42,20 @@ class Client:
|
||||||
'Check your username and password'
|
'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
|
@property
|
||||||
def servers(self) -> List[atserver.AternosServer]:
|
def servers(self) -> List[atserver.AternosServer]:
|
||||||
serverspage = self.atconn.request_cloudflare(
|
serverspage = self.atconn.request_cloudflare(
|
||||||
|
|
|
@ -89,10 +89,7 @@ class AternosConnect:
|
||||||
cftitle = '<title>Please Wait... | Cloudflare</title>'
|
cftitle = '<title>Please Wait... | Cloudflare</title>'
|
||||||
|
|
||||||
if sendtoken:
|
if sendtoken:
|
||||||
if params == None:
|
url += f'?TOKEN={self.token}&SEC={self.sec}'
|
||||||
params = {}
|
|
||||||
params['SEC'] = self.sec
|
|
||||||
params['TOKEN'] = self.token
|
|
||||||
|
|
||||||
if headers == None:
|
if headers == None:
|
||||||
headers = {}
|
headers = {}
|
||||||
|
@ -150,4 +147,12 @@ class AternosConnect:
|
||||||
)
|
)
|
||||||
countdown -= 1
|
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
|
return req
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
import re
|
import re
|
||||||
import js2py
|
import js2py
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
brkregex = re.compile(r'\((?!\)|[\'\"])(.+?)(?<!\(|[\'\"])\)')
|
brkregex = re.compile(r'\((?!\)|[\'\"])(.+?)(?<!\(|[\'\"])\)')
|
||||||
|
|
||||||
def parse_brackets(f):
|
def parse_brackets(f):
|
||||||
return brkregex.search(f)[1]
|
return brkregex.search(f)[1]
|
||||||
|
|
||||||
def to_ecma5_function(f):
|
def to_ecma5_function(f):
|
||||||
fnstart = f.find('{')+1
|
fnstart = f.find('{')+1
|
||||||
fnend = f.rfind('}')
|
fnend = f.rfind('}')
|
||||||
f = arrow_conv(f[fnstart:fnend])
|
f = arrow_conv(f[fnstart:fnend])
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def atob(s):
|
def atob(s):
|
||||||
return base64.standard_b64decode(str(s)).decode('utf-8')
|
return base64.standard_b64decode(str(s)).decode('utf-8')
|
||||||
|
|
||||||
def arrow_conv(f):
|
def arrow_conv(f):
|
||||||
if '=>' in f:
|
if '=>' in f:
|
||||||
inner = parse_brackets(f)
|
inner = parse_brackets(f)
|
||||||
while brkregex.match(inner) != None:
|
while brkregex.match(inner) != None:
|
||||||
inner = parse_brackets(inner)
|
inner = parse_brackets(inner)
|
||||||
|
|
||||||
func = re.sub(
|
func = re.sub(
|
||||||
r'(\w+)\s*=>\s*(.+)',
|
r'(\w+)\s*=>\s*(.+)',
|
||||||
r'function(\1){return \2}', inner
|
r'function(\1){return \2}', inner
|
||||||
)
|
)
|
||||||
start = f.find(inner)
|
start = f.find(inner)
|
||||||
end = start + len(inner)
|
end = start + len(inner)
|
||||||
f = f[:start] + func + f[end:]
|
f = f[:start] + func + f[end:]
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def exec(f):
|
def exec(f):
|
||||||
ctx = js2py.EvalJs({'atob': atob})
|
ctx = js2py.EvalJs({'atob': atob})
|
||||||
ctx.execute(to_ecma5_function(f))
|
ctx.execute(to_ecma5_function(f))
|
||||||
return ctx
|
return ctx
|
||||||
|
|
|
@ -129,6 +129,7 @@ class AternosServer:
|
||||||
headers:Optional[dict]=None,
|
headers:Optional[dict]=None,
|
||||||
sendtoken:bool=False) -> Response:
|
sendtoken:bool=False) -> Response:
|
||||||
|
|
||||||
|
print(sendtoken)
|
||||||
return self.atconn.request_cloudflare(
|
return self.atconn.request_cloudflare(
|
||||||
url=url, method=method,
|
url=url, method=method,
|
||||||
params=params, data=data,
|
params=params, data=data,
|
||||||
|
|
1
python_aternos/client_secrets.py
Normal file
1
python_aternos/client_secrets.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CSJSON = 'eyJpbnN0YWxsZWQiOnsiY2xpZW50X2lkIjoiNjU4MTQyNjkxNjQxLXFnZ21sdGNmdXY0a2I1a2NwczdoZjBiaGlvN2Q0dnUzLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwicHJvamVjdF9pZCI6InB5dGhvbi1hdGVybm9zIiwiYXV0aF91cmkiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvYXV0aCIsInRva2VuX3VyaSI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiYXV0aF9wcm92aWRlcl94NTA5X2NlcnRfdXJsIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vb2F1dGgyL3YxL2NlcnRzIiwiY2xpZW50X3NlY3JldCI6IkdPQ1NQWC1XUUJsMjIzOTZxcHVLMDJIVXVpWUhhUXNmbC03IiwicmVkaXJlY3RfdXJpcyI6WyJ1cm46aWV0Zjp3ZzpvYXV0aDoyLjA6b29iIiwiaHR0cDovL2xvY2FsaG9zdCJdfX0='
|
Reference in a new issue