]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - server-bans/index.php
Use non-slim jquery, so we have AJAX requests available
[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";
bb8529e9 4require_once "../inc/connection.php";
fe2a6f27
VP
5
6if (!empty($_POST))
7{
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
104$tkl = $rpc->serverban()->getAll();
105?>
33f512fa
VP
106<h4>Server Bans Overview</h4>
107Here are all your network bans, from K-Lines to G-Lines, it's all here.<br><br>
bb8529e9 108<!-- Add ban -->
88cae748 109<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
110 Add entry
111 </button></p></table>
112 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
113 <div class="modal-dialog modal-dialog-centered" role="document">
114 <div class="modal-content">
115 <div class="modal-header">
71ef1a7f 116 <h5 class="modal-title" id="myModalLabel">Add new Server Ban</h5>
0d846731
VP
117 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
118 <span aria-hidden="true">&times;</span>
119 </button>
120 </div>
121 <div class="modal-body">
fe2a6f27 122
0c12196e 123 <form method="post">
0d846731
VP
124 <div class="align_label">IP / Host: </div> <input class="curvy" type="text" id="tkl_add" name="tkl_add"><br>
125 <div class="align_label">Ban Type: </div> <select class="curvy" name="bantype" id="bantype">
fe2a6f27
VP
126 <option value=""></option>
127 <optgroup label="Bans">
128 <option value="kline">Kill Line (KLine)</option>
129 <option value="gline">Global Kill Line (GLine)</option>
130 <option value="zline">Zap Line (ZLine)</option>
131 <option value="gzline">Global Zap Line (GZLine)</option>
132
133 </optgroup>
fe2a6f27
VP
134 </select><br>
135 <div class="align_label"><label for="banlen_w">Duration: </label></div>
0d846731 136 <select class="curvy" name="banlen_w" id="banlen_w">
fe2a6f27
VP
137 <?php
138 for ($i = 0; $i <= 56; $i++)
139 {
140 if (!$i)
141 echo "<option value=\"0w\"></option>";
142 else
143 {
144 $w = ($i == 1) ? "week" : "weeks";
145 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
146 }
147 }
148 ?>
149 </select>
0d846731 150 <select class="curvy" name="banlen_d" id="banlen_d">
fe2a6f27
VP
151 <?php
152 for ($i = 0; $i <= 31; $i++)
153 {
154 if (!$i)
155 echo "<option value=\"0d\"></option>";
156 else
157 {
158 $d = ($i == 1) ? "day" : "days";
159 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
160 }
161 }
162 ?>
163 </select>
0d846731 164 <select class="curvy" name="banlen_h" id="banlen_h">
fe2a6f27
VP
165 <?php
166 for ($i = 0; $i <= 24; $i++)
167 {
168 if (!$i)
169 echo "<option value=\"0d\"></option>";
170 else
171 {
172 $h = ($i == 1) ? "hour" : "hours";
173 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
174 }
175 }
176 ?>
177 </select>
178 <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
0d846731
VP
179 <input class="curvy input_text" type="text" id="ban_reason" name="ban_reason"><br>
180 <input class="curvy input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
181
182 </div>
183
184 <div class="modal-footer">
185 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
186 <button type="submit" action="post" class="btn btn-danger">Add Ban</button>
187 </form>
188 </div>
189 </div>
fe2a6f27 190 </div>
0d846731
VP
191 </div>
192
bb8529e9
BM
193<!-- The banlist table -->
194
195 <!-- only in this file for now for testing -->
196 <link rel="stylesheet" href="<?php echo get_config("base_url"); ?>css/datatables.min.css" />
197 <script src="<?php echo get_config("base_url"); ?>js/datatables.min.js"></script>
198 <script src="<?php echo get_config("base_url"); ?>js/datatables-natural-sort.js"></script>
199
0c12196e 200 <form method="post">
bb8529e9
BM
201 <table id="data_list" class="container-xxl table table-sm table-responsive caption-top table-striped">
202 <thead class="table-primary">
f41baac8
VP
203 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
204 <th scope="col">Mask</th>
205 <th scope="col">Type</th>
206 <th scope="col">Duration</th>
207 <th scope="col">Reason</th>
208 <th scope="col">Set By</th>
209 <th scope="col">Set On</th>
210 <th scope="col">Expires</th>
0d846731 211 </thead>
f41baac8 212 <tbody>
fe2a6f27
VP
213 <?php
214 foreach($tkl as $tkl)
215 {
67e3edd0 216 $set_in_config = ((isset($tkl->set_in_config) && $tkl->set_in_config) || ($tkl->set_by == "-config-")) ? true : false;
f41baac8 217 echo "<tr scope='col'>";
67e3edd0 218 if ($set_in_config)
f41baac8 219 echo "<td scope=\"col\"></td>";
67e3edd0 220 else
f41baac8
VP
221 echo "<td scope=\"col\"><input type=\"checkbox\" value='" . base64_encode($tkl->name).",".base64_encode($tkl->type) . "' name=\"tklch[]\"></td>";
222 echo "<td scope=\"col\">".$tkl->name."</td>";
223 echo "<td scope=\"col\">".$tkl->type_string."</td>";
224 echo "<td scope=\"col\">".$tkl->duration_string."</td>";
225 echo "<td scope=\"col\">".$tkl->reason."</td>";
9307bb12 226 $set_by = $set_in_config ? "<span class=\"badge rounded-pill badge-secondary\">Config</span>" : show_nick_only($tkl->set_by);
f41baac8
VP
227 echo "<td scope=\"col\">".$set_by."</td>";
228 echo "<td scope=\"col\">".$tkl->set_at_string."</td>";
229 echo "<td scope=\"col\">".$tkl->expire_at_string."</td>";
230 echo "</tr>";
fe2a6f27 231 }
88cae748 232 ?></tbody></table><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
233 Delete selected
234 </button></p>
235 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
236 <div class="modal-dialog modal-dialog-centered" role="document">
237 <div class="modal-content">
238 <div class="modal-header">
e3f034ee 239 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
c88945a1
VP
240 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
241 <span aria-hidden="true">&times;</span>
242 </button>
243 </div>
244 <div class="modal-body">
245 Are you sure you want to do this?<br>
246 This cannot be undone.
247 </div>
248 <div class="modal-footer">
e3f034ee 249 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
c88945a1
VP
250 <button type="submit" action="post" class="btn btn-danger">Delete</button>
251
252 </div>
253 </div>
254 </div>
255 </div></form></div></div>
fe2a6f27 256
bb8529e9
BM
257<script>
258$(document).ready( function () {
259 $('#data_list').DataTable({
260 'columnDefs': [
261 { targets: '_all', 'type': 'natural' }
262 ],
263 'pageLength':100,
264 });
265} );
266</script>
267
c06c1713 268<?php require_once '../inc/footer.php'; ?>