X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/a448002a8fc5be5aec9dab66d2d6050163d655b2..f88a8f2fcfac94743022af7b324c2a21de8f7118:/spamfilter.php?ds=inline diff --git a/spamfilter.php b/spamfilter.php index 3e2e029..442428a 100644 --- a/spamfilter.php +++ b/spamfilter.php @@ -1,8 +1,79 @@ Array("short_text" => "usermsg", "long_text" => "User message"), + "n"=>Array("short_text" => "usernotice", "long_text" => "User notice"), + "c"=>Array("short_text" => "chanmsg", "long_text" => "Channel message"), + "N"=>Array("short_text" => "channotice", "long_text" => "Channel notice"), + "P"=>Array("short_text" => "part", "long_text" => "Part message"), + "q"=>Array("short_text" => "quit", "long_text" => "Quit message"), + "d"=>Array("short_text" => "dcc", "long_text" => "DCC Filename"), + "a"=>Array("short_text" => "away", "long_text" => "Away message"), + "t"=>Array("short_text" => "topic", "long_text" => "Channel topic"), + "T"=>Array("short_text" => "message-tag", "long_text" => "Message tag"), + "u"=>Array("short_text" => "usermask", "long_text" => "User mask (nick!user@host:realname)"), +); + +function spamfilter_targets_to_string($targets) +{ + GLOBAL $spamfilter_target_info; + + $ret = ''; + for ($i = 0, $targs = ""; $i < strlen($targets); $i++) + { + $c = $targets[$i]; + if (isset($spamfilter_target_info[$c])) + $ret .= $spamfilter_target_info[$c]["short_text"].", "; + else + $ret .= "??, "; + } + $ret = rtrim($ret,", "); + return $ret; +} + +function spamfilter_targets_to_string_with_info($targets) +{ + GLOBAL $spamfilter_target_info; + + $ret = ''; + for ($i = 0, $targs = ""; $i < strlen($targets); $i++) + { + $c = $targets[$i]; + if (isset($spamfilter_target_info[$c])) + $ret .= "".$spamfilter_target_info[$c]["short_text"].", "; + else + $ret .= "??, "; + } + $ret = rtrim($ret,", "); + return $ret; +} + +function spamfilter_target_name_to_char($name) +{ + GLOBAL $spamfilter_target_info; + + foreach ($spamfilter_target_info as $char=>$e) + { + if ($e["short_text"] == $name) + return $char; + } + return false; +} + +function spamfilter_targets_from_array_to_chars($ar) +{ + $ret = ''; + foreach ($ar as $name) + { + $c = spamfilter_target_name_to_char($name); + if ($c !== false) + $ret .= $c; + } + return $ret; +} + if (!empty($_POST)) { @@ -27,45 +98,7 @@ if (!empty($_POST)) { $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; - } - } + $targ_chars = spamfilter_targets_from_array_to_chars($targets); /* duplicate code for now [= */ $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL; $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL; @@ -87,7 +120,7 @@ if (!empty($_POST)) $reason = isset($_POST['ban_reason']) ? $_POST['ban_reason'] : "No reason"; $soft = (isset($_POST['soft'])) ? true : false; if ($soft) - $targ_chars = "%" . $targ_chars; + $bantype = "soft-$bantype"; 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 @@ -137,18 +170,18 @@ $spamfilter = $rpc->spamfilter()->getAll();