-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchip.php
227 lines (204 loc) · 7.19 KB
/
searchip.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
<?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 (!defined('INTERNAL'))
die("Don't call me directly!");
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['player']) || empty($_GET['player']))
redirect('index.php');
else {
$pastbans = true;
if(isset($_GET['excluderecords']))
$pastbans = false;
// Get the server details
$server = $settings['servers'][$_GET['server']];
// Clear old search cache's
clearCache($_GET['server'].'/search', 300);
clearCache($_GET['server'].'/mysqlTime', 300);
$search = $_GET['player'];
$page = 0;
$size = 10;
$sortByCol = 0;
$sortBy = 'ASC';
$filter = '';
$filterCol = 0;
$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;
if(isset($_GET['ajax'])) {
if(isset($_GET['page']) && is_numeric($_GET['page']))
$page = $_GET['page'];
if(isset($_GET['size']) && is_numeric($_GET['size']))
$size = $_GET['size'];
if(isset($_GET['filter']) && $_GET['filter'] != 'filter') {
preg_match('/filter\[([0-9])\]=([a-z0-9]*)/', $_GET['filter'], $filters);
if(!empty($filters)) {
if(isset($filters[1]) && is_numeric($filters[1]))
$filterCol = $filters[1];
if(isset($filters[2]) && is_alphanum($filters[2]))
$filter = $filters[2];
}
}
if(isset($_GET['sortby'])) {
preg_match('/column\[([0-9])\]=([0-9])/', $_GET['sortby'], $orders);
if(!empty($orders)) {
if(isset($orders[1]) && is_numeric($orders[1]))
$sortByCol = $orders[1];
if(isset($orders[2]) && is_numeric($orders[2]))
$sortBy = ($orders[2] == 0 ? 'ASC' : 'DESC');
}
}
$found = searchIps($search, $_GET['server'], $server, $sortByCol, $sortBy, $pastbans);
$total = count($found);
$timeNow = time();
if(is_array($found)) {
$playerNames = array_keys($found);
$ajaxArray = array();
$ajaxArray['total_rows'] = $total;
$start = $page * $size;
$end = $start + $size;
if(!empty($filter)) {
$start = 0;
$end = $total;
}
for($i = $start; $i < $end; ++$i) {
if(!isset($playerNames[$i]))
break;
$player = $found[$playerNames[$i]];
$expireTime = ($player['expires'] + $mysqlSecs)- $timeNow;
if($player['expires'] == 0)
$expires = '<span class="label label-important">Permanent</span>';
else if(isset($expireTime) && $expireTime > 0) {
$expires = '<span class="label label-warning">'.secs_to_hmini($expireTime).'</span>';
} else
$expires = '<span class="label label-warning">Expired</span>';
if(!empty($filter)) {
$skip = false;
switch($filterCol) {
case 0:
if(stripos($playerNames[$i], $filter) === false)
$skip = true;
break;
case 1:
if(stripos($player['type'], $filter) === false)
$skip = true;
break;
case 2:
if(stripos($player['by'], $filter) === false)
$skip = true;
break;
case 3:
if(stripos($player['reason'], $filter) === false)
$skip = true;
break;
case 4:
if(stripos($expires, $filter) === false)
$skip = true;
break;
case 5:
$time = (!empty($player['time']) ? date('j F Y h:i:s A', $player['time']) : '');
if(stripos($time, $filter) === false)
$skip = true;
break;
}
if($skip)
continue;
}
if(!isset($time))
$time = (!empty($player['time']) ? date('j F Y h:i:s A', $player['time']) : '');
$ajaxArray['rows'][] = array(
'<a href="index.php?action=viewip&ip='.$playerNames[$i].'&server='.$_GET['server'].'">'.$playerNames[$i].'</a>',
$player['type'],
$player['by'],
$player['reason'],
$expires,
$time
);
unset($time);
}
if(!empty($filter) && isset($ajaxArray['rows'])) {
$ajaxArray['total_rows'] = count($ajaxArray['rows']);
$start = $page * $size;
if($ajaxArray['total_rows'] >= $start) {
$ajaxArray['rows'] = array_slice($ajaxArray['rows'], $start, $size);
}
}
} else
$total = 1;
if(!is_array($found) || !isset($ajaxArray['rows']))
$ajaxArray = array('total_rows' => 1, 'rows' => array(array('None Found', '', '', '', '', '')));
die(json_encode($ajaxArray));
}
$found = searchIps($search, $_GET['server'], $server, $sortByCol, $sortBy, $pastbans);
if(!$found) {
errors('No matched players found');
?><a href="index.php" class="btn btn-primary">New Search</a><?php
} else {
?>
<form class="form-inline" action="" method="get">
<fieldset>
<div class="page-header">
<h1>Advanced Search</h1>
</div>
<input type="hidden" name="action" value="searchplayer" />
<input type="hidden" name="server" value="<?php echo $_GET['server']; ?>" />
<input type="hidden" name="player" value="<?php echo $_GET['player']; ?>" />
<div class="checkbox" id="excludepast">
<label type="checkbox">
Exclude Past <input type="checkbox" name="excluderecords" value="1"
<?php
if(isset($_GET['excluderecords']))
echo 'checked="checked"';
?>
/>
</label>
</div>
<button type="submit" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-search"></span> Update</button>
</fieldset>
</form>
<table class="table table-striped table-bordered sortable">
<thead>
<tr>
<th>IP Address</th>
<th>Type</th>
<th>By</th>
<th>Reason</th>
<th>Expires</th>
<th>Date</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th colspan="7" class="pager form-horizontal">
<button class="btn btn-default first"><span class="glyphicon glyphicon-step-backward"></span></button>
<button class="btn btn-default prev"><span class="glyphicon glyphicon-arrow-left"></span></button>
<span class="pagedisplay"></span>
<button class="btn btn-default next"><span class="glyphicon glyphicon-arrow-right" style="float:none"></span></button>
<button class="btn btn-default last"><span class="glyphicon glyphicon-step-forward"></span></button>
<select class="pagesize input-mini" title="Select page size">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
<select class="pagenum input-mini" title="Select page number"></select>
</th>
</tr>
</tfoot>
</table>
<?php
}
}
?>