]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | require_once "../inc/common.php"; | |
3 | require_once "../inc/header.php"; | |
4 | ||
5 | if (!empty($_POST)) | |
6 | { | |
7 | require_once "../inc/connection.php"; | |
8 | ||
9 | if (!empty($_POST['tklch'])) // User has asked to delete these tkls | |
10 | { | |
11 | if (!current_user_can(PERMISSION_SERVER_BAN_DEL)) | |
12 | { | |
13 | Message::Fail("Could not delete: Permission denied"); | |
14 | } | |
15 | else { | |
16 | foreach ($_POST['tklch'] as $key => $value) { | |
17 | $tok = explode(",", $value); | |
18 | $ban = base64_decode($tok[0]); | |
19 | $type = base64_decode($tok[1]); | |
20 | $success = false; | |
21 | if ($type == "except") | |
22 | $success = $rpc->serverbanexception()->delete($ban); | |
23 | else if ($type == "qline" || $type == "local-qline") | |
24 | $success = $rpc->nameban()->delete($ban); | |
25 | else | |
26 | $success = $rpc->serverban()->delete($ban, $type); | |
27 | ||
28 | ||
29 | if ($success) | |
30 | Message::Success("$type has been removed for $ban"); | |
31 | else | |
32 | Message::Fail("Unable to remove $type on $ban: $rpc->error"); | |
33 | } | |
34 | } | |
35 | } | |
36 | elseif (isset($_POST['do_add_ban'])) | |
37 | { | |
38 | if (!current_user_can(PERMISSION_SERVER_BAN_ADD)) | |
39 | { | |
40 | Message::Fail("Could not add: Permission denied"); | |
41 | } | |
42 | else | |
43 | { | |
44 | if (empty($_POST['ban_host']) || empty($_POST['ban_type'])) | |
45 | { | |
46 | Message::Fail("Unable to add Server Ban: No host or ban type selected"); | |
47 | } else | |
48 | { | |
49 | $ban_host = $_POST['ban_host']; | |
50 | $ban_type = $_POST['ban_type']; | |
51 | $ban_soft = empty($_POST['ban_soft']) ? false : true; | |
52 | $ban_duration = $_POST['ban_duration'] ?? 0; | |
53 | $ban_reason = $_POST['ban_reason'] ?? ''; | |
54 | if (!str_contains($ban_host, "@")) | |
55 | $ban_host = "*@$ban_host"; // prefix ban with *@ if no @ present | |
56 | if ($ban_soft) | |
57 | $ban_host = "%$ban_host"; // prefix ban with % if soft-ban | |
58 | if ($rpc->serverban()->add($ban_host, $ban_type, $ban_duration, $ban_reason)) | |
59 | { | |
60 | Message::Success("Ban added on ".htmlspecialchars($ban_host)); | |
61 | } else { | |
62 | $success = false; | |
63 | if (($rpc->errno == -1001) && !empty($_POST['edit_existing'])) | |
64 | { | |
65 | // existing one = del + add | |
66 | // and yeah we do this after add() fails because then we now | |
67 | // at least the syntax and fields and everything are OK. | |
68 | // This so we don't accidentally remove a ban and the add fails | |
69 | // causing the edit to result in a deletion. | |
70 | $e = explode(":", $_POST['edit_existing'], 2); | |
71 | if (count($e) == 2) | |
72 | { | |
73 | if ($rpc->serverban()->delete($e[1], $e[0])) | |
74 | { | |
75 | /* Good, now try the add operation */ | |
76 | if ($rpc->serverban()->add($ban_host, $ban_type, $ban_duration, $ban_reason)) | |
77 | { | |
78 | Message::Success("Ban successfully modified: ".htmlspecialchars($ban_host)); | |
79 | $success = true; | |
80 | } | |
81 | } | |
82 | } | |
83 | } | |
84 | if (!$success) | |
85 | Message::Fail("The ".htmlspecialchars($ban_type)." on ".htmlspecialchars($ban_host)." could not be added: $rpc->error / $rpc->errno"); | |
86 | } | |
87 | } | |
88 | } | |
89 | } | |
90 | elseif (isset($_POST['search_types']) && !empty($_POST['search_types'])) | |
91 | { | |
92 | ||
93 | } | |
94 | } | |
95 | ||
96 | ?> | |
97 | <h4>Server Bans Overview</h4> | |
98 | Here are all your network bans, from K-Lines to G-Lines, it's all here.<br><br> | |
99 | Click on an entry to edit it. | |
100 | <!-- Top add button --> | |
101 | <p><div class="btn btn-primary" onclick="add_ban()" <?php echo (current_user_can(PERMISSION_SERVER_BAN_ADD)) ? "" : "disabled"; ?>> | |
102 | Add Ban</div></p></table> | |
103 | ||
104 | <!-- Add/edit ban --> | |
105 | <div class="modal fade" id="ban_add" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> | |
106 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
107 | <form id="ban_add_form" method="post"> | |
108 | <input name="edit_existing" type="hidden" id="edit_existing" value=""> | |
109 | <div class="modal-content"> | |
110 | <div class="modal-header"> | |
111 | <h5 class="modal-title" id="ban_add_title">Add server ban</h5> | |
112 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
113 | <span aria-hidden="true">×</span></button> | |
114 | </div> | |
115 | <div class="modal-body"> | |
116 | <div class="form-group"> | |
117 | <label for="ban_host" id="iphost_label">IP / Host</label> | |
118 | <input name="ban_host" type="text" class="form-control" id="ban_host" aria-describedby="ban_host_help" value="" required> | |
119 | <small id="ban_host_help" class="form-text text-muted">IP or host on which the ban is applied.</small> | |
120 | </div> | |
121 | <div class="form-group"> | |
122 | <label for="ban_type">Type</label><br> | |
123 | <select class="curvy" name="ban_type" id="ban_type"> | |
124 | <option value=""></option> | |
125 | <optgroup label="Bans"> | |
126 | <option value="kline">Local Kill (K-Line)</option> | |
127 | <option value="gline">Global Kill (G-Line)</option> | |
128 | <option value="zline">Local Z-Line</option> | |
129 | <option value="gzline">Global Z-line</option> | |
130 | </optgroup> | |
131 | </select> | |
132 | <small id="ban_type_help" class="form-text text-muted">Usually K-Line or G-Line. Use Z-Lines with care.</small> | |
133 | </div> | |
134 | <div class="form-group"> | |
135 | <input class="curvy input_text" type="checkbox" id="ban_soft" name="ban_soft"><label for="ban_soft">Soft-ban</label><br> | |
136 | <small id="ban_soft_help" class="form-text text-muted">Ban does not affect logged in users</small> | |
137 | </div> | |
138 | <div class="form-group"> | |
139 | <label for="ban_duration">Duration</label> | |
140 | <input name="ban_duration" type="text" class="form-control" id="ban_duration" aria-describedby="ban_duration_help" value="" placeholder="(empty means permanent ban)"> | |
141 | <small id="ban_duration_help" class="form-text text-muted">Duration of the ban in seconds, or in a format like 1d for 1 day. Leave empty for permanent ban</small> | |
142 | </div> | |
143 | <div class="form-group"> | |
144 | <label for="ban_reason">Reason</label> | |
145 | <input name="ban_reason" type="text" class="form-control" id="ban_reason" aria-describedby="ban_reason_help" value=""> | |
146 | <small id="ban_reason_help" class="form-text text-muted">Reason of the ban (shown to the banned user)</small> | |
147 | </div> | |
148 | </div> | |
149 | ||
150 | <div class="modal-footer"> | |
151 | <button id="CloseButton" type="button" id="cancel_add_ban" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
152 | <button type="submit" name="do_add_ban" id="do_add_ban" class="btn btn-primary">Add Ban</button> | |
153 | </div> | |
154 | </div> | |
155 | </form> | |
156 | </div> | |
157 | </div> | |
158 | ||
159 | <!-- The banlist table --> | |
160 | <form method="post"> | |
161 | <table id="data_list" class="table-striped display responsive nowrap" style="width:100%"> | |
162 | <thead class="table-primary"> | |
163 | <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th> | |
164 | <th scope="col">Mask</th> | |
165 | <th scope="col">Type</th> | |
166 | <th scope="col">Duration</th> | |
167 | <th scope="col">Reason</th> | |
168 | <th scope="col">Set By</th> | |
169 | <th scope="col">Set On</th> | |
170 | <th scope="col">Expires</th> | |
171 | </thead> | |
172 | </table> | |
173 | ||
174 | <!-- Delete button --> | |
175 | <p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2" <?php echo (current_user_can(PERMISSION_SERVER_BAN_DEL)) ? "" : "disabled"; ?>> | |
176 | Delete selected | |
177 | </button></p> | |
178 | <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> | |
179 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
180 | <div class="modal-content"> | |
181 | <div class="modal-header"> | |
182 | <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5> | |
183 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
184 | <span aria-hidden="true">×</span> | |
185 | </button> | |
186 | </div> | |
187 | <div class="modal-body"> | |
188 | Are you sure you want to do this?<br> | |
189 | This cannot be undone. | |
190 | </div> | |
191 | <div class="modal-footer"> | |
192 | <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
193 | <button type="submit" action="post" class="btn btn-danger">Delete</button> | |
194 | ||
195 | </div> | |
196 | </div> | |
197 | </div> | |
198 | </div></form></div></div> | |
199 | ||
200 | <script> | |
201 | let form = document.getElementById("ban_add_form"); | |
202 | let submitban =document.getElementById("do_add_ban"); | |
203 | form.addEventListener("submit", (e) => { | |
204 | let bantype = document.getElementById("ban_type"); | |
205 | let banhost = document.getElementById("ban_host"); | |
206 | if ((bantype.value === "zline" || bantype.value === "gzline") && banhost.value.includes("@")) | |
207 | { | |
208 | e.preventDefault(); | |
209 | document.getElementById("iphost_label").innerHTML = `IP / Host <span class="card alert-danger" style="color:red">Value for (G)Z-Lines MUST be a host or IP.</span>`; | |
210 | } | |
211 | }); | |
212 | ||
213 | let data_list_table = null; | |
214 | ||
215 | $(document).ready( function () { | |
216 | args = { | |
217 | 'responsive': true, | |
218 | 'fixedHeader': { | |
219 | header: true, | |
220 | headerOffset: 53 | |
221 | }, | |
222 | 'ajax': { | |
223 | 'url': '<?php echo get_config("base_url"); ?>api/server-bans.php', | |
224 | dataSrc: '' | |
225 | }, | |
226 | 'columns': [ | |
227 | { 'data': 'Select', 'responsivePriority': 1 }, | |
228 | { 'data': 'Mask', 'responsivePriority': 2, 'className':'virtuallink' }, | |
229 | { 'data': 'Type', 'responsivePriority': 3 }, | |
230 | { 'data': 'Duration', 'responsivePriority': 4 }, | |
231 | { 'data': 'Reason', 'responsivePriority': 5, 'render': DataTable.render.ellipsis(50, false) }, | |
232 | { 'data': 'Set By', 'responsivePriority': 6 }, | |
233 | { 'data': 'Set On', 'responsivePriority': 7 }, | |
234 | { 'data': 'Expires', 'responsivePriority': 8 }, | |
235 | ], | |
236 | 'pageLength':100, | |
237 | 'order':[[1,'asc']], | |
238 | createdRow: function(row) { | |
239 | var td = jQuery(row).find(".truncate"); | |
240 | td.each(function(index, el) { | |
241 | jQuery(this).attr("title", jQuery(this).html()); | |
242 | }); | |
243 | }, | |
244 | }; | |
245 | /* Only show filter pane on desktop */ | |
246 | if (window.innerWidth > 800) | |
247 | { | |
248 | args['dom'] = 'Pfrtip'; | |
249 | args['searchPanes'] = { | |
250 | 'initCollapsed': 'true', | |
251 | 'columns': [2,3,5], | |
252 | 'dtOpts': { | |
253 | select: { style: 'multi'}, | |
254 | order: [[ 1, "desc" ]] | |
255 | }, | |
256 | } | |
257 | } | |
258 | ||
259 | data_list_table = $('#data_list').DataTable(args); | |
260 | ||
261 | $('#data_list').on( 'click', 'td', function () { | |
262 | edit_ban(this); | |
263 | } ); | |
264 | } ); | |
265 | ||
266 | function edit_ban(e) | |
267 | { | |
268 | /* The first column is the 'Select' column */ | |
269 | if (data_list_table.cell(e).index().column == 0) | |
270 | return; | |
271 | /* For all the other columns we try to popup and edit screen */ | |
272 | var data = data_list_table.row(e).data(); | |
273 | $host = data['Mask']; | |
274 | if ($host.startsWith('%')) | |
275 | { | |
276 | $('#ban_host').val($host.substring(1)); | |
277 | $('#ban_soft').prop('checked', true); | |
278 | } else { | |
279 | $('#ban_host').val($host); | |
280 | $('#ban_soft').prop('checked', false); | |
281 | } | |
282 | $type = data['Type'].replace('Soft ',''); | |
283 | if ($type == 'Global Z-Line') | |
284 | $type = 'gzline'; | |
285 | else if ($type == 'Z-Line') | |
286 | $type = 'zline'; | |
287 | else if ($type == 'G-Line') | |
288 | $type = 'gline'; | |
289 | else | |
290 | $type = 'kline'; | |
291 | $('#ban_type').val($type); | |
292 | if (data['Duration'] == 'permanent') | |
293 | $('#ban_duration').val(); | |
294 | else | |
295 | $('#ban_duration').val(data['Duration']); | |
296 | $('#ban_reason').val(data['Reason']); | |
297 | $('#do_del_ban').show(); | |
298 | $('#ban_add_title').html("Edit server ban"); | |
299 | $('#do_add_ban').html("Modify Ban"); | |
300 | $('#edit_existing').val($type+':'+data['Mask']); | |
301 | $('#ban_add').modal('show'); | |
302 | } | |
303 | ||
304 | // This is in a function because a canceled edit_rpc_server otherwise causes a prefilled effect | |
305 | function add_ban() | |
306 | { | |
307 | $('#edit_existing').val(""); | |
308 | $('#ban_host').val(""); | |
309 | $('#ban_type').val(""); | |
310 | $('#ban_duration').val(""); | |
311 | $('#ban_reason').val(""); | |
312 | $('#ban_soft').prop('checked', false); | |
313 | $('#do_del_ban').hide(); | |
314 | $('#ban_add_title').html("Add server ban"); | |
315 | $('#do_add_ban').html("Add Ban"); | |
316 | $('#ban_add').modal('show'); | |
317 | } | |
318 | ||
319 | ||
320 | </script> | |
321 | ||
322 | <?php require_once '../inc/footer.php'; ?> |