]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - users/index.php
Make Users list use Datatables with a Search Pane (filter) and Search bar.
[irc/unrealircd/unrealircd-webpanel.git] / users / index.php
CommitLineData
e98b5a51 1<?php
c06c1713
BM
2require_once "../inc/common.php";
3require_once "../inc/connection.php";
4require_once "../inc/header.php";
e98b5a51 5
10102cdc
VP
6if (!empty($_GET))
7{
8 if (isset($_GET['account']) && !isset($_POST['uf_account']))
9 $_POST['uf_account'] = $_GET['account'];
10
11 if (isset($_GET['operonly']) && !isset($_POST['operonly']))
12 $_POST['operonly'] = $_GET['operonly'];
65a14aac
VP
13
14 if (isset($_GET['servicesonly']) && !isset($_POST['servicesonly']))
15 $_POST['servicesonly'] = $_GET['servicesonly'];
10102cdc 16}
6b218bea 17
65a14aac
VP
18if (!empty($_POST))
19{
e98b5a51 20 do_log($_POST);
c68cfb17 21 $bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : NULL;
65a14aac 22
d843c1de 23 if (isset($_POST['userch'])) {
65a14aac
VP
24 foreach ($_POST["userch"] as $user)
25 {
d843c1de 26 $user = $name = base64_decode($user);
65a14aac
VP
27
28 if (!$bantype) /* shouldn't happen? */
29 {
e98b5a51 30 Message::Fail("An error occured");
65a14aac
VP
31 }
32
33 else
34 {
d843c1de
VP
35 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
36 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
37 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
38
39 $duration = "";
40 if (!$banlen_d && !$banlen_h && !$banlen_w)
41 $duration .= "0";
42 else {
43 if ($banlen_w)
44 $duration .= $banlen_w;
45 if ($banlen_d)
46 $duration .= $banlen_d;
47 if ($banlen_h)
48 $duration .= $banlen_h;
49 }
50 $user = $rpc->user()->get($user);
65a14aac 51
0d846731 52 if (!$user && $bantype !== "qline") {
d843c1de 53 Message::Fail("Could not find that user: User not online");
65a14aac
VP
54 }
55
56 else
57 {
d843c1de
VP
58 $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for " . rpc_convert_duration_string($duration);
59 $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
65a14aac 60
0d846731
VP
61 if ($bantype == "qline")
62 $rpc->nameban()->add($name, $reason, $duration);
65a14aac 63
0b546dde
VP
64 else if ($bantype == "kill")
65 {
66 if ($rpc->user()->kill($user->id, $reason))
67 Message::Success($user->name . "(*@" . $user->hostname . ") has been killed: $reason");
68 else
69 Message::Fail("Could not kill $user->name: $rpc->error");
70 }
0d846731 71 else if ($rpc->serverban()->add($user->id, $bantype, $duration, $reason))
d843c1de 72 Message::Success($user->name . " (*@" . $user->hostname . ") has been $bantype" . "d $msg_msg: $reason");
65a14aac 73
d843c1de
VP
74 else
75 Message::Fail("Could not add $bantype against $name: $rpc->error");
76 }
e98b5a51 77 }
e98b5a51
BM
78 }
79 }
80}
81
e98b5a51 82?>
b111d43c 83<h4>Users Overview</h4>
d1d9caa9 84
62d4ea03 85Click on a username to view more information.
e98b5a51 86
4fa72795 87<div class="usertable">
d1d9caa9 88
e98b5a51 89 <?php
10102cdc 90
e98b5a51
BM
91 if (isset($_POST['uf_nick']) && strlen($_POST['uf_nick']))
92 Message::Info("Listing users which match nick: \"" . $_POST['uf_nick'] . "\"");
93
94 if (isset($_POST['uf_ip']) && strlen($_POST['uf_ip']))
95 Message::Info("Listing users which match IP: \"" . $_POST['uf_ip'] . "\"");
96
97 if (isset($_POST['uf_host']) && strlen($_POST['uf_host']))
98 Message::Info("Listing users which match hostmask: \"" . $_POST['uf_host'] . "\"");
99
100 if (isset($_POST['uf_account']) && strlen($_POST['uf_account']))
101 Message::Info("Listing users which match account: \"" . $_POST['uf_account'] . "\"");
102
a5400f9a
VP
103 if (isset($_POST['uf_server']) && strlen($_POST['uf_server']))
104 Message::Info("Listing users connected to servers matching: \"" . $_POST['uf_server'] . "\"");
105
10102cdc 106
e98b5a51 107 ?>
b111d43c 108
5485abb5
BM
109 <!-- The user list -->
110 <table id="data_list" class="container-xxl table table-sm table-responsive caption-top table-striped">
b111d43c
BM
111 <thead class="table-primary">
112 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_user(this)" /></th>
d1d9caa9 113 <th scope="col">Nick</th>
729a16a0 114 <th class="countrycol" scope="col">Country</th>
d75f6d14 115 <th class="hostname" scope="col">Host / IP</th>
729a16a0
BM
116 <th class="accountcol" scope="col"><span data-toggle="tooltip" data-placement="bottom" title="The services account name, if the user identified to services." style="border-bottom: 1px dotted #000000">Account</span></th>
117 <th class="umodescol" scope="col">Usermodes <a href="https://www.unrealircd.org/docs/User_modes" target="_blank">ℹ️</a></th>
d75f6d14
VP
118 <th class="opercol" scope="col">Oper</th>
119 <th class="securecol" scope="col"><span data-toggle="tooltip" data-placement="bottom" title="This shows [Secure] if the user is using SSL/TLS or is on localhost." style="border-bottom: 1px dotted #000000">Secure</span></th>
120 <th class="uplinkcol" scope="col">Connected to</th>
729a16a0 121 <th class="reputationcol" scope="col"><span id="reputationheader" data-toggle="tooltip" data-placement="bottom" title="The reputation score gets higher when someone with this IP address has been connected in the past weeks. A low reputation score (like <10) is an indication of a new IP." style="border-bottom: 1px dotted #000000">Rep.</span> <a href="https://www.unrealircd.org/docs/Reputation_score" target="_blank">ℹ️</a></th>
2bc4c695 122 </thead>
5485abb5 123 </table>
e98b5a51 124
5485abb5 125 <!-- User Actions -->
d1d9caa9
VP
126 <table class="table table-responsive table-light">
127 <tr>
128 <td colspan="2">
129 <label for="bantype">Apply action: </label>
e98b5a51
BM
130 <select name="bantype" id="bantype">
131 <option value=""></option>
132 <optgroup label="Bans">
133 <option value="gline">GLine</option>
134 <option value="gzline">GZLine</option>
0b546dde 135 <option value="kill">Kill</option>
e98b5a51 136 </optgroup>
d1d9caa9
VP
137 </select></td><td colspan="2">
138 <label for="banlen_w">Duration: </label>
e98b5a51
BM
139 <select name="banlen_w" id="banlen_w">
140 <?php
141 for ($i = 0; $i <= 56; $i++)
142 {
143 if (!$i)
144 echo "<option value=\"0w\"></option>";
145 else
146 {
147 $w = ($i == 1) ? "week" : "weeks";
148 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
149 }
150 }
151 ?>
152 </select>
153 <select name="banlen_d" id="banlen_d">
154 <?php
155 for ($i = 0; $i <= 31; $i++)
156 {
157 if (!$i)
158 echo "<option value=\"0d\"></option>";
159 else
160 {
161 $d = ($i == 1) ? "day" : "days";
162 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
163 }
164 }
165 ?>
166 </select>
167 <select name="banlen_h" id="banlen_h">
168 <?php
169 for ($i = 0; $i <= 24; $i++)
170 {
171 if (!$i)
172 echo "<option value=\"0d\"></option>";
173 else
174 {
175 $h = ($i == 1) ? "hour" : "hours";
176 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
177 }
178 }
d1d9caa9 179
e98b5a51 180 ?>
0b546dde
VP
181 </select>
182
183 <br></td><tr><td colspan="3">
d1d9caa9
VP
184
185 <label for="ban_reason">Reason: </label>
0b546dde 186 <input class="form-control" type="text" name="ban_reason" id="ban_reason" value="No reason">
d1d9caa9 187 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
0b546dde 188 Apply
d1d9caa9
VP
189 </button></td></table>
190 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
191 <div class="modal-dialog modal-dialog-centered" role="document">
192 <div class="modal-content">
193 <div class="modal-header">
194 <h5 class="modal-title" id="myModalLabel">Apply ban</h5>
195 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
196 <span aria-hidden="true">&times;</span>
197 </button>
198 </div>
199 <div class="modal-body">
200 Are you sure you want to do this?
201
202 </div>
203 <div class="modal-footer">
204 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
0b546dde 205 <button type="submit" action="post" class="btn btn-danger">Apply</button>
d1d9caa9
VP
206
207 </div>
208 </div>
209 </div>
210 </div>
211
e98b5a51 212 </form>
d91b75a2 213
4fa72795
VP
214 <style>
215 #rclickmenu {
216 position: fixed;
217 z-index: 10000;
218 width: 250px;
219 background: #1b1a1a;
220 border-radius: 5px;
cd5d0af0
VP
221 transform: scale(0);
222 transform-origin: top left;
4fa72795
VP
223 }
224 #rclickmenu.visible {
cd5d0af0
VP
225 transform: scale(1);
226 transition: transform 120ms ease-in-out;
4fa72795
VP
227 }
228 #rclickmenu .item {
229 padding: 8px 10px;
230 font-size: 15px;
231 color: #eee;
232 cursor: pointer;
233 border-radius: inherit;
234 }
235 #rclickmenu .item:hover {
236 background: #343434;
237 text-decoration: none;
238 }
239 </style>
240
cd5d0af0 241 <div id='rclickmenu' class="nav-item list-group">
4fa72795
VP
242 <div id="rclick_opt1" class="item list-group-item-action">View details</div>
243 <div id="rclick_opt2" class="item list-group-item-action">Kill</div>
cd5d0af0 244 <div id="rclick_opt3" class="item list-group-item-action">Copy
4fa72795
VP
245 </div>
246
0674e7b5 247<?php /* ?>
d91b75a2
M
248 <h3>Top country</h3>
249 <div id="top-country">
250 <ul>
251 <?php
252 arsort($registrationOfaAllFlags);
253 foreach($registrationOfaAllFlags as $country_code => $count){
254 echo '<li>
255 <div class="drag"><img src="https://flagcdn.com/108x81/'.htmlspecialchars(strtolower($country_code)).'.png" width="108" height="81"><br />
256 '.$country_code . '
257 </div>
258 <div class="count">' . $count . ' <span>connected</span></div>
259 </li>';
260 }
261 ?>
262 </ul>
263 </div>
0674e7b5 264<?php */ ?>
d91b75a2
M
265
266</div>
d1d9caa9
VP
267
268<script>
d75f6d14
VP
269 function resize_check()
270 {
271 var width = window.innerWidth;
729a16a0
BM
272 var show_elements = '';
273 var hide_elements = '';
729a16a0
BM
274 if (width < 500)
275 {
276 show_elements = '';
277 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol, .umodescol, .countrycol';
278 } else
0046e598 279 if (width < 600)
729a16a0 280 {
0046e598
BM
281 show_elements = '.countrycol';
282 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol, .umodescol';
283 } else
284 if (width < 700)
285 {
286 show_elements = '.umodescol, .countrycol';
287 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol';
288 } else
289 if (width < 768)
290 {
291 show_elements = '.securecol, .umodescol, .countrycol';
292 hide_elements = '.hostname, .opercol, .uplinkcol';
293 } else
294 if (width < 875)
295 {
296 // left nav kicks in at 768+ so need to drop one column between 768..875
297 show_elements = '.umodescol, .countrycol';
298 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol';
299 } else if (width < 1000)
300 {
301 show_elements = '.securecol, .umodescol, .countrycol';
302 hide_elements = '.hostname, .uplinkcol, .opercol';
303 } else if (width < 1200)
304 {
305 show_elements = '.opercol, .securecol, .umodescol, .countrycol';
306 hide_elements = '.hostname, .uplinkcol';
307 } else if (width < 1550)
308 {
309 show_elements = '.opercol, .uplinkcol, .securecol, .umodescol, .countrycol';
310 hide_elements = '.hostname';
311 } else if (width < 1750)
312 {
313 show_elements = '.hostname, .opercol, .securecol, .umodescol, .countrycol';
314 hide_elements = '.uplinkcol';
315 } else {
316 show_elements = '.hostname, .opercol, .uplinkcol, .securecol, .umodescol, .countrycol';
317 hide_elements = '';
729a16a0 318 }
d75f6d14 319
729a16a0
BM
320 if (show_elements != '')
321 {
322 show_elements=document.querySelectorAll(show_elements);
323 for (let i = 0; i < show_elements.length; i++)
324 show_elements[i].style.display = '';
325 }
d75f6d14 326
729a16a0
BM
327 if (hide_elements != '')
328 {
329 hide_elements=document.querySelectorAll(hide_elements);
330 for (let i = 0; i < hide_elements.length; i++)
331 hide_elements[i].style.display = 'none';
332 }
d75f6d14
VP
333 }
334 resize_check();
335 window.addEventListener('resize', function() {
336 resize_check();
337 });
4fa72795
VP
338 var rclickmenu = document.getElementById('rclickmenu');
339 var scopes = document.querySelectorAll('.userselector');
cd5d0af0 340 document.addEventListener("click", (e) =>
4fa72795 341 {
cd5d0af0
VP
342 if (e.target.offsetParent != rclickmenu)
343 {
344 rclickmenu.classList.remove("visible");
345 }
4fa72795
VP
346 });
347 scopes.forEach((scope) => {
348 scope.addEventListener("contextmenu", (event) =>
349 {
350 event.preventDefault();
351 var { clientX: mouseX, clientY: mouseY } = event;
352 var name = $('#' + scope.id).attr('value')
cd5d0af0 353 document.getElementById("rclick_opt1").innerHTML = 'View details for ' + name;
4fa72795
VP
354 rclickmenu.style.top = `${mouseY}px`;
355 rclickmenu.style.left = `${mouseX}px`;
cd5d0af0
VP
356 rclickmenu.classList.remove("visible");
357 setTimeout(() => { rclickmenu.classList.add("visible"); });
4fa72795 358 });
4fa72795 359 });
cd5d0af0
VP
360 document.addEventListener('keydown', (event) => {
361 if (event.key === 'Escape')
362 {
363 rclickmenu.classList.remove("visible");
364 }
365});
5485abb5
BM
366
367$(document).ready( function () {
368 $('#data_list').DataTable({
369 'ajax': {
370 'url': '<?php echo get_config("base_url"); ?>api/users.php',
371 dataSrc: ''
372 },
373 'pageLength':100,
374 'order':[[1,'asc']],
375 'dom': 'Pfrtip',
376 'searchPanes': {
377 'initCollapsed': 'true',
378 'columns': [2,8],
379 'dtOpts': {
380 select: { style: 'multi'},
381 order: [[ 1, "desc" ]]
382 }
383 },
384 'columns': [
385 { 'data': 'Select' },
386 { 'data': 'Nick' },
387 { 'data': 'Country' },
388 { 'data': 'Host/IP' },
389 { 'data': 'Account' },
390 { 'data': 'Usermodes', 'name':'Usermodes', 'searchPanes': { 'name':'Usermodes' } },
391 { 'data': 'Oper' },
392 { 'data': 'Secure' },
393 { 'data': 'Connected to' },
394 { 'data': 'Reputation' },
395 ],
396 });
397} );
398
d1d9caa9 399</script>
e98b5a51 400
c06c1713 401<?php require_once UPATH.'/inc/footer.php'; ?>