-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbans.php
More file actions
133 lines (115 loc) · 2.9 KB
/
bans.php
File metadata and controls
133 lines (115 loc) · 2.9 KB
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
<?php
$pagetitle = 'Ban Control';
require 'common.php';
if (!$logged)
{
$tpl->message = 'You must be logged in to view this page.';
$tpl->Execute(null);
exit;
}
if (!$GUARDIAN)
{
$tpl->message = 'You must be a Guardian to view this page.';
$tpl->Execute(null);
exit;
}
$count = webcp_db_fetchall('SELECT COUNT(1) as count FROM bans');
$count = $count[0]['count'];
if ($count == 0)
{
$tpl->message = 'No bans have been set yet.';
$tpl->Execute(null);
return;
}
if (isset($_POST['action']))
{
switch($_POST['action'])
{
case 'cleanup':
$rows = webcp_db_execute("DELETE FROM bans WHERE expires < ? AND expires != 0", time());
$tpl->message = $rows." ban(s) removed.";
break;
case 'unban':
if (isset($_POST['input'], $_POST['unban-username']))
{
$col = 'username';
$val = $_POST['input'];
}
elseif (isset($_POST['input'], $_POST['unban-ip']))
{
$col = 'ip';
$val = ip2long(($_POST['input']));
if (!$val)
{
$tpl->error = 'Malformed IP address.';
$tpl->Execute('error');
exit;
}
}
elseif (isset($_POST['input'], $_POST['unban-hdid']))
{
$col = 'hdid';
$hdid = explode('-', $_POST['input']);
if (isset($hdid[1]))
{
$val = hexdec($hdid[0]) * 0x10000 + hexdec($hdid[1]);
}
else
{
$val = hexdec($hdid[0]);
}
}
else
{
$tpl->error = 'Invalid arguments to unban action.';
$tpl->Execute('error');
exit;
}
$rows = webcp_db_execute("DELETE FROM bans WHERE $col = ?", $val);
$tpl->message = $rows ." ban(s) removed.";
break;
}
}
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$pages = ceil($count / $perpage);
if ($page < 1 || $page > $pages)
{
$page = max(min($page, $pages), 1);
}
$start = ($page-1) * $perpage;
$bans = webcp_db_fetchall("SELECT * FROM bans ORDER BY expires DESC LIMIT ?,?", $start, $perpage);
foreach ($bans as &$ban)
{
$ban['username'] = $ban['username']===null?'-':$ban['username'];
$ban['nouser'] = $ban['username']===null;
$ban['noip'] = $ban['ip']===null;
$ban['nohdid'] = $ban['hdid']===null;
$ban['ip_str'] = $ban['ip']===null?'-':long2ip($ban['ip']);
$ban['setter'] = ucfirst($ban['setter']);
$ban['hdid_str'] = sprintf("%08x", (double)$ban['hdid']);
$ban['hdid_str'] = strtoupper(substr($ban['hdid_str'],0,4).'-'.substr($ban['hdid_str'],4,4));
$ban['hdid_str'] = $ban['hdid']===null?'-':$ban['hdid_str'];
if ($ban['expires'] <= 0)
{
$ban['remaining'] = '<b>Permanent</b>';
}
elseif ($ban['expires'] <= time())
{
$ban['remaining'] = '<i>Expired</i>';
}
else
{
$ban['remaining'] = timeago_full($ban['expires'], time(), false);
}
}
$pagination = generate_pagination($pages, $page);
$tpl->page = $page;
$tpl->pages = $pages;
$tpl->pagination = $pagination;
$tpl->perpage = $perpage;
$tpl->showing = count($bans);
$tpl->start = $start+1;
$tpl->end = min($start+$perpage, $count);
$tpl->count = $count;
$tpl->bans = $bans;
$tpl->Execute('bans');