forked from PANIGE/Airmod-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
104 lines (83 loc) · 3.84 KB
/
main.py
File metadata and controls
104 lines (83 loc) · 3.84 KB
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
97
98
99
100
101
102
103
104
from multiprocessing import context
from multiprocessing.sharedctypes import Value
import os
import sys
from multiprocessing.pool import ThreadPool
import traceback
import tornado.gen
import tornado.httpserver
import tornado.ioloop
import tornado.web
from objects import Context
import pkgutil
import logging
import threading
from handlers.WebRegister import WebStore
from helpers.config import configManager
from helpers import console
from helpers import database
from helpers import generalHelper
def make_app():
return tornado.web.Application(WebStore.items())
if __name__ == "__main__":
try:
os.system('cls' if os.name == 'nt' else 'clear')
console.printAscii()
generalHelper.CheckFolders()
Context.runtimeLog = open(".data/logs/runtime.log", "w")
Context.errorLog = open(".data/logs/errors.log", "w")
Context.pool = ThreadPool(24)
console.writeColored("Hello! this is Airmod API.", console.Colors.GREEN)
console.write("> Reading config file... ", True)
Context.configManager = configManager("config.ini")
if Context.configManager.default:
console.writeCaution()
console.writeColored("[!] config.ini not found. A default one has been generated.", console.Colors.YELLOW)
console.writeColored("[!] Please edit your config.ini and run the server again.", console.Colors.YELLOW)
raise Exception()
if not Context.configManager.isValid():
console.writeFailure()
console.writeColored("[!] Invalid config.ini. Please configure it properly", console.Colors.RED)
console.writeColored("[!] Delete your config.ini to generate a default one", console.Colors.RED)
raise Exception()
else:
console.writeSuccess()
console.write("> Checking folders... ", True)
paths = [".data"]
for i in paths:
if not os.path.exists(i):
os.makedirs(i, 0o770)
console.writeSuccess()
try:
console.write("> Connecting to MySQL database... ", True)
Context.mysql = database.Db()
console.writeSuccess()
except:
# Exception while connecting to db
console.writeFailure()
console.writeColored("[!] Error while connection to database. Please check your config.ini and run the server again", console.Colors.RED)
raise
console.writeColored("> Loading Delta Dash Packets ", console.Colors.BLUE)
generalHelper.registerAllHandlers("handlers/path")
if generalHelper.stringToBool(Context.configManager.config.get("server", "debug")):
Context.debug = True
console.writeColored("[!] Katayo is currently in debug mode", console.Colors.YELLOW)
serverPort = int(Context.configManager.config.get("server", "port"))
console.writeColored("> Listening on: 0.0.0.0:{} \n> Ready to accept connections".format(serverPort), console.Colors.GREEN)
Context.app = make_app()
logging.getLogger('tornado.access').disabled = True
threading.Thread(target=lambda:generalHelper.SideLoops()).start() #Run side tasks
# Set Secure cookies with some encryption
if (not os.path.isfile(".data/secret.key")):
with open(".data/secret.key", 'w') as f:
f.write(generalHelper.randomString(4096))
with open(".data/secret.key", 'r') as f:
Context.app.settings["cookie_secret"] = f.read()
Context.app.listen(serverPort)
tornado.ioloop.IOLoop.instance().start()
finally:
console.writeColored("> Closing server", console.Colors.RED)
if Context.mysql is not None:
Context.mysql.cnx.close()
console.writeColored("> Seeya !", console.Colors.GREEN)
Context.runtimeLog.close()