-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.php
executable file
·184 lines (147 loc) · 5.03 KB
/
remove.php
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
<?php session_start();
include "core.php";
include "config.php";
$id = -1;
$History = "false";
$Request = "false";
$Redirect = "";
$AuthorizedCreation = 0;
if (isset($_REQUEST['redir'])) {
$Redirect = htmlspecialchars($_REQUEST['redir']);
}
if (isset($_REQUEST['history'])) {
$History = htmlspecialchars($_REQUEST['history']);
}
if (isset($_REQUEST['request'])) {
$Request = htmlspecialchars($_REQUEST['request']);
}
if (isset($_REQUEST['id'])) {
$id = htmlspecialchars($_REQUEST['id']);
} else {
if ($Redirect == "admin") {
header("Location: admin.php?e=endpoint");
} else if ($Redirect == "edit") {
header("Location: edit.php?e=endpoint&action=articles");
} else {
header("Location: /");
}
die();
}
$Database = createTables($sqlDB);
$DatabaseQuery = $Database->query('SELECT * FROM users');
if (!isset($_SESSION['username']) || !isset($_SESSION['password']) || !isset($_SESSION['type'])) {
header('Location: login.php?redir=admin');
die();
} else if (htmlspecialchars($_SESSION['type']) != 2) { // not allowed
header('Location: /');
die();
}
$DatabaseQuery = $Database->query('SELECT * FROM users');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['username'] == htmlspecialchars($_SESSION['username']) && htmlspecialchars($_SESSION['username']) != "" && $line['password'] == htmlspecialchars($_SESSION['password']) && $line['usertype'] == 2) {
$AuthorizedCreation = 1;
break;
}
}
$Username = htmlspecialchars($_SESSION['username']);
// not authorized
if ($AuthorizedCreation != 1) {
header('Location: /');
die();
}
if ($History == "false" && $Request == "false") {
$DatabaseQuery = $Database->query('SELECT * FROM pages');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['id'] == $id && $id != -1) {
$File = $line['file'];
$Directory = dirname($File);
if (is_file($File)) {
unlink($File);
if (is_dir($Directory)) {
rmdir($Directory);
}
}
$Database->exec("DELETE FROM pages WHERE id='$id'");
// also delete requests
$ModDatabaseQuery = $Database->query('SELECT * FROM requests');
while ($mline = $ModDatabaseQuery->fetchArray()) {
if ($mline['pageid'] == $id && $id != -1) {
$File = $mline['file'];
$Directory = dirname($File);
if (is_file($File)) {
unlink($File);
if (is_dir($Directory)) {
rmdir($Directory);
}
}
$Database->exec("DELETE FROM requests WHERE pageid='$id'");
break;
}
}
// also delete history
$HistDatabaseQuery = $Database->query('SELECT * FROM history');
while ($hline = $HistDatabaseQuery->fetchArray()) {
if ($hline['pageid'] == $id && $id != -1) {
$File = $hline['file'];
$Directory = dirname($File);
if (is_file($File)) {
unlink($File);
if (is_dir($Directory)) {
rmdir($Directory);
}
}
$Database->exec("DELETE FROM history WHERE pageid='$id'");
break;
}
}
break;
}
}
} else if ($Request == "true") {
$DatabaseQuery = $Database->query('SELECT * FROM requests');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['id'] == $id && $id != -1) {
$File = $line['file'];
$Directory = dirname($File);
if (is_file($File)) {
unlink($File);
if (is_dir($Directory)) {
rmdir($Directory);
}
}
$Database->exec("DELETE FROM requests WHERE id='$id'");
break;
}
}
} else if ($History == "true") {
$DatabaseQuery = $Database->query('SELECT * FROM history');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['id'] == $id && $id != -1) {
$File = $line['file'];
$Directory = dirname($File);
if (is_file($File)) {
unlink($File);
if (is_dir($Directory)) {
rmdir($Directory);
}
}
$Database->exec("DELETE FROM history WHERE id='$id'");
break;
}
}
}
if ($Redirect == "admin") {
header("Location: admin.php?action=users");
} else if ($Redirect == "edit") {
if ($History == "true") {
header("Location: edit.php?action=history&id=$id");
} else if ($Request == "true") {
header("Location: edit.php?action=requests&id=$id");
} else {
header("Location: edit.php?action=articles");
}
} else {
header("Location: /");
}
die();
?>