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