-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewip.php
277 lines (265 loc) · 8.94 KB
/
viewip.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
<?php
/* BanManagement © 2012, a web interface for the Bukkit plugin BanManager
by James Mortemore of http://www.frostcast.net
is licenced under a Creative Commons
Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales.
Permissions beyond the scope of this licence
may be available at http://creativecommons.org/licenses/by-nc-sa/2.0/uk/.
Additional licence terms at https://raw.github.com/confuser/Ban-Management/master/banmanagement/licence.txt
*/
if(!isset($_GET['server']) || !is_numeric($_GET['server']))
redirect('index.php');
else if(!isset($settings['servers'][$_GET['server']]))
redirect('index.php');
else if(!isset($_GET['ip']) || empty($_GET['ip']))
redirect('index.php');
else if(!filter_var($_GET['ip'], FILTER_VALIDATE_IP))
redirect('index.php');
else {
// Get the server details
$server = $settings['servers'][$_GET['server']];
// Clear old ip
clearCache($_GET['server'].'/ips', 300);
clearCache($_GET['server'].'/mysqlTime', 300);
// Check if they are logged in as an admin
if(isset($_SESSION['admin']) && $_SESSION['admin'])
$admin = true;
else
$admin = false;
// Check if the player exists
$currentBans = cache("SELECT * FROM ".$server['ipTable']." WHERE banned = '".$_GET['ip']."'", 300, $_GET['server'].'/ips', $server);
$pastBans = cache("SELECT * FROM ".$server['ipRecordTable']." WHERE banned = '".$_GET['ip']."'", 300, $_GET['server'].'/ips', $server);
if(count($currentBans) == 0 && count($pastBans) == 0) {
errors('IP does not exist');
?><a href="index.php" class="btn btn-primary">New Search</a><?php
} else {
// They have been banned, naughty!
// Now check the time differences!
$timeDiff = cache('SELECT ('.time().' - UNIX_TIMESTAMP(now()))/3600 AS mysqlTime', 5, $_GET['server'].'/mysqlTime', $server); // Cache it for a few seconds
$mysqlTime = $timeDiff['mysqlTime'];
$mysqlTime = ($mysqlTime > 0) ? floor($mysqlTime) : ceil ($mysqlTime);
$mysqlSecs = ($mysqlTime * 60) * 60;
?>
<div class="hero-unit">
<h2><?php echo $_GET['ip']; ?></h2>
<h3>Server: <?php echo $server['name']; ?></h3>
<?php
$id = array_keys($settings['servers']);
$i = 0;
$html = '';
if(count($settings['servers']) > 1) {
echo '
<h5>Change Server: ';
foreach($settings['servers'] as $serv) {
if($serv['name'] != $server['name']) {
$html .= '<a href="index.php?action=viewplayer&ip='.$_GET['ip'].'&server='.$id[$i].'">'.$serv['name'].'</a>, ';
}
++$i;
}
echo substr($html, 0, -2).'
</h5>';
}
?>
<br />
<table class="table table-striped table-bordered">
<caption>Current Ban</caption>
<tbody>
<?php
if(count($currentBans) == 0) {
echo '
<tr>
<td colspan="2">None</td>
</tr>';
} else {
$reason = str_replace(array('"', '"'), array(''', '\''), $currentBans['ban_reason']);
echo '
<tr>
<td>Expires in:</td>
<td>';
if($currentBans['ban_expires_on'] == 0)
echo '<span class="label label-important">Never</span>';
else {
$currentBans['ban_expires_on'] = $currentBans['ban_expires_on'] + $mysqlSecs;
$currentBans['ban_time'] = $currentBans['ban_time'] + $mysqlSecs;
$expires = $currentBans['ban_expires_on'] - time();
if($expires > 0)
echo '<time datetime="'.date('c', $currentBans['ban_expires_on']).'">'.secs_to_h($expires).'</time>';
else
echo 'Now';
}
echo '</td>
</tr>
<tr>
<td>Banned by:</td>
<td>'.$currentBans['banned_by'].'</td>
</tr>
<tr>
<td>Banned at:</td>
<td>'.date('jS F Y h:i:s A', $currentBans['ban_time']).'</td>
</tr>
<tr>
<td>Reason:</td>
<td>'.$reason.'</td>
</tr>';
if(!empty($currentBans['server'])) {
echo '
<tr>
<td>Server:</td>
<td>'.$currentBans['server'].'</td>
</tr>';
}
}
?>
</tbody>
<?php
if($admin && count($currentBans) != 0) {
echo '
<tfoot>
<tr>
<td colspan="2">
<a class="btn btn-warning edit" title="Edit" href="#editipban" data-toggle="modal"><i class="icon-pencil icon-white"></i> Edit</a>
<a class="btn btn-danger delete" title="Unban" data-role="confirm" href="index.php?action=deleteipban&ajax=true&authid='.sha1($settings['password']).'&server='.$_GET['server'].'&id='.$currentBans['ban_id'].'" data-confirm-title="Unban '.$_GET['ip'].'" data-confirm-body="Are you sure you want to unban '.$_GET['ip'].'?<br />This cannot be undone"><i class="icon-trash icon-white"></i> Unban</a>
</td>
</tr>
</tfoot>';
}
?>
</table>
<?php
if($admin && count($currentBans) != 0) {?>
<div class="modal hide fade" id="editipban">
<form class="form-horizontal" action="" method="post">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Edit IP Ban</h3>
</div>
<div class="modal-body">
<fieldset>
<div class="control-group">
<label class="control-label" for="yourtime">Your Time:</label>
<div class="controls">
<span class="yourtime"></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="servertime">Server Time:</label>
<div class="controls">
<span class="servertime"><?php echo date('d/m/Y H:i:s', time() + $mysqlSecs); ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="bandatetime">Expires Server Time:</label>
<div class="controls">
<div class="input-append datetimepicker date"><?php
echo '
<div class="input-prepend">
<button class="btn btn-danger bantype" type="button">';
if($currentBans['ban_expires_on'] == 0)
echo 'Never';
else
echo 'Temp';
echo '</button>
<input type="text" class="required';
if($currentBans['ban_expires_on'] == 0)
echo ' disabled" disabled="disabled"';
else
echo '"';
echo ' name="expires" data-format="dd/MM/yyyy hh:mm:ss" value="';
if($currentBans['ban_expires_on'] == 0)
echo '';
else
echo date('d/m/Y H:i:s', $currentBans['ban_expires_on']);
echo '" id="bandatetime" />';
?>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="banreason">Reason:</label>
<div class="controls">
<textarea id="banreason" name="reason" rows="4"><?php echo $currentBans['ban_reason']; ?></textarea>
</div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<input type="submit" class="btn btn-primary" value="Save" />
</div>
<input type="hidden" name="id" value="<?php echo $currentBans['ban_id']; ?>" />
<input type="hidden" name="server" value="<?php echo $_GET['server']; ?>" />
<input type="hidden" name="expiresTimestamp" value="" />
</form>
</div><?php
}
?>
<br />
<table class="table table-striped table-bordered" id="previous-ip-bans">
<caption>Previous Bans</caption>
<thead>
<tr>
<th>ID</th>
<th>Reason</th>
<th>By</th>
<th>On</th>
<th>Length</th>
<th>Unbanned By</th>
<th>At</th><?php
if(!is_array($pastBans[0]))
$pastBans = array($pastBans);
$serverName = false;
foreach($pastBans as $r) {
if(!empty($r['server'])) {
$serverName = true;
break;
}
}
if($serverName) {
echo '
<th>Server</th>';
}
?>
</tr>
</thead>
<tbody><?php
if(isset($pastBans[0]) && count($pastBans[0]) == 0) {
echo '
<tr>
<td colspan="8">None</td>
</tr>';
} else {
$i = 1;
if(!isset($pastBans[0]) || (isset($pastBans[0]) && !is_array($pastBans[0])))
$pastBans = array($pastBans);
foreach($pastBans as $r) {
$r['ban_reason'] = str_replace(array('"', '"'), array(''', '\''), $r['ban_reason']);
$r['ban_expired_on'] = ($r['ban_expired_on'] != 0 ? $r['ban_expired_on'] + $mysqlSecs : $r['ban_expired_on']);
$r['ban_time'] = $r['ban_time'] + $mysqlSecs;
$r['unbanned_time'] = $r['unbanned_time'] + $mysqlSecs;
echo '
<tr>
<td>'.$i.'</td>
<td>'.$r['ban_reason'].'</td>
<td>'.$r['banned_by'].'</td>
<td>'.date('H:i:s d/m/y', $r['ban_time']).'</td>
<td>'.($r['ban_expired_on'] == 0 ? 'Never' : secs_to_h($r['ban_expired_on'] - $r['ban_time'])).'</td>
<td>'.$r['unbanned_by'].'</td>
<td>'.date('H:i:s d/m/y', $r['unbanned_time']).'</td>'.($serverName ? '
<td>'.$r['server'].'</td>' : '').($admin ? '
<td class="admin-options"><a href="#" class="btn btn-danger delete" title="Remove" data-server="'.$_GET['server'].'" data-record-id="'.$r['ban_record_id'].'"><i class="icon-trash icon-white"></i></a></td>' : '').'
</tr>';
++$i;
}
}
?>
</tbody>
</table>
</div>
<?php
}
}
?>