63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
import Crypto
|
|
import asyncio
|
|
import logging
|
|
import platform
|
|
import sys
|
|
|
|
from aiohttp.web import AppRunner, TCPSite
|
|
|
|
from . import views
|
|
from .application import app
|
|
|
|
|
|
def crypto_check():
|
|
vers_split = platform.python_version().split('.')
|
|
pip_command = 'pip3 uninstall pycrypto && pip3 install pycryptodome'
|
|
|
|
if Crypto.__version__ != '2.6.1':
|
|
return
|
|
|
|
if int(vers_split[1]) > 7 and Crypto.__version__ == '2.6.1':
|
|
logging.error('PyCrypto is broken on Python 3.8+. Please replace it with pycryptodome before running again. Exiting...')
|
|
logging.error(pip_command)
|
|
sys.exit()
|
|
|
|
else:
|
|
logging.warning('PyCrypto is old and should be replaced with pycryptodome')
|
|
logging.warning(pip_command)
|
|
|
|
|
|
async def start_webserver():
|
|
config = app['config']
|
|
runner = AppRunner(app, access_log_format='%{X-Forwarded-For}i "%r" %s %b "%{Referer}i" "%{User-Agent}i"')
|
|
|
|
logging.info(f'Starting webserver at {config.host} ({config.listen}:{config.port})')
|
|
await runner.setup()
|
|
|
|
site = TCPSite(runner, config.listen, config.port)
|
|
await site.start()
|
|
|
|
def main():
|
|
# web pages
|
|
app.router.add_get('/', views.home)
|
|
|
|
# endpoints
|
|
app.router.add_post('/actor', views.inbox)
|
|
app.router.add_post('/inbox', views.inbox)
|
|
app.router.add_get('/actor', views.actor)
|
|
app.router.add_get('/nodeinfo/2.0.json', views.nodeinfo_2_0)
|
|
app.router.add_get('/.well-known/nodeinfo', views.nodeinfo_wellknown)
|
|
app.router.add_get('/.well-known/webfinger', views.webfinger)
|
|
|
|
if logging.DEBUG <= logging.root.level:
|
|
app.router.add_get('/stats', views.stats)
|
|
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
asyncio.ensure_future(start_webserver(), loop=loop)
|
|
loop.run_forever()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
crypto_check()
|
|
main()
|