X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/e3f034ee6f73e12d53ee1902c5c06ee7535e454e..9b71952e53965e83fe1b95a1791babb440414165:/spamfilter.php diff --git a/spamfilter.php b/spamfilter.php index 2ae1306..8a8a749 100644 --- a/spamfilter.php +++ b/spamfilter.php @@ -1,7 +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)) { @@ -10,95 +82,66 @@ if (!empty($_POST)) if (($sf = (isset($_POST['sf_add'])) ? $_POST['sf_add'] : false)) // 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"); - + if (!current_user_can(PERMISSION_SPAMFILTER_ADD)) + Message::Fail("Could not add Spamfilter entry: Permission denied"); else { - - $bantype = $_POST['sf_bantype']; - $targ_chars = ""; - foreach($targets as $targ) + + /* get targets */ + $targets = []; // empty arrae + foreach($_POST as $key => $value) { - 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; - } + if (substr($key, 0, 7) == "target_") + $targets[] = str_replace(["target_", "_"], ["", "-"], $key); } - /* 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"; - + if (empty($targets)) + Message::Fail("No target was specified"); + + if (!isset($_POST['sf_bantype'])) + Message::Fail("No action was chosen"); + 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]"); + + $bantype = $_POST['sf_bantype']; + $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; + $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL; + $duration = ""; + if (!$banlen_d && !$banlen_h && !$banlen_w) + $duration .= "0"; + else - Message::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error"); + { + 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) + $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 + Message::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error"); + } } } else if (!empty($_POST['sf'])) - foreach ($_POST as $key => $value) - foreach ($value as $tok) + { + if (!current_user_can(PERMISSION_SPAMFILTER_DEL)) + Message::Fail("Could not delete Spamfilter entry or entries: Permission denied"); + else + foreach ($_POST['sf'] as $key => $value) { - $tok = explode(",", $tok); + $tok = explode(",", $value); $name = base64_decode($tok[0]); $match_type = base64_decode($tok[1]); $spamfilter_targets = base64_decode($tok[2]); @@ -108,6 +151,7 @@ if (!empty($_POST)) else Message::Fail("Unable to remove spamfilter on $name: $rpc->error"); } + } } @@ -115,7 +159,7 @@ $spamfilter = $rpc->spamfilter()->getAll(); ?>

Spamfilter Overview


-

- +
- - - - - - - + + + - + + spamfilter()->getAll(); { echo ""; echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; echo ""; - echo ""; + echo ""; + echo ""; + echo ""; echo ""; - 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 ""; echo ""; + echo ""; + echo ""; } - ?>
Select allMaskTypeSet BySet OnExpiresDuration Match TypeMaskTarget Action Action DurationTarget ReasonSet BySet On
".$sf->name."".$sf->type_string."".$sf->set_by."".$sf->set_at_string."".$sf->expire_at_string."".$sf->duration_string."".$sf->match_type."".$sf->ban_action."".$sf->name."".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)."".$sf->ban_action."".$sf->ban_duration_string."".$targs."".$sf->reason."".show_nick_only($sf->set_by)."".$sf->set_at_string."

- +