]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - users/index.php
b33fbd1b69607cf80567fc3bd89128d54a670497
[irc/unrealircd/unrealircd-webpanel.git] / users / index.php
1 <?php
2 require_once "../inc/common.php";
3 require_once "../inc/header.php";
4
5 if (!empty($_GET))
6 {
7 if (isset($_GET['account']) && !isset($_POST['uf_account']))
8 $_POST['uf_account'] = $_GET['account'];
9
10 if (isset($_GET['operonly']) && !isset($_POST['operonly']))
11 $_POST['operonly'] = $_GET['operonly'];
12
13 if (isset($_GET['servicesonly']) && !isset($_POST['servicesonly']))
14 $_POST['servicesonly'] = $_GET['servicesonly'];
15 }
16
17 if (!empty($_POST))
18 {
19 require_once "../inc/connection.php";
20 do_log($_POST);
21 $bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : NULL;
22
23 if (isset($_POST['userch'])) {
24 foreach ($_POST["userch"] as $user)
25 {
26 $user = $name = base64_decode($user);
27
28 if (!$bantype) /* shouldn't happen? */
29 {
30 Message::Fail("An error occured");
31 }
32
33 else
34 {
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);
51
52 if (!$user && $bantype !== "qline") {
53 Message::Fail("Could not find that user: User not online");
54 }
55
56 else
57 {
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";
60
61 if ($bantype == "qline")
62 $rpc->nameban()->add($name, $reason, $duration);
63
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 }
71 else if ($rpc->serverban()->add($user->id, $bantype, $duration, $reason))
72 Message::Success($user->name . " (*@" . $user->hostname . ") has been $bantype" . "d $msg_msg: $reason");
73
74 else
75 Message::Fail("Could not add $bantype against $name: $rpc->error");
76 }
77 }
78 }
79 }
80 }
81
82 ?>
83 <h4>Users Overview</h4>
84
85 Click on a username to view more information.
86
87 <div class="usertable">
88
89 <?php
90
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
103 if (isset($_POST['uf_server']) && strlen($_POST['uf_server']))
104 Message::Info("Listing users connected to servers matching: \"" . $_POST['uf_server'] . "\"");
105
106
107 ?>
108
109 <!-- The user list -->
110 <table id="data_list" class="container-xxl table table-sm table-responsive caption-top table-striped">
111 <thead class="table-primary">
112 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_user(this)" /></th>
113 <th scope="col">Nick</th>
114 <th class="countrycol" scope="col">Country</th>
115 <th class="hostname" scope="col">Host / IP</th>
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>
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>
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>
122 </thead>
123 </table>
124
125 <!-- User Actions -->
126 <table class="table table-responsive table-light">
127 <tr>
128 <td colspan="2">
129 <label for="bantype">Apply action: </label>
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>
135 <option value="kill">Kill</option>
136 </optgroup>
137 </select></td><td colspan="2">
138 <label for="banlen_w">Duration: </label>
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 }
179
180 ?>
181 </select>
182
183 <br></td><tr><td colspan="3">
184
185 <label for="ban_reason">Reason: </label>
186 <input class="form-control" type="text" name="ban_reason" id="ban_reason" value="No reason">
187 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#ban_confirmation">
188 Apply
189 </button></td></table>
190
191 <!-- Ban confirmation modal -->
192 <div class="modal fade" id="ban_confirmation" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
193 <div class="modal-dialog modal-dialog-centered" role="document">
194 <div class="modal-content">
195 <div class="modal-header">
196 <h5 class="modal-title" id="ban_confirmation_label">Apply ban</h5>
197 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
198 <span aria-hidden="true">&times;</span>
199 </button>
200 </div>
201 <div class="modal-body">
202 Are you sure you want to do this?
203
204 </div>
205 <div class="modal-footer">
206 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
207 <button type="submit" action="post" class="btn btn-danger">Apply</button>
208
209 </div>
210 </div>
211 </div>
212 </div>
213
214 </form>
215
216 <style>
217 #rclickmenu {
218 position: fixed;
219 z-index: 10000;
220 width: 250px;
221 background: #1b1a1a;
222 border-radius: 5px;
223 transform: scale(0);
224 transform-origin: top left;
225 }
226 #rclickmenu.visible {
227 transform: scale(1);
228 transition: transform 120ms ease-in-out;
229 }
230 #rclickmenu .item {
231 padding: 8px 10px;
232 font-size: 15px;
233 color: #eee;
234 cursor: pointer;
235 border-radius: inherit;
236 }
237 #rclickmenu .item:hover {
238 background: #343434;
239 text-decoration: none;
240 }
241 </style>
242
243 <div id='rclickmenu' class="nav-item list-group">
244 <div id="rclick_opt1" class="item list-group-item-action">View details</div>
245 <div id="rclick_opt2" class="item list-group-item-action">Kill</div>
246 <div id="rclick_opt3" class="item list-group-item-action">Copy
247 </div>
248
249 <?php /* ?>
250 <h3>Top country</h3>
251 <div id="top-country">
252 <ul>
253 <?php
254 arsort($registrationOfaAllFlags);
255 foreach($registrationOfaAllFlags as $country_code => $count){
256 echo '<li>
257 <div class="drag"><img src="https://flagcdn.com/108x81/'.htmlspecialchars(strtolower($country_code)).'.png" width="108" height="81"><br />
258 '.$country_code . '
259 </div>
260 <div class="count">' . $count . ' <span>connected</span></div>
261 </li>';
262 }
263 ?>
264 </ul>
265 </div>
266 <?php */ ?>
267
268 </div>
269
270 <script>
271 function resize_check()
272 {
273 var width = window.innerWidth;
274 var show_elements = '';
275 var hide_elements = '';
276 if (width < 500)
277 {
278 show_elements = '';
279 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol, .umodescol, .countrycol';
280 } else
281 if (width < 600)
282 {
283 show_elements = '.countrycol';
284 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol, .umodescol';
285 } else
286 if (width < 700)
287 {
288 show_elements = '.umodescol, .countrycol';
289 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol';
290 } else
291 if (width < 768)
292 {
293 show_elements = '.securecol, .umodescol, .countrycol';
294 hide_elements = '.hostname, .opercol, .uplinkcol';
295 } else
296 if (width < 875)
297 {
298 // left nav kicks in at 768+ so need to drop one column between 768..875
299 show_elements = '.umodescol, .countrycol';
300 hide_elements = '.hostname, .opercol, .uplinkcol, .securecol';
301 } else if (width < 1000)
302 {
303 show_elements = '.securecol, .umodescol, .countrycol';
304 hide_elements = '.hostname, .uplinkcol, .opercol';
305 } else if (width < 1200)
306 {
307 show_elements = '.opercol, .securecol, .umodescol, .countrycol';
308 hide_elements = '.hostname, .uplinkcol';
309 } else if (width < 1550)
310 {
311 show_elements = '.opercol, .uplinkcol, .securecol, .umodescol, .countrycol';
312 hide_elements = '.hostname';
313 } else if (width < 1750)
314 {
315 show_elements = '.hostname, .opercol, .securecol, .umodescol, .countrycol';
316 hide_elements = '.uplinkcol';
317 } else {
318 show_elements = '.hostname, .opercol, .uplinkcol, .securecol, .umodescol, .countrycol';
319 hide_elements = '';
320 }
321
322 if (show_elements != '')
323 {
324 show_elements=document.querySelectorAll(show_elements);
325 for (let i = 0; i < show_elements.length; i++)
326 show_elements[i].style.display = '';
327 }
328
329 if (hide_elements != '')
330 {
331 hide_elements=document.querySelectorAll(hide_elements);
332 for (let i = 0; i < hide_elements.length; i++)
333 hide_elements[i].style.display = 'none';
334 }
335 }
336 resize_check();
337 window.addEventListener('resize', function() {
338 resize_check();
339 });
340
341 var rclickmenu = document.getElementById('rclickmenu');
342 var scopes = document.querySelectorAll('.userselector');
343 document.addEventListener("click", (e) =>
344 {
345 if (e.target.offsetParent != rclickmenu)
346 {
347 rclickmenu.classList.remove("visible");
348 }
349 });
350 scopes.forEach((scope) => {
351 scope.addEventListener("contextmenu", (event) =>
352 {
353 event.preventDefault();
354 var { clientX: mouseX, clientY: mouseY } = event;
355 var name = $('#' + scope.id).attr('value')
356 document.getElementById("rclick_opt1").innerHTML = 'View details for ' + name;
357 rclickmenu.style.top = `${mouseY}px`;
358 rclickmenu.style.left = `${mouseX}px`;
359 rclickmenu.classList.remove("visible");
360 setTimeout(() => { rclickmenu.classList.add("visible"); });
361 });
362 });
363 document.addEventListener('keydown', (event) => {
364 if (event.key === 'Escape')
365 {
366 rclickmenu.classList.remove("visible");
367 }
368 });
369
370 $(document).ready( function () {
371 $('#data_list').DataTable({
372 'ajax': {
373 'url': '<?php echo get_config("base_url"); ?>api/users.php',
374 dataSrc: ''
375 },
376 'pageLength':100,
377 'order':[[1,'asc']],
378 'dom': 'Pfrtip',
379 'searchPanes': {
380 'initCollapsed': 'true',
381 'columns': [2,8],
382 'dtOpts': {
383 select: { style: 'multi'},
384 order: [[ 1, "desc" ]]
385 }
386 },
387 'columns': [
388 { 'data': 'Select' },
389 { 'data': 'Nick' },
390 { 'data': 'Country', 'className':'countrycol' },
391 { 'data': 'Host/IP', 'className':'hostname' },
392 { 'data': 'Account', 'className':'accountcol' },
393 { 'data': 'Usermodes', 'className':'umodescol' },
394 { 'data': 'Oper', 'className':'opercol' },
395 { 'data': 'Secure', 'className':'securecol' },
396 { 'data': 'Connected to', 'className':'uplinkcol' },
397 { 'data': 'Reputation', 'className':'reputationcol' },
398 ],
399 'initComplete': function(settings, json) { resize_check(); },
400 });
401 } );
402
403 </script>
404
405 <?php require_once UPATH.'/inc/footer.php'; ?>