-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.py
221 lines (184 loc) · 10 KB
/
install.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
from hashlib import sha256
from json import dumps
from os import system, getuid
from platform import uname
from uuid import uuid1, uuid3
from argon2 import PasswordHasher
from pymysql import connect
def create_user():
token = str(uuid3(uuid1(), str(uuid1()))) # Génération d'un token unique
hashed_password = PasswordHasher().hash(password) # Hashage des mots de passe
# Création de l'utilisateur dans la base de données
cursor.execute("""INSERT INTO cantina_administration.user(token, username, password, email, admin)
VALUES (%s, %s, %s, %s, %s)""", (token, username, hashed_password, "", 1))
# Création des permissions de l'utilisateur dans la base de données
cursor.execute("""INSERT INTO cantina_administration.permission(user_token, show_log, edit_username, edit_email,
edit_password, edit_profile_picture, edit_A2F, edit_ergo, show_specific_account, edit_username_admin,
edit_email_admin, edit_password_admin, edit_profile_picture_admin, allow_edit_username, allow_edit_email,
allow_edit_password, allow_edit_profile_picture, allow_edit_A2F, create_user, delete_account, desactivate_account,
edit_permission, show_all_modules, on_off_modules, on_off_maintenance, delete_modules, add_modules,
edit_name_module, edit_url_module, edit_socket_url, edit_smtp_config) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s)""",
(token, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
con.commit()
return token
def create_config():
token = str(uuid3(uuid1(), str(uuid1()))) # Génération d'un token unique
secret_token = sha256(PasswordHasher().hash(token).encode())
cursor.execute("""INSERT INTO cantina_administration.config(name, content) VALUES (%s, %s)""",
("secret_token", secret_token))
perm_list = ["edit_username", "edit_password", "edit_email", "edit_profile_picture", "edit_a2f", "SMTP_URL",
"SMTP_PORT", "SMTP_EMAIL", "SMTP_PASSWORD", "MAIL_VERIFICATION_SUJET", "MAIL_VERIFICATION_CONTENU"]
for element in perm_list:
cursor.execute("""INSERT INTO cantina_administration.config(name, content) VALUES (%s, %s)""",
(element, 0))
CRED = '\033[91m'
CEND = '\033[0m'
CWAR = '\033[93m'
based_on = None
os_info = uname()
database = [False, False]
ph = PasswordHasher()
if getuid() != 0:
exit("L'installation doit être faite avec les permissions d'administrateur!")
elif os_info.system != "Linux":
exit("L'installation doit être faire sur une système linux!")
print("Bienvenue dans l'installation de Cantina Olympe!")
if "Debian" in os_info.version:
print("Système Debian détecté.")
system("sudo adduser cantina --system")
system("sudo addgroup cantina")
system("sudo apt install python3-venv")
else:
distrib_check = input(
"Votre système est:\n 1: Basé sur Debian\n 2: Basé sur Arch\n 3: Basé sur Red Hat\n")
while distrib_check not in ["1", "2", "3"]:
print("Merci de répondre uniquement par 1, 2 ou 3!")
distrib_check = input(
"Votre système est:\n 1: Basé sur Debian\n 2: Basé sur Arch\n 3: Basé sur Red Hat\n")
if distrib_check == "1" or distrib_check == "3":
system("sudo adduser cantina --system")
system("sudo addgroup cantina")
elif distrib_check == "2":
system("sudo useradd cantina")
system("sudo groupadd cantina")
else:
exit("Vous avez cassé notre système :/")
system("sudo usermod -a -G cantina cantina")
system("git clone https://github.com/Cantina-Org/Olympe /home/cantina/Olympe")
system("python3 -m venv /home/cantina/Olympe/venv")
system('/home/cantina/Olympe/venv/bin/pip install -r /home/cantina/Olympe/requirements.txt')
system('sudo mkdir /home/cantina/Olympe/static/ProfilePicture')
print(CRED +
"----------------------------------------------------------------------------------------------------------------"
"--------------------------------------------------------" + CEND
)
print("Identifiants de connexion aux bases de données: ")
database_username = input(" Nom d'utilisateur: ")
database_password = input(" Mots de passe: ")
database_host = input(" Adresse: ")
database_port = input(" Port: ")
while database_password == '' or database_username == '' or database_host == '' or database_port == '':
print("Merci de rentrer des valeurs!")
database_username = input(" Nom d'utilisateur: ")
database_password = input(" Mots de passe: ")
database_host = input(" Adresse: ")
database_port = input(" Port: ")
try:
con = connect(user=database_username, password=database_password, host=database_host, port=int(database_port))
cursor = con.cursor()
except Exception as e:
exit("Un problème est survenue lors de la connexion à Mariadb: " + str(e))
cursor.execute("""SHOW DATABASES""")
data = cursor.fetchall()
for i in data:
if i[0] == 'cantina_administration':
database[0] = True
if not database[0]:
cursor.execute("CREATE DATABASE cantina_administration")
cursor.execute("USE cantina_administration")
cursor.execute("""CREATE TABLE IF NOT EXISTS cantina_administration.user(id INT PRIMARY KEY AUTO_INCREMENT,
token TEXT NOT NULL, username TEXT NOT NULL, password TEXT NOT NULL, email TEXT NOT NULL,
picture BOOL DEFAULT false, email_verified BOOL DEFAULT FALSE, email_verification_code TEXT,
A2F BOOL DEFAULT FALSE, A2F_secret TEXT, last_connection DATE, admin BOOL DEFAULT FALSE,
desactivated BOOL DEFAULT FALSE, theme TEXT DEFAULT 'white')""", None)
cursor.execute("""CREATE TABLE IF NOT EXISTS cantina_administration.config(id INT PRIMARY KEY AUTO_INCREMENT,
name TEXT, content TEXT)""", None)
cursor.execute("""CREATE TABLE IF NOT EXISTS cantina_administration.modules(id INT PRIMARY KEY AUTO_INCREMENT,
token TEXT, name TEXT, fqdn TEXT, maintenance BOOL default FALSE, status INTEGER DEFAULT 0,
socket_url TEXT DEFAULT '/socket/')""", None)
cursor.execute("""CREATE TABLE IF NOT EXISTS cantina_administration.permission(id INT PRIMARY KEY AUTO_INCREMENT,
user_token TEXT NOT NULL, show_log BOOL DEFAULT FALSE, edit_username BOOL DEFAULT FALSE, edit_email BOOL DEFAULT FALSE,
edit_password BOOL DEFAULT FALSE, edit_profile_picture BOOL DEFAULT FALSE, edit_A2F BOOL DEFAULT FALSE,
edit_ergo BOOL DEFAULT FALSE, show_specific_account BOOL DEFAULT FALSE, edit_username_admin BOOL DEFAULT FALSE,
edit_email_admin BOOL DEFAULT FALSE, edit_password_admin BOOL DEFAULT FALSE,
edit_profile_picture_admin BOOl DEFAULT FALSE, allow_edit_username BOOL DEFAULT FALSE,
allow_edit_email BOOL DEFAULT FALSE, allow_edit_password BOOL DEFAULT FALSE,
allow_edit_profile_picture BOOL DEFAULT FALSE, allow_edit_A2F BOOL DEFAULT FALSE, create_user BOOL DEFAULT FALSE,
delete_account BOOL DEFAULT FALSE, desactivate_account BOOL DEFAULT FALSE, edit_permission BOOL DEFAULT FALSE,
show_all_modules BOOL DEFAULT FALSE, on_off_modules BOOL DEFAULT FALSE, on_off_maintenance BOOL DEFAULT FALSE,
delete_modules BOOL DEFAULT FALSE, add_modules BOOL DEFAULT FALSE, edit_name_module BOOL DEFAULT FALSE,
edit_url_module BOOL DEFAULT FALSE, edit_socket_url BOOL DEFAULT FALSE, edit_smtp_config BOOL DEFAULT FALSE)""", None)
cursor.execute("""CREATE TABLE IF NOT EXISTS cantina_administration.log(id INT PRIMARY KEY AUTO_INCREMENT,
action_name TEXT, user_ip TEXT, user_token TEXT, details TEXT, log_level INT)""", None)
print("Nous allons donc créer un premier compte administrateur.")
username = input(" Nom d'utilisateur: ")
password = input(" Mots de passe: ")
email = input(" Email: ")
create_user()
create_config()
print(CRED +
"----------------------------------------------------------------------------------------------------------------"
"--------------------------------------------------------" + CEND
)
con.commit()
print(CRED +
"----------------------------------------------------------------------------------------------------------------"
"--------------------------------------------------------" + CEND
)
print("Sur quel port local souhaitez-vous utiliser Cantina Olympe ?")
port = input("Port : ")
print("Sur quel domaine internet souhaitez-vous utiliser Cantina Olympe ?")
domain = input("Domaine internet : ")
print(CRED +
"----------------------------------------------------------------------------------------------------------------"
"--------------------------------------------------------" + CEND
)
cursor.execute('''INSERT INTO cantina_administration.modules(token, name, fqdn) VALUES (%s, 'olympe', %s)''',
(str(uuid3(uuid1(), str(uuid1()))), domain))
con.commit()
json_data = {
"database": [{
"username": database_username,
"password": database_password,
"address": database_host,
"port": int(database_port)
}],
"modules": [{
"name": "olympe",
"port": port,
"maintenance": False,
"debug_mode": False
}]
}
with open("/home/cantina/Olympe/config.json", "w") as outfile:
outfile.write(dumps(json_data, indent=4))
launch_startup = input("Voullez vous lancez Cantina Olympe au lancement de votre serveur? ")
system("touch /etc/systemd/system/cantina_olympe.service")
system(f"""echo '[Unit]
Description=Cantina Olympe
[Service]
User=cantina
WorkingDirectory=/home/cantina/Olympe
ExecStart=/home/cantina/Olympe/venv/bin/python app.py
[Install]
WantedBy=multi-user.target' >> /etc/systemd/system/cantina_olympe.service""")
system('chown cantina:cantina /home/cantina/*/*/*')
system("systemctl enable cantina_olympe")
system("systemctl start cantina_olympe")
print(CRED +
"----------------------------------------------------------------------------------------------------------------"
"--------------------------------------------------------" + CEND
)
print("Nous venons de finir l'instalation de Cantina! Vous pouvez maintenant configurer votre serveur web pour qu'il " +
f"pointe sur l'ip 127.0.0.1:{port}!")