]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Allow adding multiple ban exception types
authorValerie Pond <redacted>
Sun, 5 Feb 2023 05:44:46 +0000 (05:44 +0000)
committerValerie Pond <redacted>
Sun, 5 Feb 2023 05:44:46 +0000 (05:44 +0000)
Also add two more columns to the list

Classes/class-paneluser.php
misc/ban-exceptions-misc.php [new file with mode: 0644]
server-bans/ban-exceptions.php
users/index.php

index e2a93223a4161ab23874657e993d14e3d0659504..b0d85125b1ce8d61ae2a4efe9cb1b2aada92839b 100644 (file)
@@ -27,6 +27,7 @@ class PanelUser
        public $created = NULL;
        public $user_meta = [];
        public $bio = NULL;
+       public $email = NULL;
 
        /**
         * Find a user in the database by name or ID
diff --git a/misc/ban-exceptions-misc.php b/misc/ban-exceptions-misc.php
new file mode 100644 (file)
index 0000000..72a95fe
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+
+function convert_exceptiontypes_to_badges($types)
+{
+    $badges = "";
+    var_dump($types);
+    for ($i = 0; $i <= strlen($types) - 1; $i++)
+    {
+        if ($types[$i] == "k")
+            $name = "K-Line";
+        if ($types[$i] == "G")
+            $name = "G-Line";
+        elseif ($types[$i] == "z")
+            $name = "Z-Line";
+        elseif ($types[$i] == "Z")
+            $name = "GZ-Line";
+        elseif ($types[$i] == "Q")
+            $name = "Q-Line";
+        elseif ($types[$i] == "s")
+            $name = "Shun";
+        elseif ($types[$i] == "F")
+            $name = "Spamfilter";
+        elseif ($types[$i] == "b")
+            $name = "Blacklist";
+        elseif ($types[$i] == "c")
+            $name = "Connect Flood";
+        elseif ($types[$i] == "d")
+            $name = "Handshake";
+        elseif ($types[$i] == "m")
+            $name = "Max Per IP";
+        elseif ($types[$i] == "r")
+            $name = "Anti-Random";
+        elseif ($types[$i] == "8")
+            $name = "Anti-Mixed-UTF8";
+        elseif ($types[$i] == "v")
+            $name = "Versions";
+        if (isset($name))
+            $badges .= "<span class=\"rounded-pill badge badge-info\">$name</span>";
+    }
+    return $badges;
+}
index ca1046dc351c35bb5d74ab5f0893ab38bb5ec6d2..74761a18ed1345729f346f67bc588bc2a953035c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 require_once "../common.php";
-
 require_once "../header.php";
+require_once "../misc/ban-exceptions-misc.php";
 if (!empty($_POST))
 {
 
@@ -27,7 +27,13 @@ if (!empty($_POST))
        {
                if (!($iphost = $_POST['tkl_add']))
                        Message::Fail("No mask was specified");
-               
+
+               $bantypes = isset($_POST['bantype']) ? $_POST['bantype'] : "";
+               $bantypes_dup = "";
+               if (!empty($bantypes))
+                       foreach ($bantypes as $bt)
+                               $bantypes_dup .= $bt;
+               $bantypes = $bantypes_dup;
                /* duplicate code for now [= */
                $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
                $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
@@ -45,8 +51,10 @@ if (!empty($_POST))
                }
                $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for " . rpc_convert_duration_string($duration);
                $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
-       
-               if ($rpc->serverbanexception()->add($iphost, $reason, $duration))
+
+               if (isset($_POST['soft']))
+                       $iphost = "%$iphost";
+               if ($rpc->serverbanexception()->add($iphost, $bantypes, $reason, (($user = unreal_get_current_user())) ? $user->username : NULL, $duration))
                        Message::Success("Ban Exception set against \"$iphost\": $reason");
                else
                        Message::Fail("Ban Exception could not be set against \"$iphost\": $rpc->error");
@@ -68,7 +76,7 @@ Here is where you can make an exception to bans, that is, to make it so that the
                        Add entry
        </button></p></table>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
-       <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
+       <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                <div class="modal-header">
                        <h5 class="modal-title" id="myModalLabel">Add new Ban Exception</h5>
@@ -80,7 +88,7 @@ Here is where you can make an exception to bans, that is, to make it so that the
                
                <form  method="post">
                        <div class="align_label">IP / Mask</div> <input class="curvy" type="text" id="tkl_add" name="tkl_add"><br>
-                       <div class="align_label">Exception Type: </div> <select multiple name="bantype" id="bantype" data-live-search="true">
+                       <div class="align_label">Exception Type: </div> <select multiple name="bantype[]" id="bantype" data-live-search="true">
                                <option value=""></option>
                                
                                        <option value="k">Kill Line (KLine)</option>
@@ -142,14 +150,13 @@ Here is where you can make an exception to bans, that is, to make it so that the
                                                        ?>
                                        </select>
                                        <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
-                                       <input class="curvy input_text" type="text" id="ban_reason" name="ban_reason"><br>
-                                       <input class="curvy input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
+                                       <input class="curvy input_text" type="text" id="ban_reason" name="ban_reason">
                                
                        </div>
                        
                <div class="modal-footer">
                        <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
-                       <button type="submit" action="post" class="btn btn-danger">Add Ban</button>
+                       <button type="submit" action="post" class="btn btn-danger">Add Ban Exception</button>
                        </form>
                </div>
                </div>
@@ -162,6 +169,8 @@ Here is where you can make an exception to bans, that is, to make it so that the
        <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
        <th scope="col">Mask</th>
        <th scope="col">Duration</th>
+       <th scope="col">Type</th>
+       <th scope="col">Exception Types</th>
        <th scope="col">Reason</th>
        <th scope="col">Set By</th>
        <th scope="col">Set On</th>
@@ -179,6 +188,8 @@ Here is where you can make an exception to bans, that is, to make it so that the
                                echo "<td scope=\"col\"><input type=\"checkbox\" value='" . base64_encode($ban_exceptions->name).",".base64_encode($ban_exceptions->type) . "' name=\"tklch[]\"></td>";
                        echo "<td scope=\"col\">".$ban_exceptions->name."</td>";
                        echo "<td scope=\"col\">".$ban_exceptions->duration_string."</td>";
+                       echo "<td scope=\"col\"><span class=\"badge badge-pill badge-primary\">".$ban_exceptions->type."</span></td>";
+                       echo "<td scope=\"col\">".convert_exceptiontypes_to_badges($ban_exceptions->exception_types)."</td>";
                        echo "<td scope=\"col\">".$ban_exceptions->reason."</td>";
                        $set_by = $set_in_config ? "<span class=\"badge rounded-pill badge-secondary\">Config</span>" : show_nick_only($ban_exceptions->set_by);
                        echo "<td scope=\"col\">".$set_by."</td>";
index 5d34ce0bf92b30649134b5cbd8a453ae650956f9..7723b2c1610109af990410f8506f381d3528e605 100644 (file)
@@ -60,6 +60,13 @@ if (!empty($_POST))
                                        if ($bantype == "qline")
                                                $rpc->nameban()->add($name, $reason, $duration);
 
+                                       else if ($bantype == "kill")
+                                       {
+                                               if ($rpc->user()->kill($user->id, $reason))
+                                                       Message::Success($user->name . "(*@" . $user->hostname . ") has been killed: $reason");
+                                               else
+                                                       Message::Fail("Could not kill $user->name: $rpc->error");
+                                       }
                                        else if ($rpc->serverban()->add($user->id, $bantype, $duration, $reason))
                                                Message::Success($user->name . " (*@" . $user->hostname . ") has been $bantype" . "d $msg_msg: $reason");
 
@@ -160,11 +167,10 @@ Click on a username to view more information.
 
                        /* Some basic filtering for ACCOUNT */
                        if (isset($_POST['uf_account']) && strlen($_POST['uf_account']) && 
-                       strpos(strtolower($user->user->account), strtolower($_POST['uf_account'])) !== 0 &&
-                       strpos(strtolower($user->user->account), strtolower($_POST['uf_account'])) == false)
+                       strtolower($user->user->account) !== strtolower($_POST['uf_account']))
                                continue;
 
-                       /* Some basic filtering for ACCOUNT */
+                       /* Some basic filtering for SERVER */
                        if (isset($_POST['uf_server']) && strlen($_POST['uf_server']) && 
                        strpos(strtolower($user->user->servername), strtolower($_POST['uf_server'])) !== 0 &&
                        strpos(strtolower($user->user->servername), strtolower($_POST['uf_server'])) == false)
@@ -213,6 +219,7 @@ Click on a username to view more information.
                <optgroup label="Bans">
                        <option value="gline">GLine</option>
                        <option value="gzline">GZLine</option>
+                       <option value="kill">Kill</option>
                </optgroup>
        </select></td><td colspan="2">
        <label for="banlen_w">Duration: </label>
@@ -258,12 +265,14 @@ Click on a username to view more information.
                        }
                        
                        ?>
-       </select><br></td><tr><td colspan="3">
+       </select>
+       
+       <br></td><tr><td colspan="3">
        
        <label for="ban_reason">Reason: </label>
-       <input class="short-form-control" type="text" name="ban_reason" id="ban_reason" value="No reason">
+       <input class="form-control" type="text" name="ban_reason" id="ban_reason" value="No reason">
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
-                       Apply ban
+                       Apply
        </button></td></table>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
@@ -280,7 +289,7 @@ Click on a username to view more information.
                </div>
                <div class="modal-footer">
                        <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
-                       <button type="submit" action="post" class="btn btn-danger">Ban</button>
+                       <button type="submit" action="post" class="btn btn-danger">Apply</button>
                        
                </div>
                </div>