Add files via upload

This commit is contained in:
Andrey 2021-10-08 19:35:20 +04:00 committed by GitHub
parent c4fa20fd14
commit b010b8a4c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 420 additions and 305 deletions

View file

@ -0,0 +1,58 @@
import hashlib
import lxml.html
from . import atserver
from . import atconnect
from . import aterrors
class Client:
def __init__(self, username, md5=None, password=None):
if (password == None) and (md5 == None):
raise AttributeError('Password was not specified')
if (password != None):
self.__init__(
username,
md5=hashlib.md5(password.encode('utf-8'))\
.hexdigest().lower()
)
return
self.atconn = atconnect.AternosConnect()
self.token = self.atconn.get_token()
self.sec = self.atconn.generate_sec()
self.credentials = {
'user': username,
'password': md5
}
loginreq = self.atconn.request_cloudflare(
f'https://aternos.org/panel/ajax/account/login.php?' + \
f'SEC={self.sec}&TOKEN={self.token}',
self.atconn.REQPOST, data=self.credentials
)
if loginreq.cookies.get('ATERNOS_SESSION', None) == None:
raise aterrors.AternosCredentialsError(
'Check your username and password'
)
def get_servers(self):
serverspage = self.atconn.request_cloudflare(
'https://aternos.org/servers/',
self.atconn.REQGET
)
serverstree = lxml.html.fromstring(serverspage.content)
serverslist = serverstree.xpath('//div[@class="servers"]/div')
servers = []
for server in serverslist:
servid = server.xpath('./div[@class="server-body"]/@data-id')[0]
servers.append(atserver.AternosServer(servid, self.atconn))
return servers

View file

@ -3,7 +3,8 @@ import time
import random import random
import lxml.html import lxml.html
from cloudscraper import CloudScraper from cloudscraper import CloudScraper
from aterrors import AternosCredentialsError
from . import aterrors
class AternosConnect: class AternosConnect:
@ -33,7 +34,7 @@ class AternosConnect:
pagehead.text_content() pagehead.text_content()
)[1] )[1]
except (IndexError, TypeError): except (IndexError, TypeError):
raise AternosCredentialsError( raise aterrors.AternosCredentialsError(
'Unable to parse TOKEN from the page' 'Unable to parse TOKEN from the page'
) )

28
python_aternos/atfiles.py Normal file
View file

@ -0,0 +1,28 @@
from . import atconnect
class AternosFileManager:
def __init__(atserv):
self.atserv = atserv
def listdir(self, path=''):
self.atserv.atserver_request(
f'https://aternos.org/files/{path}',
atconnect.AternosConnect.REQGET
)
def get_file(self, path):
self.atserv.atserver_request(
f'https://aternos.org/panel/ajax/files/download.php?file={path}',
atconnect.AternosConnect.REQGET
)
def get_world(self, world):
self.atserv.atserver_request(
f'https://aternos.org/panel/ajax/worlds/download.php?world={world}',
atconnect.AternosConnect.REQGET
)

View file

@ -1,5 +1,7 @@
import lxml.html import lxml.html
import aterrors
from . import aterrors
from . import atfiles
class AternosServer: class AternosServer:
@ -8,7 +10,7 @@ class AternosServer:
self.servid = servid self.servid = servid
self.atconn = atconn self.atconn = atconn
servreq = self._atserver_request( servreq = self.atserver_request(
'https://aternos.org/server', 'https://aternos.org/server',
self.atconn.REQGET self.atconn.REQGET
) )
@ -21,7 +23,12 @@ class AternosServer:
'/div[@class="server-info-box-body"]' + \ '/div[@class="server-info-box-body"]' + \
'/div[@class="server-info-box-value"]/span' '/div[@class="server-info-box-value"]/span'
) )
self._address = servinfo[0].text
fullip = servinfo[0].text
self._address = fullip
self._domain = fullip[:fullip.rfind(':')]
self._port = fullip[fullip.rfind(':')+1:]
self._software = servinfo[1].text self._software = servinfo[1].text
self._version = servinfo[2].text self._version = servinfo[2].text
@ -30,7 +37,7 @@ class AternosServer:
def start(self, accepteula=True): def start(self, accepteula=True):
startreq = self._atserver_request( startreq = self.atserver_request(
'https://aternos.org/panel/ajax/start.php', 'https://aternos.org/panel/ajax/start.php',
self.atconn.REQGET, sendtoken=True self.atconn.REQGET, sendtoken=True
) )
@ -55,35 +62,46 @@ class AternosServer:
f'Unable to start server. Code: {error}' f'Unable to start server. Code: {error}'
) )
def confirm(self):
self.atserver_request(
'https://aternos.org/panel/ajax/confirm.php',
self.atconn.REQGET, sendtoken=True
)
def stop(self): def stop(self):
self._atserver_request( self.atserver_request(
'https://aternos.org/panel/ajax/stop.php', 'https://aternos.org/panel/ajax/stop.php',
self.atconn.REQGET, sendtoken=True self.atconn.REQGET, sendtoken=True
) )
def cancel(self): def cancel(self):
self._atserver_request( self.atserver_request(
'https://aternos.org/panel/ajax/cancel.php', 'https://aternos.org/panel/ajax/cancel.php',
self.atconn.REQGET, sendtoken=True self.atconn.REQGET, sendtoken=True
) )
def restart(self): def restart(self):
self._atserver_request( self.atserver_request(
'https://aternos.org/panel/ajax/restart.php', 'https://aternos.org/panel/ajax/restart.php',
self.atconn.REQGET, sendtoken=True self.atconn.REQGET, sendtoken=True
) )
def eula(self): def eula(self):
self._atserver_request( self.atserver_request(
'https://aternos.org/panel/ajax/eula.php', 'https://aternos.org/panel/ajax/eula.php',
self.atconn.REQGET, sendtoken=True self.atconn.REQGET, sendtoken=True
) )
def _atserver_request( def files(self):
return AternosFileManager(self)
def atserver_request(
self, url, method, params=None, self, url, method, params=None,
data=None, headers=None, sendtoken=False): data=None, headers=None, sendtoken=False):
@ -101,6 +119,14 @@ class AternosServer:
def address(self): def address(self):
return self._address return self._address
@property
def domain(self):
return self._domain
@property
def port(self):
return self._port
@property @property
def software(self): def software(self):
return self._software return self._software

View file

@ -5,7 +5,7 @@ with open('README.md', 'rt') as readme:
setuptools.setup( setuptools.setup(
name='python-aternos', name='python-aternos',
version='0.1', version='0.2',
author='Chechkenev Andrey (@DarkCat09)', author='Chechkenev Andrey (@DarkCat09)',
author_email='aacd0709@mail.ru', author_email='aacd0709@mail.ru',
description='An unofficial Aternos API', description='An unofficial Aternos API',
@ -14,6 +14,7 @@ setuptools.setup(
url='https://github.com/DarkCat09/python-aternos', url='https://github.com/DarkCat09/python-aternos',
project_urls={ project_urls={
'Bug Tracker': 'https://github.com/DarkCat09/python-aternos/issues', 'Bug Tracker': 'https://github.com/DarkCat09/python-aternos/issues',
'Documentation': 'https://github.com/DarkCat09/python-aternos/wiki/Client-(entry-point)',
}, },
classifiers=[ classifiers=[
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
@ -25,5 +26,6 @@ setuptools.setup(
'requests==2.25.1', 'requests==2.25.1',
'cloudscraper==1.2.58' 'cloudscraper==1.2.58'
], ],
packages=['python_aternos'],
python_requires=">=3.6", python_requires=">=3.6",
) )