]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - server-bans/index.php
Server Bans: don't do "edit ban" popup when selecting bans for deletion.
[irc/unrealircd/unrealircd-webpanel.git] / server-bans / index.php
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
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 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">&times;</span></button>
114 </div>
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>
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>
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">&times;</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 data_list_table = null;
202
203 $(document).ready( function () {
204 args = {
205 'responsive': true,
206 'fixedHeader': {
207 header: true,
208 headerOffset: 53
209 },
210 'ajax': {
211 'url': '<?php echo get_config("base_url"); ?>api/server-bans.php',
212 dataSrc: ''
213 },
214 'columns': [
215 { 'data': 'Select', 'responsivePriority': 1 },
216 { 'data': 'Mask', 'responsivePriority': 2 },
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 },
223 ],
224 'pageLength':100,
225 'order':[[1,'asc']],
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());
230 });
231 },
232 };
233 /* Only show filter pane on desktop */
234 if (window.innerWidth > 800)
235 {
236 args['dom'] = 'Pfrtip';
237 args['searchPanes'] = {
238 'initCollapsed': 'true',
239 'columns': [2,3,5],
240 'dtOpts': {
241 select: { style: 'multi'},
242 order: [[ 1, "desc" ]]
243 },
244 }
245 }
246
247 data_list_table = $('#data_list').DataTable(args);
248
249 $('#data_list').on( 'click', 'td', function () {
250 edit_ban(this);
251 } );
252 } );
253
254 function edit_ban(e)
255 {
256 /* The first column is the 'Select' column */
257 if (data_list_table.cell(e).index().column == 0)
258 return;
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('%'))
263 {
264 $('#ban_host').val($host.substring(1));
265 $('#ban_soft').prop('checked', true);
266 } else {
267 $('#ban_host').val($host);
268 $('#ban_soft').prop('checked', false);
269 }
270 $type = data['Type'].replace('Soft ','');
271 if ($type == 'Global Z-Line')
272 $type = 'gzline';
273 else if ($type == 'Z-Line')
274 $type = 'zline';
275 else if ($type == 'G-Line')
276 $type = 'gline';
277 else
278 $type = 'kline';
279 $('#ban_type').val($type);
280 if (data['Duration'] == 'permanent')
281 $('#ban_duration').val();
282 else
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');
290 }
291
292 // This is in a function because a canceled edit_rpc_server otherwise causes a prefilled effect
293 function add_ban()
294 {
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').modal('show');
303 }
304
305
306 </script>
307
308 <?php require_once '../inc/footer.php'; ?>