]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - server-bans/name-bans.php
Rather large update, please see commit notes
[irc/unrealircd/unrealircd-webpanel.git] / server-bans / name-bans.php
1 <?php
2 require_once "../common.php";
3
4 require_once "../header.php";
5
6 if (!empty($_POST))
7 {
8
9 do_log($_POST);
10
11 if (isset($_POST['tklch']) && !empty($_POST['tklch'])) // User has asked to delete these tkls
12 {
13 foreach ($_POST['tklch'] as $key => $value)
14 {
15 $tok = base64_decode($value);
16 $success = false;
17 $success = $rpc->nameban()->delete($tok);
18
19
20 if ($success)
21 Message::Success("Name Ban has been removed for $tok");
22 else
23 Message::Fail("Unable to remove Name Ban on $tok: $rpc->error");
24 }
25 }
26 elseif (isset($_POST['tkl_add']) && !empty($_POST['tkl_add']))
27 {
28 if (!($iphost = $_POST['tkl_add']))
29 Message::Fail("No mask was specified");
30
31 /* duplicate code for now [= */
32 $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
33 $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
34 $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
35 $duration = "";
36 if (!$banlen_d && !$banlen_h && !$banlen_w)
37 $duration .= "0";
38 else {
39 if ($banlen_w)
40 $duration .= $banlen_w;
41 if ($banlen_d)
42 $duration .= $banlen_d;
43 if ($banlen_h)
44 $duration .= $banlen_h;
45 }
46 $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for " . rpc_convert_duration_string($duration);
47 $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
48
49 if ($rpc->nameban()->add($iphost, $reason, $duration))
50 Message::Success("Name Ban set against \"$iphost\": $reason");
51 else
52 Message::Fail("Name Ban could not be set against \"$iphost\": $rpc->error");
53
54 }
55 elseif (isset($_POST['search_types']) && !empty($_POST['search_types']))
56 {
57
58 }
59 }
60
61
62 $name_bans = $rpc->nameban()->getAll();
63
64 ?>
65 <h4>Name Bans Overview</h4>
66 Here you can essentially forbid the use of a nick or channel name. This is useful to reserve services nicks so they cannot be used by normal users.<br>
67 You can also forbid the use of channel names. This is useful in such cases where an admin might need to close a channel for reasons relating to their own policy.<br>
68 <br>
69 <p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
70 Add entry
71 </button></p></table>
72 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
73 <div class="modal-dialog modal-dialog-centered" role="document">
74 <div class="modal-content">
75 <div class="modal-header">
76 <h5 class="modal-title" id="myModalLabel">Add new Name Ban</h5>
77 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
78 <span aria-hidden="true">&times;</span>
79 </button>
80 </div>
81 <div class="modal-body">
82
83 <form method="post">
84 <div class="align_label">Nick / Channel</div> <input class="curvy" type="text" id="tkl_add" name="tkl_add"><br>
85
86 <div class="align_label"><label for="banlen_w">Duration: </label></div>
87 <select class="curvy" name="banlen_w" id="banlen_w">
88 <?php
89 for ($i = 0; $i <= 56; $i++)
90 {
91 if (!$i)
92 echo "<option value=\"0w\"></option>";
93 else
94 {
95 $w = ($i == 1) ? "week" : "weeks";
96 echo "<option value=\"$i" . "w\">$i $w" . "</option>";
97 }
98 }
99 ?>
100 </select>
101 <select class="curvy" name="banlen_d" id="banlen_d">
102 <?php
103 for ($i = 0; $i <= 31; $i++)
104 {
105 if (!$i)
106 echo "<option value=\"0d\"></option>";
107 else
108 {
109 $d = ($i == 1) ? "day" : "days";
110 echo "<option value=\"$i" . "d\">$i $d" . "</option>";
111 }
112 }
113 ?>
114 </select>
115 <select class="curvy" name="banlen_h" id="banlen_h">
116 <?php
117 for ($i = 0; $i <= 24; $i++)
118 {
119 if (!$i)
120 echo "<option value=\"0d\"></option>";
121 else
122 {
123 $h = ($i == 1) ? "hour" : "hours";
124 echo "<option value=\"$i" . "h\">$i $h" . "</option>";
125 }
126 }
127 ?>
128 </select>
129 <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
130 <input class="curvy input_text" type="text" id="ban_reason" name="ban_reason"><br>
131
132 </div>
133
134 <div class="modal-footer">
135 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
136 <button type="submit" action="post" class="btn btn-danger">Add Ban</button>
137 </form>
138 </div>
139 </div>
140 </div>
141 </div>
142
143 <table class="container-xxl table table-sm table-responsive caption-top table-striped">
144 <thead class="table-primary">
145 <form method="post" action="name-bans.php">
146 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
147 <th scope="col">Mask</th>
148 <th scope="col">Duration</th>
149 <th scope="col">Reason</th>
150 <th scope="col">Set By</th>
151 <th scope="col">Set On</th>
152 <th scope="col">Expires</th>
153 </thead>
154 <tbody>
155 <?php
156 foreach($name_bans as $name_bans)
157 {
158 $set_in_config = ((isset($name_bans->set_in_config) && $name_bans->set_in_config) || ($name_bans->set_by == "-config-")) ? true : false;
159 echo "<tr scope='col'>";
160 if ($set_in_config)
161 echo "<td scope=\"col\"></td>";
162 else
163 echo "<td scope=\"col\"><input type=\"checkbox\" value='" . base64_encode($name_bans->name)."' name=\"tklch[]\"></td>";
164 echo "<td scope=\"col\">".$name_bans->name."</td>";
165 echo "<td scope=\"col\">".$name_bans->duration_string."</td>";
166 echo "<td scope=\"col\">".$name_bans->reason."</td>";
167 $set_by = $set_in_config ? "<span class=\"badge rounded-pill badge-secondary\">Config</span>" : show_nick_only($name_bans->set_by);
168 echo "<td scope=\"col\">".$set_by."</td>";
169 echo "<td scope=\"col\">".$name_bans->set_at_string."</td>";
170 echo "<td scope=\"col\">".$name_bans->expire_at_string."</td>";
171 echo "</tr>";
172 }
173 ?></tbody></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
174 Delete selected
175 </button></p>
176 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
177 <div class="modal-dialog modal-dialog-centered" role="document">
178 <div class="modal-content">
179 <div class="modal-header">
180 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
181 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
182 <span aria-hidden="true">&times;</span>
183 </button>
184 </div>
185 <div class="modal-body">
186 Are you sure you want to do this?<br>
187 This cannot be undone.
188 </div>
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">Delete</button>
192
193 </div>
194 </div>
195 </div>
196 </div></form></div></div>
197
198 <?php require_once 'footer.php'; ?>