]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - server-bans/index.php
85e30ed0ebe99ce515fe5ea3957e21901a2618aa
[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 if (isset($_POST['tklch']) && !empty($_POST['tklch'])) // User has asked to delete these tkls
9 {
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);
17 $ban = base64_decode($tok[0]);
18 $type = base64_decode($tok[1]);
19 $success = false;
20 if ($type == "except")
21 $success = $rpc->serverbanexception()->delete($ban);
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)
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 }
35 elseif (isset($_POST['tkl_add']) && !empty($_POST['tkl_add']))
36 {
37 if (!current_user_can(PERMISSION_SERVER_BAN_ADD))
38 {
39 Message::Fail("Could not add: Permission denied");
40 }
41 else
42 {
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 */{
49
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;
59
60 $soft = ($_POST['soft']) ? true : false;
61
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");
95 }
96 }
97 }
98 elseif (isset($_POST['search_types']) && !empty($_POST['search_types']))
99 {
100
101 }
102 }
103
104 ?>
105 <h4>Server Bans Overview</h4>
106 Here are all your network bans, from K-Lines to G-Lines, it's all here.<br><br>
107 <!-- Add ban -->
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"; ?>>
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">
115 <h5 class="modal-title" id="myModalLabel">Add new Server Ban</h5>
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">
121
122 <form method="post">
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">
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>
133 </select><br>
134 <div class="align_label"><label for="banlen_w">Duration: </label></div>
135 <select class="curvy" name="banlen_w" id="banlen_w">
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>
149 <select class="curvy" name="banlen_d" id="banlen_d">
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>
163 <select class="curvy" name="banlen_h" id="banlen_h">
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>
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>
189 </div>
190 </div>
191
192 <!-- The banlist table -->
193
194 <!-- only in this file for now for testing -->
195 <link rel="stylesheet" href="<?php echo get_config("base_url"); ?>css/datatables.min.css" />
196 <script src="<?php echo get_config("base_url"); ?>js/datatables.min.js"></script>
197 <script src="<?php echo get_config("base_url"); ?>js/datatables-natural-sort.js"></script>
198
199 <form method="post">
200 <table id="data_list" class="container-xxl table table-sm table-responsive caption-top table-striped">
201 <thead class="table-primary">
202 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
203 <th scope="col">Mask</th>
204 <th scope="col">Type</th>
205 <th scope="col">Duration</th>
206 <th scope="col">Reason</th>
207 <th scope="col">Set By</th>
208 <th scope="col">Set On</th>
209 <th scope="col">Expires</th>
210 </thead>
211 </table>
212
213 <!-- Delete button -->
214 <p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2" <?php echo (current_user_can(PERMISSION_SERVER_BAN_DEL)) ? "" : "disabled"; ?>>
215 Delete selected
216 </button></p>
217 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
218 <div class="modal-dialog modal-dialog-centered" role="document">
219 <div class="modal-content">
220 <div class="modal-header">
221 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
222 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
223 <span aria-hidden="true">&times;</span>
224 </button>
225 </div>
226 <div class="modal-body">
227 Are you sure you want to do this?<br>
228 This cannot be undone.
229 </div>
230 <div class="modal-footer">
231 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
232 <button type="submit" action="post" class="btn btn-danger">Delete</button>
233
234 </div>
235 </div>
236 </div>
237 </div></form></div></div>
238
239 <script>
240 $(document).ready( function () {
241 $('#data_list').DataTable({
242 'ajax': {
243 'url': '<?php echo get_config("base_url"); ?>api/server-bans.php',
244 dataSrc: ''
245 },
246 'columns': [
247 { 'data': 'Select' },
248 { 'data': 'Mask' },
249 { 'data': 'Type' },
250 { 'data': 'Duration' },
251 { 'data': 'Reason' },
252 { 'data': 'Set By' },
253 { 'data': 'Set On' },
254 { 'data': 'Expires' },
255 ],
256 'columnDefs': [
257 { targets: '_all', 'type': 'natural' }
258 ],
259 'pageLength':100,
260 });
261 } );
262 </script>
263
264 <?php require_once '../inc/footer.php'; ?>