X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/c88945a18c30f4ddd969f7a72f6153540d6d46bc..3f431b7a3666a818f0895e14049b1d25aa8df924:/spamfilter.php?ds=sidebyside diff --git a/spamfilter.php b/spamfilter.php index 3e3a9bb..4f28dd0 100644 --- a/spamfilter.php +++ b/spamfilter.php @@ -1,14 +1,85 @@ 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)) { do_log($_POST); - if ($sf = $_POST['sf_add']) // if it was a spamfilter entry + if (($sf = (isset($_POST['sf_add'])) ? $_POST['sf_add'] : false)) // if it was a spamfilter entry { /* get targets */ $targets = []; // empty arrae @@ -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; @@ -130,11 +163,25 @@ $spamfilter = $rpc->spamfilter()->getAll();
"; - echo " | ".$sf->name." | "; - echo "".$sf->type_string." | "; - echo "".$sf->set_by." | "; - echo "".$sf->set_at_string." | "; - echo "".$sf->expire_at_string." | "; - echo "".$sf->duration_string." | "; echo "".$sf->match_type." | "; + echo "".$sf->name." | "; + echo "".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)." | "; echo "".$sf->ban_action." | "; echo "".$sf->ban_duration_string." | "; - for ($i = 0, $targs = ""; $i < strlen($sf->spamfilter_targets); $i++) - { - $c = $sf->spamfilter_targets[$i]; - if ($c == "c") - $targs .= "Channel, "; - else if ($c == "p") - $targs .= "Private,"; - else if ($c == "n") - $targs .= "Notice, "; - else if ($c == "N") - $targs .= "Channel notice, "; - else if ($c == "P") - $targs .= "Part message, "; - else if ($c == "q") - $targs .= "Quit message, "; - else if ($c == "d") - $targs .= "DCC filename, "; - else if ($c == "a") - $targs .= "Away message, "; - else if ($c == "t") - $targs .= "Channel topic, "; - else if ($c == "T") - $targs .= "MessageTag, "; - else if ($c == "u") - $targs .= "Usermask, "; - } - $targs = rtrim($targs,", "); - echo "".$targs." | "; echo "".$sf->reason." | "; + echo "".show_nick_only($sf->set_by)." | "; + echo "".$sf->set_at_string." | "; } ?>