]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - users/index.php
Use responsive datatables in Users view: automatic column priority etc.
[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 <!-- <table id="data_list" class="table table-striped table-bordered dt-responsive nowrap" style="width:400px"> -->
112 <table id="data_list" class="display responsive nowrap" style="width:100%">
113 <thead>
114 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_user(this)" /></th>
115 <th scope="col">Nick</th>
116 <th class="countrycol" scope="col">Country</th>
117 <th class="hostname" scope="col">Host / IP</th>
118 <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>
119 <th class="umodescol" scope="col">Usermodes <a href="https://www.unrealircd.org/docs/User_modes" target="_blank">ℹ️</a></th>
120 <th class="opercol" scope="col">Oper</th>
121 <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>
122 <th class="uplinkcol" scope="col">Connected to</th>
123 <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>
124 </thead>
125 </table>
126
127 <!-- User Actions -->
128 <table class="table table-responsive table-light">
129 <tr>
130 <td colspan="2">
131 <label for="bantype">Apply action: </label>
132 <select name="bantype" id="bantype">
133 <option value=""></option>
134 <optgroup label="Bans">
135 <option value="gline">GLine</option>
136 <option value="gzline">GZLine</option>
137 <option value="kill">Kill</option>
138 </optgroup>
139 </select></td><td colspan="2">
140 <label for="banlen_w">Duration: </label>
141 <select name="banlen_w" id="banlen_w">
142 <?php
143 for ($i = 0; $i <= 56; $i++)
144 {
145 if (!$i)
146 echo "<option value=\"0w\"></option>";
147 else
148 {
149 $w = ($i == 1) ? "week" : "weeks";
150 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
151 }
152 }
153 ?>
154 </select>
155 <select name="banlen_d" id="banlen_d">
156 <?php
157 for ($i = 0; $i <= 31; $i++)
158 {
159 if (!$i)
160 echo "<option value=\"0d\"></option>";
161 else
162 {
163 $d = ($i == 1) ? "day" : "days";
164 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
165 }
166 }
167 ?>
168 </select>
169 <select name="banlen_h" id="banlen_h">
170 <?php
171 for ($i = 0; $i <= 24; $i++)
172 {
173 if (!$i)
174 echo "<option value=\"0d\"></option>";
175 else
176 {
177 $h = ($i == 1) ? "hour" : "hours";
178 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
179 }
180 }
181
182 ?>
183 </select>
184
185 <br></td><tr><td colspan="3">
186
187 <label for="ban_reason">Reason: </label>
188 <input class="form-control" type="text" name="ban_reason" id="ban_reason" value="No reason">
189 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#ban_confirmation">
190 Apply
191 </button></td></table>
192
193 <!-- Ban confirmation modal -->
194 <div class="modal fade" id="ban_confirmation" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
195 <div class="modal-dialog modal-dialog-centered" role="document">
196 <div class="modal-content">
197 <div class="modal-header">
198 <h5 class="modal-title" id="ban_confirmation_label">Apply ban</h5>
199 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
200 <span aria-hidden="true">&times;</span>
201 </button>
202 </div>
203 <div class="modal-body">
204 Are you sure you want to do this?
205
206 </div>
207 <div class="modal-footer">
208 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
209 <button type="submit" action="post" class="btn btn-danger">Apply</button>
210
211 </div>
212 </div>
213 </div>
214 </div>
215
216 </form>
217
218 <style>
219 #rclickmenu {
220 position: fixed;
221 z-index: 10000;
222 width: 250px;
223 background: #1b1a1a;
224 border-radius: 5px;
225 transform: scale(0);
226 transform-origin: top left;
227 }
228 #rclickmenu.visible {
229 transform: scale(1);
230 transition: transform 120ms ease-in-out;
231 }
232 #rclickmenu .item {
233 padding: 8px 10px;
234 font-size: 15px;
235 color: #eee;
236 cursor: pointer;
237 border-radius: inherit;
238 }
239 #rclickmenu .item:hover {
240 background: #343434;
241 text-decoration: none;
242 }
243 </style>
244
245 <div id='rclickmenu' class="nav-item list-group">
246 <div id="rclick_opt1" class="item list-group-item-action">View details</div>
247 <div id="rclick_opt2" class="item list-group-item-action">Kill</div>
248 <div id="rclick_opt3" class="item list-group-item-action">Copy
249 </div>
250 </div>
251
252 <script>
253 var rclickmenu = document.getElementById('rclickmenu');
254 var scopes = document.querySelectorAll('.userselector');
255 document.addEventListener("click", (e) =>
256 {
257 if (e.target.offsetParent != rclickmenu)
258 {
259 rclickmenu.classList.remove("visible");
260 }
261 });
262 scopes.forEach((scope) => {
263 scope.addEventListener("contextmenu", (event) =>
264 {
265 event.preventDefault();
266 var { clientX: mouseX, clientY: mouseY } = event;
267 var name = $('#' + scope.id).attr('value')
268 document.getElementById("rclick_opt1").innerHTML = 'View details for ' + name;
269 rclickmenu.style.top = `${mouseY}px`;
270 rclickmenu.style.left = `${mouseX}px`;
271 rclickmenu.classList.remove("visible");
272 setTimeout(() => { rclickmenu.classList.add("visible"); });
273 });
274 });
275 document.addEventListener('keydown', (event) => {
276 if (event.key === 'Escape')
277 {
278 rclickmenu.classList.remove("visible");
279 }
280 });
281
282 $(document).ready( function () {
283 args = {
284 'responsive': true,
285 'fixedHeader': {
286 header: true,
287 headerOffset: 53
288 },
289 'ajax': {
290 'url': '<?php echo get_config("base_url"); ?>api/users.php',
291 dataSrc: ''
292 },
293 'pageLength':100,
294 'order':[[1,'asc']],
295 'columns': [
296 { 'data': 'Select', 'responsivePriority': 1 },
297 { 'data': 'Nick', 'responsivePriority': 1 },
298 { 'data': 'Country', 'className':'countrycol', 'responsivePriority': 2 },
299 { 'data': 'Host/IP', 'className':'hostname', 'responsivePriority': 5 },
300 { 'data': 'Account', 'className':'accountcol', 'responsivePriority': 3 },
301 { 'data': 'Usermodes', 'className':'umodescol', 'responsivePriority': 7 },
302 { 'data': 'Oper', 'className':'opercol', 'responsivePriority': 8 },
303 { 'data': 'Secure', 'className':'securecol', 'responsivePriority': 9 },
304 { 'data': 'Connected to', 'className':'uplinkcol', 'responsivePriority': 6 },
305 { 'data': 'Reputation', 'className':'reputationcol', 'responsivePriority': 4 },
306 ],
307 };
308 /* Hide on mobile */
309 if (window.innerWidth > 800)
310 {
311 args['dom'] = 'Pfrtip';
312 args['searchPanes'] = {
313 'initCollapsed': 'true',
314 'columns': [2,8],
315 'dtOpts': {
316 select: { style: 'multi'},
317 order: [[ 1, "desc" ]]
318 },
319 }
320 }
321
322 $('#data_list').DataTable(args);
323 } );
324
325 </script>
326
327 <?php require_once UPATH.'/inc/footer.php'; ?>