-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
129 lines (105 loc) · 3.46 KB
/
setup.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
from flask import Flask, render_template, redirect, request
import mysql.connector
app = Flask(__name__)
@app.route("/")
def welcome():
return render_template("setup_welcome.html")
@app.route("/setup", methods=['GET', 'POST'])
def setup_1():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
host = request.form['host']
mydb = mysql.connector.connect(
host=host,
user=username,
password=password
)
if mydb:
f = open("various/db.txt", "w")
f.write(username+"\n"+password+"\n"+host)
f.close()
mydb = mysql.connector.connect(
host=host,
user=username,
password=password
)
mycursor = mydb.cursor()
mycursor.execute("CREATE DATABASE tess")
return redirect('/setup2')
else:
return redirect('/setup')
return render_template("setup_1.html")
@app.route("/setup2", methods=['GET', 'POST'])
def setup2():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
f = open("various/db.txt", "r")
db_user = f.readline().rstrip("\n")
db_pass = f.readline().rstrip("\n")
db_host = f.readline().rstrip("\n")
f.close()
print(db_host, db_pass, db_user)
mydb = mysql.connector.connect(
host=db_host,
user=db_user,
password=db_pass,
database="tess"
)
mycursor = mydb.cursor()
mycursor.execute("CREATE TABLE userdata (user VARCHAR(255), pass VARCHAR(255))")
mydb = mysql.connector.connect(
host=db_host,
user=db_user,
password=db_pass,
database="tess"
)
mycursor = mydb.cursor()
sql = "INSERT INTO userdata (user, pass) VALUES (%s, %s)"
val = (username, password)
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
mydb = mysql.connector.connect(
host=db_host,
user=db_user,
password=db_pass,
database="tess"
)
mycursor = mydb.cursor()
sett = "CREATE TABLE ",username," (setting VARCHAR(255), value VARCHAR(255))"
mycursor.execute(sett)
mydb = mysql.connector.connect(
host=db_host,
user=db_user,
password=db_pass,
database="tess"
)
mycursor = mydb.cursor()
sett = "INSERT INTO ",username," (setting, value) VALUES (%s, %s)"
sql = sett
val = ("theme", "dark")
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
mydb = mysql.connector.connect(
host=db_host,
user=db_user,
password=db_pass,
database="tess"
)
mycursor = mydb.cursor()
sett = "INSERT INTO ", username, " (setting, value) VALUES (%s, %s)"
sql = sett
val = ("role", "admin")
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "record inserted.")
return redirect("/setup3")
return render_template("setup_2.html")
@app.route("/setup3")
def setup3():
return render_template("setup_3.html")
if __name__ == "__main__":
app.run(debug=True)