forked from RealistikOsu/RealistikPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
652 lines (590 loc) · 29.1 KB
/
main.py
File metadata and controls
652 lines (590 loc) · 29.1 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
#This file is responsible for running the web server and (mostly nothing else)
from flask import Flask, render_template, session, redirect, url_for, request, send_from_directory, jsonify
from flask_recaptcha import ReCaptcha
from defaults import *
from config import UserConfig
from functions import *
from colorama import Fore, init
import os
from updater import *
from threading import Thread
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
print(f" {Fore.BLUE}Running Build {GetBuild()}")
ConsoleLog(f"RealistikPanel (Build {GetBuild()}) started!")
app = Flask(__name__)
recaptcha = ReCaptcha(app=app)
app.secret_key = os.urandom(24) #encrypts the session cookie
#recaptcha setup
if UserConfig["UseRecaptcha"]:
#recaptcha config
app.config.update({
"RECAPTCHA_THEME" : "dark",
"RECAPTCHA_SITE_KEY" : UserConfig["RecaptchaSiteKey"],
"RECAPTCHA_SECRET_KEY" : UserConfig["RecaptchaSecret"],
"RECAPTCHA_ENABLED" : True
})
@app.route("/")
def home():
if session["LoggedIn"]:
return redirect(url_for("dash"))
else:
return redirect(url_for("login"))
@app.route("/dash/")
def dash():
if HasPrivilege(session["AccountId"]):
#responsible for the "HeY cHeCk OuT tHe ChAnGeLoG"
User = GetCachedStore(session["AccountName"])
Thread(target=UpdateUserStore, args=(session["AccountName"],)).start()
if User["LastBuild"] == GetBuild():
return render_template("dash.html", title="Dashboard", session=session, data=DashData(), plays=RecentPlays(), config=UserConfig, Graph=DashActData(), MostPlayed=GetMostPlayed())
else:
return render_template("dash.html", title="Dashboard", session=session, data=DashData(), plays=RecentPlays(), config=UserConfig, Graph=DashActData(), MostPlayed=GetMostPlayed(), info=f"Hey! RealistikPanel has been recently updated to build <b>{GetBuild()}</b>! Check out <a href='/changelogs'>what's new here!</a>")
else:
return NoPerm(session)
@app.route("/login", methods = ["GET", "POST"])
def login():
if not session["LoggedIn"] and not HasPrivilege(session["AccountId"]):
if request.method == "GET":
return render_template("login.html", conf = UserConfig)
if request.method == "POST":
if recaptcha.verify():
LoginData = LoginHandler(request.form["username"], request.form["password"])
if not LoginData[0]:
return render_template("login.html", alert=LoginData[1], conf = UserConfig)
if LoginData[0]:
SessionToApply = LoginData[2]
#modifying the session
for key in list(SessionToApply.keys()):
session[key] = SessionToApply[key]
return redirect(url_for("home"))
else:
return render_template("login.html", alert="ReCaptcha Failed!", conf=UserConfig)
else:
return redirect(url_for("dash"))
@app.route("/logout")
def logout():
#modifying the session
for x in list(ServSession.keys()):
session[x] = ServSession[x]
return redirect(url_for("home"))
@app.route("/bancho/settings", methods = ["GET", "POST"])
def BanchoSettings():
if HasPrivilege(session["AccountId"], 4):
#no bypassing it.
if request.method == "GET":
return render_template("banchosettings.html", preset=FetchBSData(), title="Bancho Settings", data=DashData(), bsdata=FetchBSData(), session=session, config=UserConfig)
if request.method == "POST":
try:
BSPostHandler([request.form["banchoman"], request.form["mainmemuicon"], request.form["loginnotif"]], session) #handles all the changes
return render_template("banchosettings.html", preset=FetchBSData(), title="Bancho Settings", data=DashData(), bsdata=FetchBSData(), session=session, config=UserConfig, success="Bancho settings were successfully edited!")
except Exception as e:
print(e)
ConsoleLog("Error while editing bancho settings!", f"{e}", 3)
return render_template("banchosettings.html", preset=FetchBSData(), title="Bancho Settings", data=DashData(), bsdata=FetchBSData(), session=session, config=UserConfig, error="An internal error has occured while saving bancho settings! An error has been logged to the console.")
else:
return NoPerm(session)
@app.route("/rank/<id>", methods = ["GET", "POST"])
def RankMap(id):
if HasPrivilege(session["AccountId"], 3):
if request.method == "GET":
return render_template("beatrank.html", title="Rank Beatmap!", data=DashData(), session=session, beatdata=SplitList(GetBmapInfo(id)), config=UserConfig, Id= id)
if request.method == "POST":
try:
BeatmapNumber = request.form["beatmapnumber"]
RankBeatmap(BeatmapNumber, request.form[f"bmapid-{BeatmapNumber}"], request.form[f"rankstatus-{BeatmapNumber}"], session)
return render_template("beatrank.html", title="Rank Beatmap!", data=DashData(), session=session, beatdata=SplitList(GetBmapInfo(id)), config=UserConfig, success=f"Successfully ranked beatmap {id}!", Id= id)
except Exception as e:
print(e)
ConsoleLog(f"Error while ranking beatmap ({id})!", f"{e}", 3)
return render_template("beatrank.html", title="Rank Beatmap!", data=DashData(), session=session, beatdata=SplitList(GetBmapInfo(id)), config=UserConfig, error="An internal error has occured while ranking! An error has been logged to the console.", Id= id)
else:
return NoPerm(session)
@app.route("/rank", methods = ["GET", "POST"])
def RankFrom():
if request.method == "GET":
if HasPrivilege(session["AccountId"], 3):
return render_template("rankform.html", title="Rank a beatmap!", data=DashData(), session=session, config=UserConfig, SuggestedBmaps = SplitList(GetSuggestedRank()))
else:
return NoPerm(session)
else:
if not HasPrivilege(session["AccountId"]): #mixing things up eh
return NoPerm(session)
else:
return redirect(f"/rank/{request.form['bmapid']}") #does this even work
@app.route("/users/<page>", methods = ["GET", "POST"])
def Users(page = 1):
if HasPrivilege(session["AccountId"], 6):
if request.method == "GET":
return render_template("users.html", title="Users", data=DashData(), session=session, config=UserConfig, UserData = FetchUsers(int(page)-1), page=int(page), Pages=UserPageCount())
if request.method == "POST":
return render_template("users.html", title="Users", data=DashData(), session=session, config=UserConfig, UserData = FindUserByUsername(request.form["user"], int(page)), page=int(page), User=request.form["user"], Pages=UserPageCount())
else:
return NoPerm(session)
@app.route("/index.php")
def LegacyIndex():
"""For implementing RAP funcions."""
Page = request.args.get("p")
if Page == "124":
#ranking page
return redirect(f"/rank/{request.args.get('bsid')}")
elif Page == "103": #hanayo link
Account = request.args.get("id")
return redirect(f"/user/edit/{Account}")
return redirect(url_for("dash")) #take them to the root
@app.route("/system/settings", methods = ["GET", "POST"])
def SystemSettings():
if HasPrivilege(session["AccountId"], 4):
if request.method == "GET":
return render_template("syssettings.html", data=DashData(), session=session, title="System Settings", SysData=SystemSettingsValues(), config=UserConfig)
if request.method == "POST":
try:
ApplySystemSettings([request.form["webman"], request.form["gameman"], request.form["register"], request.form["globalalert"], request.form["homealert"]], session) #why didnt i just pass request
return render_template("syssettings.html", data=DashData(), session=session, title="System Settings", SysData=SystemSettingsValues(), config=UserConfig, success = "System settings successfully edited!")
except Exception as e:
print(e)
ConsoleLog("Error while editing system settings!", f"{e}", 3)
return render_template("syssettings.html", data=DashData(), session=session, title="System Settings", SysData=SystemSettingsValues(), config=UserConfig, error = "An internal error has occured while saving system settings! An error has been logged to the console.")
else:
return NoPerm(session)
@app.route("/user/edit/<id>", methods = ["GET", "POST"])
def EditUser(id):
if request.method == "GET":
if HasPrivilege(session["AccountId"], 6):
return render_template("edituser.html", data=DashData(), session=session, title="Edit User", config=UserConfig, UserData=UserData(id), Privs = GetPrivileges(), UserBadges= GetUserBadges(id), badges=GetBadges(), ShowIPs = HasPrivilege(session["AccountId"], 16))
else:
return NoPerm(session)
if request.method == "POST":
if HasPrivilege(session["AccountId"], 6):
try:
ApplyUserEdit(request.form, session)
RAPLog(session["AccountId"], f"has edited the user {request.form.get('username', 'NOT FOUND')}")
return render_template("edituser.html", data=DashData(), session=session, title="Edit User", config=UserConfig, UserData=UserData(id), Privs = GetPrivileges(), UserBadges= GetUserBadges(id), badges=GetBadges(), success=f"User {request.form.get('username', 'NOT FOUND')} has been successfully edited!", ShowIPs = HasPrivilege(session["AccountId"], 16))
except Exception as e:
print(e)
ConsoleLog("Error while editing user!", f"{e}", 3)
return render_template("edituser.html", data=DashData(), session=session, title="Edit User", config=UserConfig, UserData=UserData(id), Privs = GetPrivileges(), UserBadges= GetUserBadges(id), badges=GetBadges(), error="An internal error has occured while editing the user! An error has been logged to the console.", ShowIPs = HasPrivilege(session["AccountId"], 16))
else:
return NoPerm(session)
@app.route("/logs/<page>")
def Logs(page):
if HasPrivilege(session["AccountId"], 7):
return render_template("raplogs.html", data=DashData(), session=session, title="Logs", config=UserConfig, Logs = RAPFetch(page), page=int(page), Pages = RapLogCount())
else:
return NoPerm(session)
@app.route("/action/confirm/delete/<id>")
def ConfirmDelete(id):
"""Confirms deletion of acc so accidents dont happen"""
#i almost deleted my own acc lmao
#me forgetting to commit changes saved me
if HasPrivilege(session["AccountId"], 6):
AccountToBeDeleted = GetUser(id)
return render_template("confirm.html", data=DashData(), session=session, title="Confirmation Required", config=UserConfig, action=f"delete the user {AccountToBeDeleted['Username']}", yeslink=f"/actions/delete/{id}", backlink=f"/user/edit/{id}")
else:
return NoPerm(session)
@app.route("/user/iplookup/<ip>")
def IPUsers(ip):
if HasPrivilege(session["AccountId"], 16):
IPUserLookup = FindWithIp(ip)
UserLen = len(IPUserLookup)
return render_template("iplookup.html", data=DashData(), session=session, title="IP Lookup", config=UserConfig, ipusers=IPUserLookup, IPLen = UserLen, ip=ip)
else:
return NoPerm(session)
@app.route("/badges")
def Badges():
if HasPrivilege(session["AccountId"], 4):
return render_template("badges.html", data=DashData(), session=session, title="Badges", config=UserConfig, badges=GetBadges())
else:
return NoPerm(session)
@app.route("/badge/edit/<BadgeID>", methods = ["GET", "POST"])
def EditBadge(BadgeID: int):
if HasPrivilege(session["AccountId"], 4):
if request.method == "GET":
return render_template("editbadge.html", data=DashData(), session=session, title="Edit Badge", config=UserConfig, badge=GetBadge(BadgeID))
if request.method == "POST":
try:
SaveBadge(request.form)
RAPLog(session["AccountId"], f"edited the badge with the ID of {BadgeID}")
return render_template("editbadge.html", data=DashData(), session=session, title="Edit Badge", config=UserConfig, badge=GetBadge(BadgeID), success=f"Badge {BadgeID} has been successfully edited!")
except Exception as e:
print(e)
ConsoleLog("Error while editing badge!", f"{e}", 3)
return render_template("editbadge.html", data=DashData(), session=session, title="Edit Badge", config=UserConfig, badge=GetBadge(BadgeID), error="An internal error has occured while editing the badge! An error has been logged to the console.")
else:
return NoPerm(session)
@app.route("/privileges")
def EditPrivileges():
if HasPrivilege(session["AccountId"], 13):
return render_template("privileges.html", data=DashData(), session=session, title="Privileges", config=UserConfig, privileges=GetPrivileges())
else:
return NoPerm(session)
@app.route("/privilege/edit/<Privilege>", methods = ["GET", "POST"])
def EditPrivilege(Privilege: int):
if HasPrivilege(session["AccountId"], 13):
if request.method == "GET":
return render_template("editprivilege.html", data=DashData(), session=session, title="Privileges", config=UserConfig, privileges=GetPriv(Privilege))
if request.method == "POST":
try:
UpdatePriv(request.form)
Priv = GetPriv(Privilege)
RAPLog(session["AccountId"], f"has edited the privilege group {Priv['Name']} ({Priv['Id']})")
return render_template("editprivilege.html", data=DashData(), session=session, title="Privileges", config=UserConfig, privileges=Priv, success=f"Privilege {Priv['Name']} has been successfully edited!")
except Exception as e:
print(e)
ConsoleLog("Error while editing privilege!", f"{e}", 3)
Priv = GetPriv(Privilege)
return render_template("editprivilege.html", data=DashData(), session=session, title="Privileges", config=UserConfig, privileges=Priv, error="An internal error has occured while editing the privileges! An error has been logged to the console.")
else:
return NoPerm(session)
@app.route("/console")
def Console():
if HasPrivilege(session["AccountId"], 14):
return render_template("consolelogs.html", data=DashData(), session=session, title="Console Logs", config=UserConfig, logs=GetLog())
else:
return NoPerm(session)
@app.route("/changelogs")
def ChangeLogs():
if HasPrivilege(session["AccountId"]):
return render_template("changelog.html", data=DashData(), session=session, title="Change Logs", config=UserConfig, logs=Changelogs)
else:
return NoPerm(session)
@app.route("/current.json")
def CurrentIPs():
"""IPs for the Ripple switcher."""
return jsonify({
"osu.ppy.sh": UserConfig["CurrentIP"],
"c.ppy.sh": UserConfig["CurrentIP"],
"c1.ppy.sh": UserConfig["CurrentIP"],
"c2.ppy.sh": UserConfig["CurrentIP"],
"c3.ppy.sh": UserConfig["CurrentIP"],
"c4.ppy.sh": UserConfig["CurrentIP"],
"c5.ppy.sh": UserConfig["CurrentIP"],
"c6.ppy.sh": UserConfig["CurrentIP"],
"ce.ppy.sh": UserConfig["CurrentIP"],
"a.ppy.sh": UserConfig["CurrentIP"],
"s.ppy.sh": UserConfig["CurrentIP"],
"i.ppy.sh": UserConfig["CurrentIP"],
"bm6.ppy.sh": UserConfig["CurrentIP"]
})
@app.route("/toggledark")
def ToggleDark():
if session["Theme"] == "dark":
session["Theme"] = "white"
else:
session["Theme"] = "dark"
return redirect(url_for("dash"))
@app.route("/admins")
def Admins():
if HasPrivilege(session["AccountId"]):
return render_template("admins.html", data=DashData(), session=session, title="Admins", config=UserConfig, admins=SplitList(GetStore()))
else:
return NoPerm(session)
@app.route("/changepass/<AccountID>", methods = ["GET", "POST"]) #may change the route to something within /user
def ChangePass(AccountID):
if HasPrivilege(session["AccountId"], 6): #may create separate perm for this
if request.method == "GET":
User = GetUser(int(AccountID))
return render_template("changepass.html", data=DashData(), session=session, title=f"Change the Password for {User['Username']}", config=UserConfig, User=User)
if request.method == "POST":
ChangePWForm(request.form, session)
User = GetUser(int(AccountID))
RAPLog(session["AccountId"], f"has changed the password of {User['Username']} ({AccountID}).")
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/donoraward/<AccountID>", methods = ["GET", "POST"])
def DonorAward(AccountID):
if HasPrivilege(session["AccountId"], 6):
if request.method == "GET":
User = GetUser(int(AccountID))
return render_template("donoraward.html", data=DashData(), session=session, title=f"Award Donor to {User['Username']}", config=UserConfig, User=User)
if request.method == "POST":
GiveSupporterForm(request.form)
User = GetUser(int(AccountID))
RAPLog(session["AccountId"], f"has awarded {User['Username']} ({AccountID}) {request.form['time']} months of donor.")
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/donorremove/<AccountID>")
def RemoveDonorRoute(AccountID):
if HasPrivilege(session["AccountId"], 6):
RemoveSupporter(AccountID, session)
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/rankreq/<Page>")
def RankReq(Page):
if HasPrivilege(session["AccountId"], 3):
return render_template("rankreq.html", data=DashData(), session=session, title="Ranking Requests", config=UserConfig, RankRequests = GetRankRequests(int(Page)), page = int(Page))
else:
return NoPerm(session)
@app.route("/clans/<Page>")
def ClanRoute(Page):
if HasPrivilege(session["AccountId"], 15):
return render_template("clansview.html", data=DashData(), session=session, title="Clans", config=UserConfig, page = int(Page), Clans = GetClans(Page), Pages = GetClanPages())
else:
return NoPerm(session)
@app.route("/clan/<ClanID>", methods = ["GET", "POST"])
def ClanEditRoute(ClanID):
if HasPrivilege(session["AccountId"], 15):
if request.method == "GET":
return render_template("editclan.html", data=DashData(), session=session, title="Clans", config=UserConfig, Clan=GetClan(ClanID), Members=SplitList(GetClanMembers(ClanID)), ClanOwner = GetClanOwner(ClanID))
ApplyClanEdit(request.form, session)
return render_template("editclan.html", data=DashData(), session=session, title="Clans", config=UserConfig, Clan=GetClan(ClanID), Members=SplitList(GetClanMembers(ClanID)), ClanOwner = GetClanOwner(ClanID), success="Clan edited successfully!")
else:
return NoPerm(session)
@app.route("/clan/delete/<ClanID>")
def ClanFinalDelete(ClanID):
if HasPrivilege(session["AccountId"], 15):
NukeClan(ClanID, session)
return redirect("/clans/1")
return NoPerm(session)
@app.route("/clan/confirmdelete/<ClanID>")
def ClanDeleteConfirm(ClanID):
if HasPrivilege(session["AccountId"], 15):
Clan = GetClan(ClanID)
return render_template("confirm.html", data=DashData(), session=session, title="Confirmation Required", config=UserConfig, action=f" delete the clan {Clan['Name']}", yeslink=f"/clan/delete/{ClanID}", backlink="/clans/1")
return NoPerm(session)
@app.route("/stats", methods = ["GET", "POST"])
def StatsRoute():
if HasPrivilege(session["AccountId"]):
MinPP = request.form.get("minpp", 0)
return render_template("stats.html", data=DashData(), session=session, title="Server Statistics", config=UserConfig, StatData = GetStatistics(MinPP), MinPP = MinPP)
return NoPerm(session)
#API for js
@app.route("/js/pp/<id>")
def PPApi(id):
try:
return jsonify({
"pp" : str(round(CalcPP(id), 2)),
"dtpp" : str(round(CalcPPDT(id), 2)),
"code" : 200
})
except:
return jsonify({"code" : 500})
#api mirrors
@app.route("/js/status/api")
def ApiStatus():
try:
return jsonify(requests.get(UserConfig["ServerURL"] + "api/v1/ping", verify=False).json())
except Exception as err:
print("[ERROR] /js/status/api: ", err)
return jsonify({
"code" : 503
})
@app.route("/js/status/lets")
def LetsStatus():
try:
return jsonify(requests.get(UserConfig["LetsAPI"] + "v1/status", verify=False).json()) #this url to provide a predictable result
except Exception as err:
print("[ERROR] /js/status/lets: ", err)
return jsonify({
"server_status" : 0
})
@app.route("/js/status/bancho")
def BanchoStatus():
try:
return jsonify(requests.get(UserConfig["BanchoURL"] + "api/v1/serverStatus", verify=False).json()) #this url to provide a predictable result
except Exception as err:
print("[ERROR] /js/status/bancho: ", err)
return jsonify({
"result" : 0
})
#actions
@app.route("/actions/wipe/<AccountID>")
def Wipe(AccountID: int):
"""The wipe action."""
if HasPrivilege(session["AccountId"], 11):
Account = GetUser(AccountID)
WipeAccount(AccountID)
RAPLog(session["AccountId"], f"has wiped the account {Account['Username']} ({AccountID})")
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/actions/wipeap/<AccountID>")
def WipeAPRoute(AccountID: int):
"""The wipe action."""
if HasPrivilege(session["AccountId"], 11):
Account = GetUser(AccountID)
WipeAutopilot(AccountID)
RAPLog(session["AccountId"], f"has wiped the autopilot statistics for the account {Account['Username']} ({AccountID})")
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/actions/wiperx/<AccountID>")
def WipeRXRoute(AccountID: int):
"""The wipe action."""
if HasPrivilege(session["AccountId"], 11):
Account = GetUser(AccountID)
WipeRelax(AccountID)
RAPLog(session["AccountId"], f"has wiped the relax statistics for the account {Account['Username']} ({AccountID})")
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/actions/wipeva/<AccountID>")
def WipeVARoute(AccountID: int):
"""The wipe action."""
if HasPrivilege(session["AccountId"], 11):
Account = GetUser(AccountID)
WipeVanilla(AccountID)
RAPLog(session["AccountId"], f"has wiped the vanilla statistics for the account {Account['Username']} ({AccountID})")
return redirect(f"/user/edit/{AccountID}")
else:
return NoPerm(session)
@app.route("/actions/restrict/<id>")
def Restrict(id: int):
"""The wipe action."""
if HasPrivilege(session["AccountId"], 6):
Account = GetUser(id)
if ResUnTrict(id):
RAPLog(session["AccountId"], f"has restricted the account {Account['Username']} ({id})")
else:
RAPLog(session["AccountId"], f"has unrestricted the account {Account['Username']} ({id})")
return redirect(f"/user/edit/{id}")
else:
return NoPerm(session)
@app.route("/actions/freeze/<id>")
def Freezee(id: int):
if HasPrivilege(session["AccountId"], 6):
Account = GetUser(id)
FreezeHandler(id)
RAPLog(session["AccountId"], f"has frozen the account {Account['Username']} ({id})")
return redirect(f"/user/edit/{id}")
else:
return NoPerm(session)
@app.route("/actions/ban/<id>")
def Ban(id: int):
"""Do the FBI to the person."""
if HasPrivilege(session["AccountId"], 5):
Account = GetUser(id)
if BanUser(id):
RAPLog(session["AccountId"], f"has banned the account {Account['Username']} ({id})")
else:
RAPLog(session["AccountId"], f"has unbanned the account {Account['Username']} ({id})")
return redirect(f"/user/edit/{id}")
else:
return NoPerm(session)
@app.route("/actions/hwid/<id>")
def HWID(id: int):
"""Clear HWID matches."""
if HasPrivilege(session["AccountId"], 6):
Account = GetUser(id)
ClearHWID(id)
RAPLog(session["AccountId"], f"has cleared the HWID matches for the account {Account['Username']} ({id})")
return redirect(f"/user/edit/{id}")
else:
return NoPerm(session)
@app.route("/actions/delete/<id>")
def DeleteAcc(id: int):
"""Account goes bye bye forever."""
if HasPrivilege(session["AccountId"], 6):
AccountToBeDeleted = GetUser(id)
DeleteAccount(id)
RAPLog(session["AccountId"], f"has deleted the account {AccountToBeDeleted['Username']} ({id})")
return redirect("/users/1")
else:
return NoPerm(session)
@app.route("/actions/kick/<id>")
def KickFromBancho(id: int):
"""Kick from bancho"""
if HasPrivilege(session["AccountId"], 12):
Account = GetUser(id)
BanchoKick(id, "You have been kicked by an admin!")
RAPLog(session["AccountId"], f"has kicked the account {Account['Username']} ({id})")
return redirect(f"/user/edit/{id}")
else:
return NoPerm(session)
@app.route("/actions/deletebadge/<id>")
def BadgeDeath(id:int):
if HasPrivilege(session["AccountId"], 4):
DeleteBadge(id)
RAPLog(session["AccountId"], f"deleted the badge with the ID of {id}")
return redirect(url_for("Badges"))
else:
return NoPerm(session)
@app.route("/actions/createbadge")
def CreateBadgeAction():
if HasPrivilege(session["AccountId"], 4):
Badge = CreateBadge()
RAPLog(session["AccountId"], f"Created a badge with the ID of {Badge}")
return redirect(f"/badge/edit/{Badge}")
else:
return NoPerm(session)
@app.route("/actions/createprivilege")
def CreatePrivilegeAction():
if HasPrivilege(session["AccountId"], 13):
PrivID = CreatePrivilege()
RAPLog(session["AccountId"], f"Created a new privilege group with the ID of {PrivID}")
return redirect(f"/privilege/edit/{PrivID}")
return NoPerm(session)
@app.route("/actions/deletepriv/<PrivID>")
def PrivDeath(PrivID:int):
if HasPrivilege(session["AccountId"], 13):
PrivData = GetPriv(PrivID)
DelPriv(PrivID)
RAPLog(session["AccountId"], f"deleted the privilege {PrivData['Name']} ({PrivData['Id']})")
return redirect(url_for("EditPrivileges"))
else:
return NoPerm(session)
@app.route("/action/rankset/<BeatmapSet>")
def RankSet(BeatmapSet: int):
if HasPrivilege(session["AccountId"], 3):
SetBMAPSetStatus(BeatmapSet, 2, session)
RAPLog(session["AccountId"], f"ranked the beatmap set {BeatmapSet}")
return redirect(f"/rank/{BeatmapSet}")
else:
return NoPerm(session)
@app.route("/action/loveset/<BeatmapSet>")
def LoveSet(BeatmapSet: int):
if HasPrivilege(session["AccountId"], 3):
SetBMAPSetStatus(BeatmapSet, 5, session)
RAPLog(session["AccountId"], f"loved the beatmap set {BeatmapSet}")
return redirect(f"/rank/{BeatmapSet}")
else:
return NoPerm(session)
@app.route("/action/unrankset/<BeatmapSet>")
def UnrankSet(BeatmapSet: int):
if HasPrivilege(session["AccountId"], 3):
SetBMAPSetStatus(BeatmapSet, 0, session)
RAPLog(session["AccountId"], f"unranked the beatmap set {BeatmapSet}")
return redirect(f"/rank/{BeatmapSet}")
else:
return NoPerm(session)
@app.route("/action/deleterankreq/<ReqID>")
def MarkRequestAsDone(ReqID):
if HasPrivilege(session["AccountId"], 3):
DeleteBmapReq(ReqID)
return redirect("/rankreq/1")
else:
return NoPerm(session)
@app.route("/action/kickclan/<AccountID>")
def KickClanRoute(AccountID):
if HasPrivilege(session["AccountId"], 15):
KickFromClan(AccountID)
return redirect("/clans/1")
return NoPerm(session)
#error handlers
@app.errorhandler(404)
def NotFoundError(error):
return render_template("404.html")
@app.errorhandler(500)
def BadCodeError(error):
ConsoleLog("Misc unhandled error!", f"{error}", 3)
return render_template("500.html")
#we make sure session exists
@app.before_request
def BeforeRequest():
if "LoggedIn" not in list(dict(session).keys()): #we checking if the session doesnt already exist
for x in list(ServSession.keys()):
session[x] = ServSession[x]
def NoPerm(session):
"""If not logged it, returns redirect to login. Else 403s. This is for convienience when page is reloaded after restart."""
if session["LoggedIn"]:
return render_template("403.html")
else:
return redirect("/login")
if __name__ == "__main__":
Thread(target=PlayerCountCollection, args=(True,)).start()
UpdateCachedStore()
app.run(host= '0.0.0.0', port=UserConfig["Port"])
handleUpdate() # handle update...