-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_content.mu
executable file
·136 lines (127 loc) · 6.6 KB
/
delete_content.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
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
#!/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">Do you really want to delete this {content_type}?\n")
if content_type == "post":
post_data = main.query_database(f"SELECT username, title, content, datetime(changed, 'unixepoch') FROM posts WHERE post_id = '{content_id}'")[0]
print('`F222`B999')
print(f"`!{post_data[1]}`!")
print("``")
if post_data[0] != "[DELETED]":
display_name = main.query_database(f"SELECT display_name FROM users WHERE username = '{post_data[0]}'")[0][0]
username_styled = f"{display_name} ``(`Ff22`_`[Profile`:{main.page_path}/profile.mu`username={post_data[0]}]`f`_)"
else:
username_styled = "[DELETED]"
print(f"{username_styled}: ({post_data[3]} (UTC))")
print("-")
print(f"{post_data[2]}")
print("``")
print(">")
elif content_type == "comment":
comment_data = main.query_database(f"SELECT username, content, datetime(changed, 'unixepoch'), post_id FROM comments WHERE comment_id = '{content_id}'")[0]
post_title = main.query_database(f"SELECT title FROM posts WHERE post_id = '{comment_data[3]}'")[0][0]
print(f">>Comment on {post_title}\n")
if comment_data[0] != "[DELETED]":
display_name = main.query_database(f"SELECT display_name FROM users WHERE username = '{comment_data[0]}'")[0][0]
username_styled = f"{display_name} ```B888(`Ff22`_`[Profile`:{main.page_path}/profile.mu`username={comment_data[0]}]`f`_)"
else:
username_styled = "[DELETED]"
print(">>>")
print(f"`B888{username_styled}: ({comment_data[2]} (UTC))")
print("``")
print(comment_data[1])
print("``")
print(">")
print()
main.execute_sql(f"DELETE FROM verification_codes WHERE use_type = 'delete_content' AND use_id = '{link_id}' AND username = '{username}'")
verification_code = main.get_verification_code()
main.execute_sql(f"INSERT INTO verification_codes (username, code, use_type, use_id, creation_time) VALUES ('{username}', '{main.encrypt(verification_code)}', 'delete_content', '{link_id}', unixepoch())")
print(f"Confirm this action by typing: '{verification_code}'")
print(f"Code: `B444`<8|confirmation`>`b `Ff22`_`[Confirm deletion`:{main.page_path}/delete_content.mu`*|type={content_type}|content_id={content_id}|confirm=yes|source_link_id={link_id}]`_`f")
try:
link_id, remote_identity = main.handle_ids()
main.print_header(link_id, reload=True)
content_type = ""
content_id = ""
confirmation = ""
confirm = False
for env_variable in os.environ:
if env_variable == "var_type":
content_type = os.environ[env_variable]
elif env_variable == "var_content_id":
content_id = os.environ[env_variable]
elif env_variable == "var_confirm" and os.environ[env_variable] == "yes":
confirm = True
elif env_variable == "field_confirmation":
confirmation = os.environ[env_variable]
query_result = main.query_database(f"SELECT username FROM users WHERE link_id = '{link_id}'")
if len(query_result) != 1:
print("please login first")
else:
username = query_result[0][0]
if (content_type == "post" or content_type == "comment") and main.check_uuid(content_id):
op_username = ""
if content_type == "post":
post_data = main.query_database(f"SELECT username FROM posts WHERE post_id = '{content_id}'")
if len(post_data) != 1:
print("content not found")
main.close_database(write_changes=False)
exit(0)
op_username = post_data[0][0]
elif content_type == "comment":
comment_data = main.query_database(f"SELECT username FROM comments WHERE comment_id = '{content_id}'")
if len(comment_data) != 1:
print("content not found")
main.close_database(write_changes=False)
exit(0)
op_username = comment_data[0][0]
if main.check_admin(link_id) or op_username == username:
if confirm and main.verify_link_id():
query_result = main.query_database(f"SELECT code FROM verification_codes WHERE use_type = 'delete_content' AND use_id = '{link_id}' AND username = '{username}'")
if len(query_result) != 1:
print(">Verification error\n")
print_fields()
main.close_database(write_changes=False)
exit(0)
else:
verification_code = main.decrypt(query_result[0][0])
if confirmation == verification_code:
main.execute_sql(f"DELETE FROM verification_codes WHERE use_type = 'delete_content' AND use_id = '{link_id}' AND username = '{username}'")
if content_type == "post":
main.execute_sql(f"DELETE FROM posts WHERE post_id = '{content_id}'")
main.execute_sql(f"DELETE FROM comments WHERE post_id = '{content_id}'")
main.execute_sql(f"DELETE FROM subscriptions WHERE post_id = '{content_id}'")
print(">The post was deleted")
print(f"`Ff22`_`[Continue`:{main.page_path}/index.mu]`_`f")
elif content_type == "comment":
main.delete_comment_chain([[content_id]])
print(">The comment was deleted")
print(f"`Ff22`_`[Continue`:{main.page_path}/index.mu]`_`f")
else:
print(">Verification error\n")
print_fields()
else:
print_fields()
else:
print(">Unauthorized!")
else:
print(">STOP INJECTING STUFF INTO THE FORUM!!!")
main.close_database()
except:
print("An error occured")