-
Notifications
You must be signed in to change notification settings - Fork 0
/
logout.mu
executable file
·58 lines (49 loc) · 2.45 KB
/
logout.mu
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
#!/usr/bin/env python3
# nomadForum - a forum on the NomadNetwork
# Copyright (C) 2023-2024 AutumnSpark1226
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import main
def print_fields():
print(f"`Ff22`_`[Logout`:{main.page_path}/logout.mu`confirm=yes|source_link_id={link_id}]`_`f")
try:
link_id, remote_identity = main.handle_ids()
main.print_header(link_id, reload=True)
confirm = ""
for env_variable in os.environ:
if env_variable == "var_confirm":
confirm = os.environ[env_variable]
if len(main.query_database(f"SELECT user_id FROM users WHERE link_id = '{link_id}'")) == 0:
print("\n>You are not logged in.")
elif confirm != "yes":
print_fields()
elif confirm == "yes" and main.verify_link_id():
username = main.query_database(f"SELECT username FROM users WHERE link_id = '{link_id}'")[0][0]
if main.decrypt(main.query_database(f"SELECT password FROM users WHERE username = '{username}'")[0][0]) != "$nopassword$":
main.execute_sql(f"UPDATE users SET link_id = '0', login_time = 0 WHERE link_id = '{link_id}'")
if remote_identity != "":
query_results = main.query_database(f"SELECT remote_id, conn_id FROM connections WHERE allow_login = 1 AND username = '{username}'")
for data in query_results:
if main.decrypt(data[0]) == remote_identity:
main.execute_sql(f"UPDATE connections SET allow_login = 0 WHERE conn_id = {data[1]} AND allow_login = 1 AND username = '{username}'")
print(">Logged out")
else:
print(">Can't log out. You have set no password.")
print()
# submit a dummy value in order to force a reload
print(f"`Ff22`_`[Continue`:{main.page_path}/index.mu`reload=62323]`_`f")
main.close_database()
except:
print("An error occured")