]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - server-bans/index.php
Users: Scratch the "Secure" column, as it's less useful nowadays that
[irc/unrealircd/unrealircd-webpanel.git] / server-bans / index.php
CommitLineData
fe2a6f27 1<?php
c06c1713 2require_once "../inc/common.php";
c06c1713 3require_once "../inc/header.php";
fe2a6f27
VP
4
5if (!empty($_POST))
6{
63026197 7 require_once "../inc/connection.php";
e0c259fc 8 if (isset($_POST['tklch']) && !empty($_POST['tklch'])) // User has asked to delete these tkls
fe2a6f27 9 {
88cae748
VP
10 if (!current_user_can(PERMISSION_SERVER_BAN_DEL))
11 {
12 Message::Fail("Could not delete: Permission denied");
13 }
14 else {
15 foreach ($_POST['tklch'] as $key => $value) {
16 $tok = explode(",", $value);
fe2a6f27
VP
17 $ban = base64_decode($tok[0]);
18 $type = base64_decode($tok[1]);
c52ccf69
VP
19 $success = false;
20 if ($type == "except")
5057cc4b 21 $success = $rpc->serverbanexception()->delete($ban);
c52ccf69
VP
22 else if ($type == "qline" || $type == "local-qline")
23 $success = $rpc->nameban()->delete($ban);
24 else
25 $success = $rpc->serverban()->delete($ban, $type);
26
27
28 if ($success)
fe2a6f27
VP
29 Message::Success("$type has been removed for $ban");
30 else
31 Message::Fail("Unable to remove $type on $ban: $rpc->error");
32 }
33 }
34 }
e0c259fc 35 elseif (isset($_POST['tkl_add']) && !empty($_POST['tkl_add']))
fe2a6f27 36 {
88cae748
VP
37 if (!current_user_can(PERMISSION_SERVER_BAN_ADD))
38 {
39 Message::Fail("Could not add: Permission denied");
40 }
41 else
e0c259fc 42 {
88cae748
VP
43 if (!($iphost = $_POST['tkl_add']))
44 Message::Fail("No mask was specified");
45 else if (!($bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : false))
46 {
47 Message::Fail("Unable to add Server Ban: No ban type selected");
48 } else /* It did */{
fe2a6f27 49
88cae748
VP
50 if (
51 (
52 $bantype == "gline" ||
53 $bantype == "gzline" ||
54 $bantype == "shun" ||
55 $bantype == "eline"
56 ) && strpos($iphost, "@") == false
57 ) // doesn't have full mask
58 $iphost = "*@" . $iphost;
fe2a6f27 59
88cae748 60 $soft = ($_POST['soft']) ? true : false;
e0c259fc 61
88cae748
VP
62 if ($soft)
63 $iphost = "%" . $iphost;
64 /* duplicate code for now [= */
65 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
66 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
67 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
68 $duration = "";
69 if (!$banlen_d && !$banlen_h && !$banlen_w)
70 $duration .= "0";
71 else {
72 if ($banlen_w)
73 $duration .= $banlen_w;
74 if ($banlen_d)
75 $duration .= $banlen_d;
76 if ($banlen_h)
77 $duration .= $banlen_h;
78 }
79 $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for " . rpc_convert_duration_string($duration);
80 $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
81 if ($bantype == "qline") {
82 if ($rpc->nameban()->add($iphost, $reason, $duration))
83 Message::Success("Name Ban set against \"$iphost\": $reason");
84 else
85 Message::Fail("Name Ban could not be set against \"$iphost\": $rpc->error");
86 } elseif ($bantype == "except") {
87 if ($rpc->serverbanexception()->add($iphost, "", $duration, $reason))
88 Message::Success("Exception set for \"$iphost\": $reason");
89 else
90 Message::Fail("Exception could not be set \"$iphost\": $rpc->error");
91 } else if ($rpc->serverban()->add($iphost, $bantype, $duration, $reason)) {
92 Message::Success("Host / IP: $iphost has been $bantype" . "d $msg_msg: $reason");
93 } else
94 Message::Fail("The $bantype against \"$iphost\" could not be added: $rpc->error");
e0c259fc 95 }
fe2a6f27 96 }
e0c259fc
VP
97 }
98 elseif (isset($_POST['search_types']) && !empty($_POST['search_types']))
99 {
100
fe2a6f27
VP
101 }
102}
103
fe2a6f27 104?>
33f512fa
VP
105<h4>Server Bans Overview</h4>
106Here are all your network bans, from K-Lines to G-Lines, it's all here.<br><br>
bb8529e9 107<!-- Add ban -->
88cae748 108<p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" <?php echo (current_user_can(PERMISSION_SERVER_BAN_ADD)) ? "" : "disabled"; ?>>
0d846731
VP
109 Add entry
110 </button></p></table>
111 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
112 <div class="modal-dialog modal-dialog-centered" role="document">
113 <div class="modal-content">
114 <div class="modal-header">
71ef1a7f 115 <h5 class="modal-title" id="myModalLabel">Add new Server Ban</h5>
0d846731
VP
116 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
117 <span aria-hidden="true">&times;</span>
118 </button>
119 </div>
120 <div class="modal-body">
fe2a6f27 121
0c12196e 122 <form method="post">
0d846731
VP
123 <div class="align_label">IP / Host: </div> <input class="curvy" type="text" id="tkl_add" name="tkl_add"><br>
124 <div class="align_label">Ban Type: </div> <select class="curvy" name="bantype" id="bantype">
fe2a6f27
VP
125 <option value=""></option>
126 <optgroup label="Bans">
127 <option value="kline">Kill Line (KLine)</option>
128 <option value="gline">Global Kill Line (GLine)</option>
129 <option value="zline">Zap Line (ZLine)</option>
130 <option value="gzline">Global Zap Line (GZLine)</option>
131
132 </optgroup>
fe2a6f27
VP
133 </select><br>
134 <div class="align_label"><label for="banlen_w">Duration: </label></div>
0d846731 135 <select class="curvy" name="banlen_w" id="banlen_w">
fe2a6f27
VP
136 <?php
137 for ($i = 0; $i <= 56; $i++)
138 {
139 if (!$i)
140 echo "<option value=\"0w\"></option>";
141 else
142 {
143 $w = ($i == 1) ? "week" : "weeks";
144 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
145 }
146 }
147 ?>
148 </select>
0d846731 149 <select class="curvy" name="banlen_d" id="banlen_d">
fe2a6f27
VP
150 <?php
151 for ($i = 0; $i <= 31; $i++)
152 {
153 if (!$i)
154 echo "<option value=\"0d\"></option>";
155 else
156 {
157 $d = ($i == 1) ? "day" : "days";
158 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
159 }
160 }
161 ?>
162 </select>
0d846731 163 <select class="curvy" name="banlen_h" id="banlen_h">
fe2a6f27
VP
164 <?php
165 for ($i = 0; $i <= 24; $i++)
166 {
167 if (!$i)
168 echo "<option value=\"0d\"></option>";
169 else
170 {
171 $h = ($i == 1) ? "hour" : "hours";
172 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
173 }
174 }
175 ?>
176 </select>
177 <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
0d846731
VP
178 <input class="curvy input_text" type="text" id="ban_reason" name="ban_reason"><br>
179 <input class="curvy input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
180
181 </div>
182
183 <div class="modal-footer">
184 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
185 <button type="submit" action="post" class="btn btn-danger">Add Ban</button>
186 </form>
187 </div>
188 </div>
fe2a6f27 189 </div>
0d846731
VP
190 </div>
191
bb8529e9
BM
192<!-- The banlist table -->
193
0c12196e 194 <form method="post">
bb8529e9
BM
195 <table id="data_list" class="container-xxl table table-sm table-responsive caption-top table-striped">
196 <thead class="table-primary">
f41baac8
VP
197 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
198 <th scope="col">Mask</th>
199 <th scope="col">Type</th>
200 <th scope="col">Duration</th>
201 <th scope="col">Reason</th>
202 <th scope="col">Set By</th>
203 <th scope="col">Set On</th>
204 <th scope="col">Expires</th>
0d846731 205 </thead>
63026197
BM
206 </table>
207
208 <!-- Delete button -->
209 <p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2" <?php echo (current_user_can(PERMISSION_SERVER_BAN_DEL)) ? "" : "disabled"; ?>>
c88945a1
VP
210 Delete selected
211 </button></p>
212 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
213 <div class="modal-dialog modal-dialog-centered" role="document">
214 <div class="modal-content">
215 <div class="modal-header">
e3f034ee 216 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
c88945a1
VP
217 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
218 <span aria-hidden="true">&times;</span>
219 </button>
220 </div>
221 <div class="modal-body">
222 Are you sure you want to do this?<br>
223 This cannot be undone.
224 </div>
225 <div class="modal-footer">
e3f034ee 226 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
c88945a1
VP
227 <button type="submit" action="post" class="btn btn-danger">Delete</button>
228
229 </div>
230 </div>
231 </div>
232 </div></form></div></div>
fe2a6f27 233
bb8529e9
BM
234<script>
235$(document).ready( function () {
236 $('#data_list').DataTable({
63026197
BM
237 'ajax': {
238 'url': '<?php echo get_config("base_url"); ?>api/server-bans.php',
239 dataSrc: ''
240 },
241 'columns': [
242 { 'data': 'Select' },
243 { 'data': 'Mask' },
244 { 'data': 'Type' },
245 { 'data': 'Duration' },
246 { 'data': 'Reason' },
247 { 'data': 'Set By' },
248 { 'data': 'Set On' },
249 { 'data': 'Expires' },
250 ],
bb8529e9
BM
251 'columnDefs': [
252 { targets: '_all', 'type': 'natural' }
253 ],
254 'pageLength':100,
255 });
256} );
257</script>
258
c06c1713 259<?php require_once '../inc/footer.php'; ?>