2 require_once "../inc/common.php";
3 require_once "../inc/header.php";
7 require_once "../inc/connection.php";
9 if (!empty($_POST['tklch'])) // User has asked to delete these tkls
11 if (!current_user_can(PERMISSION_SERVER_BAN_DEL
))
13 Message
::Fail("Could not delete: Permission denied");
16 foreach ($_POST['tklch'] as $key => $value) {
17 $tok = explode(",", $value);
18 $ban = base64_decode($tok[0]);
19 $type = base64_decode($tok[1]);
21 if ($type == "except")
22 $success = $rpc->serverbanexception()->delete($ban);
23 else if ($type == "qline" || $type == "local-qline")
24 $success = $rpc->nameban()->delete($ban);
26 $success = $rpc->serverban()->delete($ban, $type);
30 Message
::Success("$type has been removed for $ban");
32 Message::Fail("Unable to remove
$type on
$ban: $rpc->error
");
36 elseif (isset($_POST['do_add_ban']))
38 if (!current_user_can(PERMISSION_SERVER_BAN_ADD))
40 Message::Fail("Could not add
: Permission denied
");
44 if (empty($_POST['ban_host']) || empty($_POST['ban_type']))
46 Message::Fail("Unable to add Server Ban
: No host
or ban type selected
");
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
57 $ban_host = "%$ban_host"; // prefix ban with % if soft-ban
58 if ($rpc->serverban()->add($ban_host, $ban_type, $ban_duration, $ban_reason))
60 Message::Success("Ban added on
".htmlspecialchars($ban_host));
63 if (($rpc->errno == -1001) && !empty($_POST['edit_existing']))
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);
73 if ($rpc->serverban()->delete($e[1], $e[0]))
75 /* Good, now try the add operation */
76 if ($rpc->serverban()->add($ban_host, $ban_type, $ban_duration, $ban_reason))
78 Message::Success("Ban successfully modified
: ".htmlspecialchars($ban_host));
85 Message::Fail("The
".htmlspecialchars($ban_type)." on
".htmlspecialchars($ban_host)." could not be added
: $rpc->error
/ $rpc->errno
");
90 elseif (isset($_POST['search_types']) && !empty($_POST['search_types']))
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>
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
">
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>
115 <div class="modal
-body
">
116 <div class="form
-group
">
117 <label for="ban_host
">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>
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>
132 <small id="ban_type_help
" class="form
-text text
-muted
">Usually K-Line or G-Line. Use Z-Lines with care.</small>
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>
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>
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>
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>
159 <!-- The banlist table -->
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>
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"; ?>>
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
>
187 <div
class="modal-body">
188 Are you sure you want to
do this
?<br
>
189 This cannot be undone
.
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
>
198 </div
></form
></div
></div
>
201 let data_list_table
= null;
203 $
(document
).ready( function () {
211 'url': '<?php echo get_config("base_url"); ?>api/server-bans.php',
215 {
'data': 'Select', 'responsivePriority': 1 },
216 {
'data': 'Mask', 'responsivePriority': 2, 'className':'virtuallink' },
217 {
'data': 'Type', 'responsivePriority': 3 },
218 {
'data': 'Duration', 'responsivePriority': 4 },
219 {
'data': 'Reason', 'responsivePriority': 5, 'render': DataTable
.render
.ellipsis(50, false) },
220 {
'data': 'Set By', 'responsivePriority': 6 },
221 {
'data': 'Set On', 'responsivePriority': 7 },
222 {
'data': 'Expires', 'responsivePriority': 8 },
226 createdRow
: function(row
) {
227 var td
= jQuery(row
).find(".truncate");
228 td
.each(function(index
, el
) {
229 jQuery(this
).attr("title", jQuery(this
).html());
233 /* Only show filter pane on desktop */
234 if (window
.innerWidth
> 800)
236 args
['dom'] = 'Pfrtip';
237 args
['searchPanes'] = {
238 'initCollapsed': 'true',
241 select
: { style
: 'multi'},
242 order
: [[ 1, "desc" ]]
247 data_list_table
= $
('#data_list').DataTable(args
);
249 $
('#data_list').on( 'click', 'td', function () {
256 /* The first column is the 'Select' column */
257 if (data_list_table
.cell(e
).index().column
== 0)
259 /* For all the other columns we try to popup and edit screen */
260 var data
= data_list_table
.row(e
).data();
261 $host = data
['Mask'];
262 if ($host.startsWith('%'))
264 $
('#ban_host').val($host.substring(1));
265 $
('#ban_soft').prop('checked', true);
267 $
('#ban_host').val($host);
268 $
('#ban_soft').prop('checked', false);
270 $type = data
['Type'].replace('Soft ','');
271 if ($type == 'Global Z-Line')
273 else if ($type == 'Z-Line')
275 else if ($type == 'G-Line')
279 $
('#ban_type').val($type);
280 if (data
['Duration'] == 'permanent')
281 $
('#ban_duration').val();
283 $
('#ban_duration').val(data
['Duration']);
284 $
('#ban_reason').val(data
['Reason']);
285 $
('#do_del_ban').show();
286 $
('#ban_add_title').html("Edit server ban");
287 $
('#do_add_ban').html("Modify Ban");
288 $
('#edit_existing').val($type+
':'+data
['Mask']);
289 $
('#ban_add').modal('show');
292 // This is in a function because a canceled edit_rpc_server otherwise causes a prefilled effect
295 $
('#edit_existing').val("");
296 $
('#ban_host').val("");
297 $
('#ban_type').val("");
298 $
('#ban_duration').val("");
299 $
('#ban_reason').val("");
300 $
('#ban_soft').prop('checked', false);
301 $
('#do_del_ban').hide();
302 $
('#ban_add_title').html("Add server ban");
303 $
('#do_add_ban').html("Add Ban");
304 $
('#ban_add').modal('show');
310 <?php
require_once '../inc/footer.php'; ?>