From: Valerie Pond Date: Sun, 8 Jan 2023 01:51:49 +0000 (+0000) Subject: Allow adding spamfilter entries X-Git-Tag: 0.9~562 X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/commitdiff_plain/2fba9a82b28b8cf2c0d9d5ab92a32b76f10d79fc?ds=sidebyside;hp=dc961139b6abc47e087ec829b862cc07550329a9 Allow adding spamfilter entries --- diff --git a/css/unrealircd-admin.css b/css/unrealircd-admin.css index 4951659..be70c16 100644 --- a/css/unrealircd-admin.css +++ b/css/unrealircd-admin.css @@ -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; +} diff --git a/index.php b/index.php index fbb29c8..a92e6cd 100644 --- 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();

+
+ Add Spamfilter Entry +
+
+ +
+
Entry:

+
MatchType:

+
Action:

+ +
+ Channel messages
+
Private messages
+
Channel notices
+
Private notices
+
Part reason
+
DCC Filename
+
Away messages
+
Channel topic
+
MessageTags
+
Userhost (nick!user@host:realname)
+
+ + + +
+
+ Don't affect logged-in users (soft) +
+
+
Select all