]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - server-bans/index.php
Try to be helpful if someone mixes wrong secrets::key with (old) DB unrealircd::rpc_p...
[irc/unrealircd/unrealircd-webpanel.git] / server-bans / index.php
CommitLineData
fe2a6f27 1<?php
33f512fa 2require_once "../common.php";
e77b1514 3require_once "../connection.php";
33f512fa 4require_once "../header.php";
fe2a6f27
VP
5
6if (!empty($_POST))
7{
8
e0c259fc 9 if (isset($_POST['tklch']) && !empty($_POST['tklch'])) // User has asked to delete these tkls
fe2a6f27 10 {
88cae748
VP
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);
fe2a6f27
VP
18 $ban = base64_decode($tok[0]);
19 $type = base64_decode($tok[1]);
c52ccf69
VP
20 $success = false;
21 if ($type == "except")
5057cc4b 22 $success = $rpc->serverbanexception()->delete($ban);
c52ccf69
VP
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)
fe2a6f27
VP
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 }
e0c259fc 36 elseif (isset($_POST['tkl_add']) && !empty($_POST['tkl_add']))
fe2a6f27 37 {
88cae748
VP
38 if (!current_user_can(PERMISSION_SERVER_BAN_ADD))
39 {
40 Message::Fail("Could not add: Permission denied");
41 }
42 else
e0c259fc 43 {
88cae748
VP
44 if (!($iphost = $_POST['tkl_add']))
45 Message::Fail("No mask was specified");
46 else if (!($bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : false))
47 {
48 Message::Fail("Unable to add Server Ban: No ban type selected");
49 } else /* It did */{
fe2a6f27 50
88cae748
VP
51 if (
52 (
53 $bantype == "gline" ||
54 $bantype == "gzline" ||
55 $bantype == "shun" ||
56 $bantype == "eline"
57 ) && strpos($iphost, "@") == false
58 ) // doesn't have full mask
59 $iphost = "*@" . $iphost;
fe2a6f27 60
88cae748 61 $soft = ($_POST['soft']) ? true : false;
e0c259fc 62
88cae748
VP
63 if ($soft)
64 $iphost = "%" . $iphost;
65 /* duplicate code for now [= */
66 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
67 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
68 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
69 $duration = "";
70 if (!$banlen_d && !$banlen_h && !$banlen_w)
71 $duration .= "0";
72 else {
73 if ($banlen_w)
74 $duration .= $banlen_w;
75 if ($banlen_d)
76 $duration .= $banlen_d;
77 if ($banlen_h)
78 $duration .= $banlen_h;
79 }
80 $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for " . rpc_convert_duration_string($duration);
81 $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
82 if ($bantype == "qline") {
83 if ($rpc->nameban()->add($iphost, $reason, $duration))
84 Message::Success("Name Ban set against \"$iphost\": $reason");
85 else
86 Message::Fail("Name Ban could not be set against \"$iphost\": $rpc->error");
87 } elseif ($bantype == "except") {
88 if ($rpc->serverbanexception()->add($iphost, "", $duration, $reason))
89 Message::Success("Exception set for \"$iphost\": $reason");
90 else
91 Message::Fail("Exception could not be set \"$iphost\": $rpc->error");
92 } else if ($rpc->serverban()->add($iphost, $bantype, $duration, $reason)) {
93 Message::Success("Host / IP: $iphost has been $bantype" . "d $msg_msg: $reason");
94 } else
95 Message::Fail("The $bantype against \"$iphost\" could not be added: $rpc->error");
e0c259fc 96 }
fe2a6f27 97 }
e0c259fc
VP
98 }
99 elseif (isset($_POST['search_types']) && !empty($_POST['search_types']))
100 {
101
fe2a6f27
VP
102 }
103}
104
105$tkl = $rpc->serverban()->getAll();
106?>
33f512fa
VP
107<h4>Server Bans Overview</h4>
108Here are all your network bans, from K-Lines to G-Lines, it's all here.<br><br>
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
f41baac8 193 <table class="container-xxl table table-sm table-responsive caption-top table-striped">
d1d9caa9 194 <thead class="table-primary">
0c12196e 195 <form method="post">
f41baac8
VP
196 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
197 <th scope="col">Mask</th>
198 <th scope="col">Type</th>
199 <th scope="col">Duration</th>
200 <th scope="col">Reason</th>
201 <th scope="col">Set By</th>
202 <th scope="col">Set On</th>
203 <th scope="col">Expires</th>
0d846731 204 </thead>
f41baac8 205 <tbody>
fe2a6f27
VP
206 <?php
207 foreach($tkl as $tkl)
208 {
67e3edd0 209 $set_in_config = ((isset($tkl->set_in_config) && $tkl->set_in_config) || ($tkl->set_by == "-config-")) ? true : false;
f41baac8 210 echo "<tr scope='col'>";
67e3edd0 211 if ($set_in_config)
f41baac8 212 echo "<td scope=\"col\"></td>";
67e3edd0 213 else
f41baac8
VP
214 echo "<td scope=\"col\"><input type=\"checkbox\" value='" . base64_encode($tkl->name).",".base64_encode($tkl->type) . "' name=\"tklch[]\"></td>";
215 echo "<td scope=\"col\">".$tkl->name."</td>";
216 echo "<td scope=\"col\">".$tkl->type_string."</td>";
217 echo "<td scope=\"col\">".$tkl->duration_string."</td>";
218 echo "<td scope=\"col\">".$tkl->reason."</td>";
9307bb12 219 $set_by = $set_in_config ? "<span class=\"badge rounded-pill badge-secondary\">Config</span>" : show_nick_only($tkl->set_by);
f41baac8
VP
220 echo "<td scope=\"col\">".$set_by."</td>";
221 echo "<td scope=\"col\">".$tkl->set_at_string."</td>";
222 echo "<td scope=\"col\">".$tkl->expire_at_string."</td>";
223 echo "</tr>";
fe2a6f27 224 }
88cae748 225 ?></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
226 Delete selected
227 </button></p>
228 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
229 <div class="modal-dialog modal-dialog-centered" role="document">
230 <div class="modal-content">
231 <div class="modal-header">
e3f034ee 232 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
c88945a1
VP
233 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
234 <span aria-hidden="true">&times;</span>
235 </button>
236 </div>
237 <div class="modal-body">
238 Are you sure you want to do this?<br>
239 This cannot be undone.
240 </div>
241 <div class="modal-footer">
e3f034ee 242 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
c88945a1
VP
243 <button type="submit" action="post" class="btn btn-danger">Delete</button>
244
245 </div>
246 </div>
247 </div>
248 </div></form></div></div>
fe2a6f27 249
d72d1923 250<?php require_once '../footer.php'; ?>