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
">
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>
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>
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 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("@"))
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
>`
;
213 let data_list_table
= null;
215 $
(document
).ready( function () {
223 'url': '<?php echo get_config("base_url"); ?>api/server-bans.php',
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 },
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());
245 /* Only show filter pane on desktop */
246 if (window
.innerWidth
> 800)
248 args
['dom'] = 'Pfrtip';
249 args
['searchPanes'] = {
250 'initCollapsed': 'true',
253 select
: { style
: 'multi'},
254 order
: [[ 1, "desc" ]]
259 data_list_table
= $
('#data_list').DataTable(args
);
261 $
('#data_list').on( 'click', 'td', function () {
268 /* The first column is the 'Select' column */
269 if (data_list_table
.cell(e
).index().column
== 0)
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('%'))
276 $
('#ban_host').val($host.substring(1));
277 $
('#ban_soft').prop('checked', true);
279 $
('#ban_host').val($host);
280 $
('#ban_soft').prop('checked', false);
282 $type = data
['Type'].replace('Soft ','');
283 if ($type == 'Global Z-Line')
285 else if ($type == 'Z-Line')
287 else if ($type == 'G-Line')
291 $
('#ban_type').val($type);
292 if (data
['Duration'] == 'permanent')
293 $
('#ban_duration').val();
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');
304 // This is in a function because a canceled edit_rpc_server otherwise causes a prefilled effect
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');
322 <?php
require_once '../inc/footer.php'; ?>