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