forked from meower-media/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
136 lines (121 loc) · 4.36 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from cloudlink import CloudLink
from supporter import Supporter
from security import Security
from files import Files
from meower import Meower
from rest_api import app as rest_api_app
from threading import Thread
"""
Streamilator Talk Social Media Platform - Server Source Code
Dependencies:
* CloudLink >=0.1.7.6
* better-profanity
* bcrypt
* traceback
* datetime
* os
* sys
* json
* random
"""
class Main:
def __init__(self, debug=False):
# Initalize libraries
self.cl = CloudLink(debug=debug) # CloudLink Server
self.supporter = Supporter( # Support functionality
cl = self.cl,
packet_callback = self.handle_packet
)
self.filesystem = Files( # Filesystem/Database I/O
logger = self.supporter.log,
errorhandler = self.supporter.full_stack
)
self.accounts = Security( # Security and account management
files = self.filesystem,
supporter = self.supporter,
logger = self.supporter.log,
errorhandler = self.supporter.full_stack
)
# Initialize Meower
self.meower = Meower(
supporter = self.supporter,
cl = self.cl,
logger = self.supporter.log,
errorhandler = self.supporter.full_stack,
accounts = self.accounts,
files = self.filesystem
)
# Load trust keys
result, payload = self.filesystem.load_item("config", "trust_keys")
if result:
self.cl.trustedAccess(True, payload["index"])
# Load IP Banlist
ips = []
for netlog in self.filesystem.db["netlog"].find({"blocked": True}):
ips.append(netlog["_id"])
self.cl.loadIPBlocklist(ips)
# Set server MOTD
self.cl.setMOTD("Streamilator Talk Social Media Platform", True)
# Run REST API
Thread(target=rest_api_app.run, kwargs={"host": "0.0.0.0", "port": 3001, "debug": False, "use_reloader": False}).start()
# Run CloudLink server
self.cl.server(port=3000, ip="0.0.0.0")
def returnCode(self, client, code, listener_detected, listener_id):
self.supporter.sendPacket({"cmd": "statuscode", "val": self.cl.codes[str(code)], "id": client}, listener_detected = listener_detected, listener_id = listener_id)
def handle_packet(self, cmd, ip, val, listener_detected, listener_id, client, clienttype):
try:
commands = set([
"ping",
"version_chk",
"get_ulist",
"authpswd",
"gen_account",
"get_profile",
"update_config",
"change_pswd",
"del_tokens",
"del_account",
"get_home",
"get_inbox",
"post_home",
"get_post",
"get_peak_users",
"search_user_posts",
"report",
"close_report",
"clear_home",
"clear_user_posts",
"alert",
"announce",
"block",
"unblock",
"kick",
"get_user_ip",
"get_ip_data",
"get_user_data",
"ban",
"pardon",
"terminate",
"repair_mode",
"delete_post",
"post_chat",
"set_chat_state",
"create_chat",
"leave_chat",
"get_chat_list",
"get_chat_data",
"get_chat_posts",
"add_to_chat",
"remove_from_chat"
])
if cmd in commands:
getattr(self.meower, cmd)(client, val, listener_detected, listener_id)
else:
# Catch-all error code
self.returnCode(code = "Invalid", client = client, listener_detected = listener_detected, listener_id = listener_id)
except Exception:
self.supporter.log("{0}".format(self.supporter.full_stack()))
# Catch-all error code
self.returnCode(code = "InternalServerError", client = client, listener_detected = listener_detected, listener_id = listener_id)
if __name__ == "__main__":
Main(debug=True)