-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin-forumbans.php
314 lines (272 loc) · 9.15 KB
/
admin-forumbans.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
require 'lib/function.php';
$_GET['forum'] = filter_int($_GET['forum']);
$_GET['edit'] = filter_int($_GET['edit']);
// Process edit actions right away
if ($_GET['forum']) {
// Make sure the forum is valid (and that we have access to it)
$forum = $sql->fetchq("SELECT id, title, minpower FROM forums WHERE id = {$_GET['forum']}");
if (!$forum || ($forum['minpower'] && $loguser['powerlevel'] < $forum['minpower'])) {
errorpage("Couldn't access the forum. Either it doesn't exist or you don't have access to it.", 'index.php', 'the index page', 0);
}
$ismod = $ismod || $sql->resultq("SELECT 1 FROM forummods WHERE forum = {$_GET['forum']} and user = {$loguser['id']}");
if (isset($_POST['dodel'])) {
// Delete (multiple) bans
check_token($_POST['auth']);
if (!$ismod) {
errorpage("You aren't allowed to edit this forum's bans.");
}
// Make sure we're deleting forum bans off the correct forum
if (!empty($_POST['delban'])){
$del = $sql->prepare("DELETE FROM forumbans WHERE id = ? AND forum = {$_GET['forum']}");
foreach ($_POST['delban'] as $ban) {
$sql->execute($del, [$ban]);
}
}
return header("Location: ?forum={$_GET['forum']}");
} else if (isset($_POST['save'])) {
// Create / Edit a ban
check_token($_POST['auth']);
if (!$ismod) {
errorpage("You aren't allowed to edit this forum's bans.");
}
if ($_GET['edit'] != -1) {
$data = $sql->fetchq("SELECT * FROM forumbans WHERE id = {$_GET['edit']}");
if (!$data) {
errorpage("You're trying to edit a nonexisting ban or the selected ban has already expired.");
}
}
$_POST['user'] = filter_int($_POST['user']);
$_POST['expire'] = filter_int($_POST['expire']);
$_POST['reason'] = filter_string($_POST['reason']);
$user = $sql->fetchq("SELECT name, powerlevel FROM users WHERE id = {$_POST['user']}");
if (!$user) {
errorpage("This user doesn't exist.");
} else if ($user['powerlevel'] >= 2) {
errorpage("uh no");
}
// All OK!
if ($_GET['edit'] == -1) {
$ircreason = $_POST['reason'] ? " for the following reason: {$_POST['reason']}" : "";
$ircmessage = xk(8) . $loguser['name'] . xk(7) ." added forum ban for ". xk(8) . $user['name'] . xk(7) ." in ". xk(8) . $forum['title'] . xk(7) . $ircreason .".";;
forumban($_GET['forum'], $_POST['user'], $_POST['reason'], $ircmessage, IRC_STAFF, $_POST['expire'], $loguser['id']);
} else {
$values = array(
'user' => $_POST['user'],
'expire' => ctime() + 3600 * $_POST['expire'],
'reason' => $_POST['reason'],
);
$sql->queryp("UPDATE forumbans SET ".mysql::setplaceholders($values)." WHERE id = {$_GET['edit']}", $values);
xk_ircsend(IRC_STAFF."|". xk(8) . $loguser['name'] . xk(7) ." updated the forum ban for ". xk(8) . $user['name'] . xk(7) ." in ". xk(8) . $forum['title'] . xk(7) .".");
}
return header("Location: ?forum={$_GET['forum']}");
}
} else {
// Stop non global-mods immediately from using the forum list feature
if (!$isfullmod) {
errorpage("No forum selected.");
}
}
// Topmost select box to change the forum bans we're editing
if ($isfullmod) {
$forumlist = "
<form method='GET'>
<div class='font center'>
Forum list: ".doforumlist($_GET['forum'], $name = 'forum', $shownone = '--- Select a forum ---')."
<input type='submit' class='submit' value='Go'>
</div>
</form>";
} else {
$forumlist = "";
}
if (!$_GET['forum']) {
pageheader("Forum bans");
print adminlinkbar().$forumlist;
errorpage("Select a forum from the list above to edit its banned users.");
} else {
if ($ismod) {
$windowtitle = "Editing forum bans";
// Deletion / addition actions at the bottom of the table
$addlink = "
<tr>
<td class='tdbgc'>
<input type='submit' class='submit' style='padding: 0px; font-size: 10px' name='dodel' value='Delete selected'>
".auth_tag()."
</td>
<td class='tdbgc center' colspan=5>
<a href='?forum={$_GET['forum']}&edit=-1'><< Add a new ban >></a>
</td>
</tr>";
} else {
$windowtitle = "Forum bans";
$addlink = $forumlist = "";
}
pageheader("{$windowtitle} - {$forum['title']}");
print adminlinkbar().$forumlist;
//--
$_POST['searchreason'] = filter_string($_POST['searchreason']);
$_POST['searchuser'] = filter_int($_POST['searchuser']);
$_POST['page'] = filter_int($_POST['page']);
$formlink = "?forum={$_GET['forum']}";
if (!isset($_GET['ppp'])) {
$ppp = 100;
} else {
$ppp = max(min(((int) $_GET['ppp']), 500), 1);
$formlink .= "&ppp={$ppp}";
}
// Query values
$outres = array();
$qsearch = "";
if ($_POST['searchreason']) {
$outres['reason'] = "%{$_POST['searchreason']}%";
$qsearch .= " AND f.reason LIKE :reason";
}
if ($_POST['searchuser']) {
//$userid = $sql->resultp("SELECT id FROM users WHERE name = ?", [$_POST['searchuser']]);
$qsearch .= " AND f.user = {$_POST['searchuser']}";
}
//--
// Ban list
$total = $sql->resultp("SELECT COUNT(*) FROM forumbans f WHERE f.forum = {$_GET['forum']} {$qsearch}", $outres);
$_POST['page'] = numrange($_POST['page'], 0, ceil($total / $ppp) - 1); // Restrict to real values
$forumbans = $sql->queryp("
SELECT f.*, ".set_userfields('u1')." uid, ".set_userfields('u2')." uid
FROM forumbans f
LEFT JOIN users u1 ON f.user = u1.id
LEFT JOIN users u2 ON f.banner = u2.id
WHERE f.forum = {$_GET['forum']} {$qsearch}
ORDER BY f.date DESC
LIMIT ".($_POST['page'] * $ppp).",$ppp
", $outres);
$txt = "";
$ban = array();
for ($i = 0; $x = $sql->fetch($forumbans, PDO::FETCH_NAMED); ++$i) {
$bg = ($i % 2) + 1;
// Confirm the ban we're viewing
if ($_GET['edit'] == $x['id']) {
$ban = $x;
}
// Don't show edit/delete links to non mods
if ($ismod) {
$editlink = "<input type='checkbox' name='delban[]' value='{$x['id']}'> - <a href='?forum={$_GET['forum']}&edit={$x['id']}'>Edit</a>";
} else {
$editlink = ($i+1);
}
$txt .= "
<tr>
<td class='tdbg{$bg} center fonts' style='width: 60px'>{$editlink}</td>
<td class='tdbg{$bg} center'>".getuserlink(array_column_by_key($x, 0), $x['user'])."</td>
<td class='tdbg{$bg} center'>".($x['reason'] ? $x['reason'] : "—")."</td>
<td class='tdbg{$bg} center'>".($x['banner'] ? getuserlink(array_column_by_key($x, 1), $x['banner']) : "Autoban")."</td>
<td class='tdbg{$bg} center'>".printdate($x['date'])."</td>
<td class='tdbg{$bg} center'>".($x['expire'] ? timeunits2($x['expire'] - ctime()) : "Permanent" )."</td>
</tr>";
}
?>
<center>
<form method="POST" action="<?=$formlink?>">
<table class="table" style="max-width: 800px">
<tr>
<td class='tdbgh' style='width: 130px'> </td>
<td class='tdbgh'> </td>
</tr>
<tr>
<td class='tdbg1 center b'>
Search user:
</td>
<td class='tdbg2'>
<?= user_select('searchuser', $_POST['searchuser'], 'powerlevel < 2') ?>
</td>
</tr>
<tr>
<td class='tdbg1 center b'>
Search reason:
</td>
<td class='tdbg2'>
<input type='text' name='searchreason' size=72 value="<?= htmlspecialchars($_POST['searchreason']) ?>">
</td>
</tr>
<tr id="pagetr">
<td class='tdbg1 center b'>
Display page:
</td>
<td class='tdbg2'>
<?= page_select($total, $ppp) ?>
</td>
</tr>
<tr>
<td class='tdbg2'></td>
<td class='tdbg2'>
<input type='submit' class='submit' name='dosearch' value='Search'>
</td>
</tr>
</table>
</center>
</form>
<br>
<form method="POST" action="<?=$formlink?>&edit=<?=$_GET['edit']?>">
<table class="table">
<tr><td class="tdbgh center b" colspan=6>Forum bans for <a href="forum.php?id=<?=$forum['id']?>?>"><?= htmlspecialchars($forum['title']) ?></a> (Total: <?= $i ?>)</td></tr>
<tr>
<td class="tdbgc center" style="width: 10px">#</td>
<td class="tdbgc center" style="width: 15%">User</td>
<td class="tdbgc center">Reason</td>
<td class="tdbgc center" style="width: 15%">Banned by</td>
<td class="tdbgc center" style="width: 200px">Date</td>
<td class="tdbgc center" style="width: 300px">Ban duration</td>
</tr>
<?= $txt ?>
<?= $addlink ?>
</table>
</form>
<?php
// Add / edit a forum ban
if ($ismod && ($ban || $_GET['edit'] == -1)) {
if ($_GET['edit'] == -1) {
$ban = array(
'user' => 0,
'expire' => 0,
'reason' => '',
);
$title = "Add a new ban";
} else {
$title = "Edit ban";
}
?>
<br>
<center>
<form method="POST" action="<?=$formlink?>>&edit=<?=$_GET['edit']?>">
<table class="table" style="max-width: 600px">
<tr><td class="tdbgh center b" colspan=2><?= $title ?></tr></td>
<tr>
<td class="tdbg1 center b">User</td>
<td class="tdbg2">
<?= user_select('user', $ban['user'], 'powerlevel < 2') ?>
</td>
</tr>
<tr>
<td class="tdbg1 center b">Ban duration</td>
<td class="tdbg2">
<?= ban_hours('expire', $ban['expire']) ?>
</td>
</tr>
<tr>
<td class="tdbg1 center b">Reason</td>
<td class="tdbg2">
<input type="text" name="reason" value="<?= htmlspecialchars($ban['reason']) ?>" maxlength=127 style="width: 450px">
</td>
</tr>
<tr>
<td class="tdbg1 center b"> </td>
<td class="tdbg2">
<input type="submit" class="submit" name="save" value="Save settings">
<?= auth_tag() ?>
</td>
</tr>
</table>
</form>
</center>
<?php
}
}
pagefooter();