]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Allow adding spamfilter entries
authorValerie Pond <redacted>
Sun, 8 Jan 2023 01:51:49 +0000 (01:51 +0000)
committerValerie Pond <redacted>
Sun, 8 Jan 2023 01:51:49 +0000 (01:51 +0000)
css/unrealircd-admin.css
index.php

index 4951659d74367c4106191350f6f0e1431ef1d071..be70c16ff4e73ef9e2e9badd7821ab7027094f2f 100644 (file)
@@ -460,4 +460,71 @@ body {
     line-height: 20px;
     cursor: pointer;
     transition: 0.3s;
-}
\ No newline at end of file
+}
+
+
+.checkbox-dropdown {
+    width: 200px;
+    border: 1px solid #aaa;
+    padding: 10px;
+    position: relative;
+    margin: 0 auto;
+    
+    user-select: first;
+}
+
+/* Display CSS arrow to the right of the dropdown text */
+.checkbox-dropdown:after {
+    content:'';
+    height: 0;
+    position: absolute;
+    width: 0;
+    border: 6px solid transparent;
+    border-top-color: #000;
+    top: 50%;
+    right: 10px;
+    margin-top: -3px;
+}
+
+/* Reverse the CSS arrow when the dropdown is active */
+.checkbox-dropdown.is-active:after {
+    border-bottom-color: #000;
+    border-top-color: #fff;
+    margin-top: -9px;
+}
+
+.checkbox-dropdown-list {
+    list-style: none;
+    margin: 0;
+    padding: 0;
+    position: absolute;
+    top: 100%; /* align the dropdown right below the dropdown text */
+    border: inherit;
+    border-top: none;
+    left: -1px; /* align the dropdown to the left */
+    right: -1px; /* align the dropdown to the right */
+    opacity: 0; /* hide the dropdown */
+   
+    transition: opacity 0.4s ease-in-out;
+    height: 100px;
+    overflow: scroll;
+    overflow-x: hidden;
+    pointer-events: none; /* avoid mouse click events inside the dropdown */
+}
+.is-active .checkbox-dropdown-list {
+    opacity: 1; /* display the dropdown */
+    pointer-events: auto; /* make sure that the user still can select checkboxes */
+}
+
+.checkbox-dropdown-list li label {
+    display: block;
+    border-bottom: 1px solid silver;
+    padding: 10px;
+   
+    transition: all 0.2s ease-out;
+}
+
+.checkbox-dropdown-list li label:hover {
+    background-color: #555;
+    color: white;
+}
index fbb29c89ebeb3c6c6a35f9c66c7dfcd804c18a81..a92e6cd0723e831ad258de675fee3fe80841bee2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -26,7 +26,96 @@ require_once "Classes/class-rpc.php";
 do_log($_POST);
 
 if (!empty($_POST)) {
-       if (!($bantype = $_POST['bantype']))
+
+       if ($sf = $_POST['sf_add']) // if it was a spamfilter entry
+       {
+               /* get targets */
+               $targets = []; // empty arrae
+               foreach($_POST as $key => $value)
+               {
+                       if (substr($key, 0, 7) == "target_")
+                               $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
+               }
+               if (empty($targets))
+                       Message::Fail("No target was specified");
+
+               if (!isset($_POST['sf_bantype']))
+                       Message::Fail("No action was chosen");
+
+               else
+               {
+
+                       $bantype = $_POST['sf_bantype'];
+                       $targ_chars = "";
+                       foreach($targets as $targ)
+                       {
+                               switch ($targ) {
+                                       case "channel":
+                                               $targ_chars .= "c";
+                                               break;
+                                       case "private":
+                                               $targ_chars .= "p";
+                                               break;
+                                       case "channel-notice":
+                                               $targ_chars .= "N";
+                                               break;
+                                       case "private-notice":
+                                               $targ_chars .= "n";
+                                               break;
+                                       case "part":
+                                               $targ_chars .= "P";
+                                               break;
+                                       case "quit":
+                                               $targ_chars .= "q";
+                                               break;
+                                       case "dcc":
+                                               $targ_chars .= "d";
+                                               break;
+                                       case "away":
+                                               $targ_chars .= "a";
+                                               break;
+                                       case "topic":
+                                               $targ_chars .= "t";
+                                               break;
+                                       case "messagetag":
+                                               $targ_chars .= "T";
+                                               break;
+                                       case "user":
+                                               $targ_chars .= "u";
+                                               break;
+                               }
+                       }
+                       /* duplicate code for now [= */
+                       $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
+                       $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
+                       $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
+                       $duration = "";
+                       if (!$banlen_d && !$banlen_h && !$banlen_w)
+                               $duration .= "0";
+                       
+                       else
+                       {
+                               if ($banlen_w)
+                                       $duration .= $banlen_w;
+                               if ($banlen_d)
+                                       $duration .= $banlen_d;
+                               if ($banlen_h)
+                                       $duration .= $banlen_h;
+                       }
+                       $match_type = $_POST['matchtype']; // should default to 'simple'
+                               $reason = isset($_POST['ban_reason']) ? $_POST['ban_reason'] : "No reason";
+                               $soft = (isset($_POST['soft'])) ? true : false;
+                               if ($soft)
+                                       $targ_chars = "%" . $targ_chars;
+                               if ($rpc->spamfilter()->add($sf, $match_type, $targ_chars, $bantype, $duration, $reason))
+                                       Message::Success("Added spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]");
+                               else
+                                       Message::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error");
+               }
+
+       }
+
+       else if (!($bantype = $_POST['bantype'])) // if it was a ban entry
        {
        } 
        else if (!($users = $_POST["userch"]))
@@ -467,6 +556,98 @@ rpc_pop_lists();
        <div class="tab-content\">
        <div id="Spamfilter" data-tab-content>
        <p></p>
+       <div class="tkl_add_boxheader">
+               Add Spamfilter Entry
+       </div>
+       <div class="tkl_add_form">
+               
+               <form action="" method="post">
+                       <div class="align_label">Entry: </div><input class="input_text" type="text" id="sf_add" name="sf_add"><br>
+                       <div class="align_label">MatchType: </div><select name="matchtype" id="matchtype">
+                               <option value="simple">Simple</option>
+                               <option value="regex">Regular Expression</option>
+                       </select><br>
+                       <div class="align_label">Action: </div><select name="sf_bantype" id="sf_bantype">
+                               <option value=""></option>
+                               <optgroup label="Bans">
+                                       <option value="kline">Kill Line (KLine)</option>
+                                       <option value="gline">Global Kill Line (GLine)</option>
+                                       <option value="zline">Zap Line (ZLine)</option>
+                                       <option value="gzline">Global Zap Line (GZLine)</option>
+                                       
+                               </optgroup>
+                               <optgroup label="Restrictions">
+                                       <option value="tempshun">Temporary Shun (Session only)</option>
+                                       <option value="shun">Shun</option>
+                                       <option value="block">Block</option>
+                                       <option value="dccblock">DCC Block</option>
+                                       <option value="viruschan">Send to "Virus Chan"</option>
+                               </optgroup>
+                               <optgroup label="Other">
+                                       <option value="warn">Warn the user</option>
+                               </optgroup>
+                       </select><br>
+                       
+                       <div class="align_label"><label for="banlen_w">Targets: </label></div>
+                       <input type="checkbox" class="input_text" id="target_channel" name="target_channel">Channel messages<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_private" name="target_private">Private messages<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_channel_notice" name="target_channel_notice">Channel notices<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_private_notice" name="target_private_notice">Private notices<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_part" name="target_part">Part reason<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_dcc" name="target_dcc">DCC Filename<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_away" name="target_away">Away messages<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_topic" name="target_topic">Channel topic<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_messagetag" name="target_messagetag">MessageTags<br>
+                       <div class="align_label"><label></label></div><input type="checkbox" class="input_text" id="target_user" name="target_user">Userhost (nick!user@host:realname)<br>
+                       <div class="align_label"><label for="banlen_w">Duration: </label></div>
+                       <select name="banlen_w" id="banlen_w">
+                                       <?php
+                                       for ($i = 0; $i <= 56; $i++)
+                                       {
+                                               if (!$i)
+                                                       echo "<option value=\"0w\"></option>";
+                                               else
+                                               {
+                                                       $w = ($i == 1) ? "week" : "weeks";
+                                                       echo "<option value=\"$i" . "w\">$i $w" . "</option>";
+                                               }
+                                       }
+                                       ?>
+                       </select>
+                       <select name="banlen_d" id="banlen_d">
+                                       <?php
+                                       for ($i = 0; $i <= 31; $i++)
+                                       {
+                                               if (!$i)
+                                                       echo "<option value=\"0d\"></option>";
+                                               else
+                                               {
+                                                       $d = ($i == 1) ? "day" : "days";
+                                                       echo "<option value=\"$i" . "d\">$i $d" . "</option>";
+                                               }
+                                       }
+                                       ?>
+                       </select>
+                       <select name="banlen_h" id="banlen_h">
+                                       <?php
+                                       for ($i = 0; $i <= 24; $i++)
+                                       {
+                                               if (!$i)
+                                                       echo "<option value=\"0d\"></option>";
+                                               else
+                                               {
+                                                       $h = ($i == 1) ? "hour" : "hours";
+                                                       echo "<option value=\"$i" . "h\">$i $h" . "</option>";
+                                               }
+                                       }
+                                       ?>
+                       </select>
+                       <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
+                       <input class="input_text" type="text" id="ban_reason" name="ban_reason"><br>
+                       <input class="input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
+                       <div class="align_right_button_tkl_add"><input class="cute_button" type="submit" id="submit" value="Submit"></div>
+               </form>
+       </div>
        <table class='users_overview'>
        <form action="" method="post">
        <th><input type="checkbox" label='selectall' onClick="toggle_sf(this)" />Select all</th>