forked from MTOSCentral/Sunflower
/
server.py
442 lines (430 loc) · 16.7 KB
/
server.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
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
#Meow Tech Codenamed 'Central' (SE) Web Edition v1
#Meow Tech Codenamed Central Beta 1.5
#Project Name:Central
#State:Beta 1.5 -> Release Canidate
import json
from flask import Flask, redirect, url_for, render_template, request,session,flash
import sqlite3
from datetime import datetime
from api.api import apimodule
from werkzeug.utils import append_slash_redirect
from hashing import Hashing
import random
import string
import base64
from passwordencryption import EncryptPass
from datetime import datetime
from datetime import timedelta
from oobe.oobe import oobeui
from werkzeug.utils import secure_filename
brandinfo={}
conn =sqlite3.connect('database\\users.sql', check_same_thread=False)
cursor = conn.cursor()
#Session Id Layout{"Public ID":"Private ID"}
sessionid={}
DEBUG=False
with open("branding\\branding.json") as file:
brandinfo = json.load(file)
productname = brandinfo["Vendor"]+" "+brandinfo["ProductName"]
lc=brandinfo["License"]
print(productname)
file.close()
with open("lang\\en-US.json",encoding="utf-8") as file:
lang = json.load(file)
file.close()
with open(lc,encoding="utf-8") as file:
license1=file.readlines()
file.close()
app = Flask(__name__)
app.register_blueprint(apimodule, url_prefix="/api")
app.register_blueprint(oobeui, url_prefix="/oobe")
app.secret_key="ThEMoSTSeCuRePassWORdINThEWorLD"
year = datetime.now().strftime('%Y')
app.permanent_session_lifetime = timedelta(days=10)
build="0110"
branch="centralbeta1_5.210906"
fullbuildname=build+"."+branch
hasher=Hashing()
@app.route('/license')
def license():
return render_template("nano/license.html",productname=productname,year=year,license=license1)
def gensession():
global session
global sessionid
letters = string.ascii_letters
letters=letters+string.digits
pri = ''.join(random.choice(letters) for i in range(128))
pub = ''.join(random.choice(letters) for i in range(128))
sessionid[pub]=pri
session["sessionid"]=pub
def regen():
letters = string.ascii_letters
letters=letters+string.digits
#print("1st"+str(sessionid))
pri = ''.join(random.choice(letters) for i in range(128))
sessionid[session["sessionid"]]=pri
#print("2nd"+str(sessionid))
def chklogin(user,pw):
global conn
cor=False
if "a" == "a":
hasher=Hashing()
session.permanent = True
user = user
passwd = pw
sqlstr='select * from users'
cur=conn.execute(sqlstr)
rows=cur.fetchall()
#print(rows)
#print(rows[5][0])
for row in rows:
#print('!')
if hasher.check(passwd,row[1]) and user == row[0]:
#session["user"] = user
#session["role"] = row[2]
#gensession()
cor=True
return [True,user,row[2]]
#else:
#pass
if not cor:
return [False,0]
@app.route("/login", methods=["POST", "GET"])
def login():
global conn
stmt = """SELECT count(*) FROM sqlite_master WHERE type='table' AND name='users';"""
cur=conn.execute(stmt)
result = cur.fetchone()
if 1+1 !=2:
pass
#if result[0] == 0:
#flash("Your Server Haven't Been Setup Yet.")
#return redirect(url_for("oobe.start"))
else:
#print(chklogin("a","a"))
cor=False
if request.method == "POST":
hasher=Hashing()
session.permanent = True
user = request.form["nm"]
passwd = request.form["pass"]
sqlstr='select * from users'
tmp=conn.execute(sqlstr)
#print(tmp)
rows=tmp.fetchall()
#print(rows)
#print(rows[5][0])
for row in rows:
#print('!')
if hasher.check(passwd,row[1]) and user == row[0]:
if user == "" or passwd=="":
flash(lang["msg12"])
return redirect(url_for("login"))
else:
session["user"] = user
session["role"] = row[2]
gensession()
cor=True
flash(lang["msg2"])
return redirect(url_for("home"))
#else:
#pass
if not cor:
flash(lang["msg1"])
return redirect(url_for("login"))
else:
if "role" in session:
user = session["user"]
flash(lang["msg3"])
return redirect(url_for("home"))
else:
return render_template("nano/login.html",productname=productname,year=year)
@app.route('/')
def home():
if "user" in session:
return render_template("nano/home.html",buildno=fullbuildname,productname=productname,year=year)
else:
flash(lang['msg5'])
return(redirect(url_for("login")))
@app.route('/logout')
def logout():
if "user" in session:
session.pop("user")
session.pop("role")
if "sessionid" in session:
session.pop("sessionid")
if "step" in session:
session.pop("step")
if "add" in session:
session.pop("add")
if "child" in session:
session.pop("child")
if "cm" in session:
session.pop("cm")
flash(lang["msg4"])
return redirect(url_for("login"))
else:
flash(lang["msg5"])
return redirect(url_for("login"))
def chkroleloggedin(role):
if 'sessionid' not in session:
return '!!'
elif session['sessionid'] not in sessionid:
return "!!"
elif 'role' not in session:
return "!!"
elif role==None:
return True
elif session['role'] == role:
return True
else:
return False
###RTM REMOVE THIS!!!!
@app.route('/dbg')
def debugmode():
global DEBUG
if DEBUG:
if chkroleloggedin(None) == "!!":
return redirect(url_for("logout"))
else:
return sessionid[session["sessionid"]]
else:
flash("Error!You T")
return redirect(url_for("home"))
def popadds():
if "add" in session:
session.pop("add")
if "child" in session:
session.pop("child")
if "step" in session:
session.pop("step")
if "cm" in session:
session.pop("cm")
@app.route('/addmoney', methods=["POST", "GET"])
def addmoney():
role=chkroleloggedin('adult')
if request.method=="POST":
if role != "!!":
if role:
child=request.form["child"]
sqlstr='select * from users'
cur=conn.execute(sqlstr)
rows=cur.fetchall()
nowdollar="D"
for row in rows:
# print('RAN USER='+session['user'])
if row[0] == child and row[2]=="child":
#print(row[3])
#print("--------")
nowdollar=row[3]
#print(nowdollar)
if nowdollar == "D":
flash("The child account you entered either is not an valid account or is not a child.")
return redirect(url_for("addmoney"))
else:
enckey=EncryptPass()
addmoney1=request.form["dollars"]
session["add"]=enckey.encrypt(sessionid[session["sessionid"]],str(addmoney1))
session["child"]=enckey.encrypt(sessionid[session["sessionid"]],child)
session["cm"]=enckey.encrypt(sessionid[session["sessionid"]],nowdollar)
#print(session["add"])
#flash("Success!")
return redirect(url_for("add_now"))
else:
flash(lang["msg6"])
return redirect(url_for("home"))
else:
return redirect(url_for("logout"))
else:
if role != "!!":
return render_template("nano/add.html",productname=productname,year=year)
else:
flash(lang["msg7"])
return redirect(url_for("logout"))
@app.route('/add_now',methods=["POST", "GET"])
def add_now():
#Add Now!
if request.method == "POST":
if "add" in session and "child" in session and "cm" in session:
#session["add"]
if chkroleloggedin(None) == "!!":
return redirect(url_for("logout"))
else:
chklogin1=chklogin(request.form['nm'],request.form['pass'])
if chklogin1[0]:
if chklogin1[2] == "adult":
#PREP THE COMMAND
enckey=EncryptPass()
child=enckey.decrypt(sessionid[session["sessionid"]],session["child"])
adder=enckey.decrypt(sessionid[session["sessionid"]],session["add"])
nowdollar=enckey.decrypt(sessionid[session["sessionid"]],session["cm"])
session.pop("child")
session.pop("add")
session.pop("cm")
cmd='UPDATE users SET "Money" = "'+str(int(nowdollar)+int(adder))+'" WHERE Name="'+child+'"'
curs = conn.cursor()
curs.execute(cmd)
conn.commit()
#Remake KEY
#History Module
#Coming Soon :>
regen()
flash(lang["success"])
return redirect(url_for("home"))
else:
popadds()
flash(lang["msg1"]+"/"+lang["msg8"])
return redirect(url_for("home"))
else:
return redirect(url_for("addmoney"))
else:
#Get
if "add" in session and "child" in session and "cm" in session:
flash(lang["msg9"])
return render_template("nano/login.html",productname=productname,year=year)
else:
flash(lang["msg10"])
return redirect(url_for("logout"))
@app.route('/removemoney', methods=["POST", "GET"])
def removemoney():
role=chkroleloggedin('adult')
if request.method=="POST":
if role != "!!":
if role:
child=request.form["child"]
sqlstr='select * from users'
cur=conn.execute(sqlstr)
rows=cur.fetchall()
nowdollar="D"
for row in rows:
#print('RAN USER='+session['user'])
if row[0] == child and row[2]=="child":
print(row[3])
nowdollar=row[3]
if nowdollar == "D":
flash("The child account you entered either is not an valid account or is not a child.")
return redirect(url_for("addmoney"))
else:
enckey=EncryptPass()
addmoney1=request.form["dollars"]
session["add"]=enckey.encrypt(sessionid[session["sessionid"]],str(addmoney1))
session["child"]=enckey.encrypt(sessionid[session["sessionid"]],child)
session["cm"]=enckey.encrypt(sessionid[session["sessionid"]],str(nowdollar))
session["step"]=enckey.encrypt(sessionid[session["sessionid"]],'1')
print(session["add"])
#return 'Added Money Now!'
flash(lang["success"])
return redirect(url_for("remove_now"))
else:
flash(lang["msg6"])
return redirect(url_for("home"))
else:
return redirect(url_for("logout"))
else:
if role != "!!":
return render_template("nano/add.html",productname=productname,year=year)
else:
flash(lang["msg7"])
return redirect(url_for("logout"))
@app.route('/remove_now',methods=["POST", "GET"])
def remove_now():
#Remove Now!
if request.method == "POST":
if "add" in session and "child" in session and "cm" in session and "step" in session:
#session["add"]
if chkroleloggedin(None) == "!!":
flash(lang["msg5"])
return redirect(url_for("logout"))
enckey=EncryptPass()
if enckey.decrypt(sessionid[session["sessionid"]],session["step"]) !="1":
return redirect(url_for('removemoney'))
else:
chklogin1=chklogin(request.form['nm'],request.form['pass'])
if chklogin1[0]:
if chklogin1[2] == "adult":
#PREP THE COMMAND
session["step"]=enckey.encrypt(sessionid[session["sessionid"]],'2')
#child=enckey.decrypt(sessionid[session["sessionid"]],session["child"])
#adder=enckey.decrypt(sessionid[session["sessionid"]],session["add"])
#nowdollar=enckey.decrypt(sessionid[session["sessionid"]],session["cm"])
#session.pop("child")
#session.pop("add")
#session.pop("cm")
#Remake KEY
#History Module
#Coming Soon :>
return redirect(url_for("remove_now2"))
#return "Hurray:>:>:<:>:<:>:<>"
else:
flash(lang["msg6"])
return redirect(url_for("home"))
else:
return redirect(url_for("removemoney"))
else:
if "add" in session and "child" in session and "cm" in session and "step" in session:
flash(lang["msg9"])
return render_template("nano/login.html",productname=productname,year=year)
else:
flash(lang["msg10"])
return redirect(url_for("logout"))
@app.route('/remove_now2',methods=["POST", "GET"])
def remove_now2():
#Remove Now!
if request.method == "POST":
if "add" in session and "child" in session and "cm" in session:
#session["add"]
if chkroleloggedin(None) == "!!":
return redirect(url_for("logout"))
enckey=EncryptPass()
if enckey.decrypt(sessionid[session["sessionid"]],session["step"]) !="2":
return redirect(url_for('removemoney'))
else:
chklogin1=chklogin(request.form['nm'],request.form['pass'])
if chklogin1[0]:
if chklogin1[2] == "child" and request.form['nm'] == enckey.decrypt(sessionid[session["sessionid"]],session["child"]):
#PREP THE COMMAND
#enckey=EncryptPass()
child=enckey.decrypt(sessionid[session["sessionid"]],session["child"])
adder=enckey.decrypt(sessionid[session["sessionid"]],session["add"])
nowdollar=enckey.decrypt(sessionid[session["sessionid"]],session["cm"])
popadds()
#Remake KEY
regen()
cmd='UPDATE users SET "Money" = "'+str(int(nowdollar)-int(adder))+'" WHERE Name="'+child+'"'
curs = conn.cursor()
curs.execute(cmd)
conn.commit()
#History Module
#Coming Soon :>
flash(lang["success"])
return redirect(url_for("home"))
else:
flash(lang["msg1"]+"/"+lang["msg8"]+"/ Your User is not the specified user.")
popadds()
return redirect(url_for("home"))
else:
flash("Unknown Error.")
popadds()
return redirect(url_for("removemoney"))
else:
if "add" in session and "child" in session and "cm" in session and "step" in session:
flash(lang["msg11"])
return render_template("nano/login.html",productname=productname,year=year)
else:
flash(lang["msg10"])
popadds()
return redirect(url_for("logout"))
#Load Modular Components
if __name__ == "__main__":
app.run(port=8888, debug=True,host="0.0.0.0")
# End Of Code - Meow Tech Codenamed Central
# Thanks For Using Meow Tech Codenamed Central
#Remarks:
"""
This Project Is Licensed Under The EPL (Eclipse Public License)
A copy of the license (license.txt) is included with the source code.
Copyright (c) Meow Tech Open Source 2020-2021, all rights reserved
DISCLAMER:DO NOT MODIFIY THE COPYRIGHT NOTICE IN THIS PART OF THE SOURCE CODE.
Note:Bootstrap Is Licensed Under MIT license.
"""
#Release Canidate Is Coming Soon.......