]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - spamfilter.php
Users: get rid of "user modes" column. Similar to previous, at least for now.
[irc/unrealircd/unrealircd-webpanel.git] / spamfilter.php
index 0c574fe66840059ae607affdcf28cba2b292a493..80d439607be06ab0f8c0e74a623ea1fee6107454 100644 (file)
@@ -1,6 +1,7 @@
 <?php
-require_once "common.php";
-require_once "header.php";
+require_once "inc/common.php";
+require_once "inc/connection.php";
+require_once "inc/header.php";
 
 $spamfilter_target_info = Array(
        "p"=>Array("short_text" => "usermsg", "long_text" => "User message"),
@@ -18,7 +19,7 @@ $spamfilter_target_info = Array(
 
 function spamfilter_targets_to_string($targets)
 {
-       GLOBAL $spamfilter_target_info;
+       global $spamfilter_target_info;
 
        $ret = '';
        for ($i = 0, $targs = ""; $i < strlen($targets); $i++)
@@ -35,7 +36,7 @@ function spamfilter_targets_to_string($targets)
 
 function spamfilter_targets_to_string_with_info($targets)
 {
-       GLOBAL $spamfilter_target_info;
+       global $spamfilter_target_info;
 
        $ret = '';
        for ($i = 0, $targs = ""; $i < strlen($targets); $i++)
@@ -52,7 +53,7 @@ function spamfilter_targets_to_string_with_info($targets)
 
 function spamfilter_target_name_to_char($name)
 {
-       GLOBAL $spamfilter_target_info;
+       global $spamfilter_target_info;
 
        foreach ($spamfilter_target_info as $char=>$e)
        {
@@ -81,57 +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 = 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
+                       /* get targets */
+                       $targets = []; // empty arrae
+                       foreach($_POST as $key => $value)
                        {
-                               if ($banlen_w)
-                                       $duration .= $banlen_w;
-                               if ($banlen_d)
-                                       $duration .= $banlen_d;
-                               if ($banlen_h)
-                                       $duration .= $banlen_h;
+                               if (substr($key, 0, 7) == "target_")
+                                       $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
                        }
-                       $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]");
+                       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 = 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]);
@@ -141,6 +151,7 @@ if (!empty($_POST))
                                else
                                        Message::Fail("Unable to remove spamfilter on $name: $rpc->error");
                        }
+       }
        
 }
 
@@ -148,7 +159,7 @@ $spamfilter = $rpc->spamfilter()->getAll();
 ?>
 
 <h4>Spamfilter Overview</h4><br>
-<p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
+<p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" <?php echo (current_user_can(PERMISSION_SPAMFILTER_ADD)) ? "" : "disabled"; ?>>
                        Add entry
        </button></p>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
@@ -257,7 +268,7 @@ $spamfilter = $rpc->spamfilter()->getAll();
                </div></div></div></div>
 
        
-       <table class="table table-responsive caption-top table-striped">
+       <table class="container-xxl table-sm table-responsive caption-top table-striped">
        <thead class="table-primary"><form action="spamfilter.php" method="post">
        <th><input type="checkbox" label='selectall' onClick="toggle_sf(this)" /></th>
        <th>Match Type</th>
@@ -278,14 +289,14 @@ $spamfilter = $rpc->spamfilter()->getAll();
                        echo "<td>".$sf->match_type."</td>";
                        echo "<td>".$sf->name."</td>";
                        echo "<td>".spamfilter_targets_to_string_with_info($sf->spamfilter_targets)."</td>";
-                       echo "<td>".$sf->ban_action."</td>";
+                       echo "<td><span class=\"badge rounded-pill badge-info\">".$sf->ban_action."</span></td>";
                        echo "<td>".$sf->ban_duration_string."</td>";
                        echo "<td>".$sf->reason."</td>";
                        echo "<td>".show_nick_only($sf->set_by)."</td>";
                        echo "<td>".$sf->set_at_string."</td>";
                        
                }
-       ?></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
+       ?></table><p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2" <?php echo (current_user_can(PERMISSION_SPAMFILTER_DEL)) ? "" : "disabled"; ?>>
        Delete selected
        </button></p>
        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
@@ -312,4 +323,4 @@ $spamfilter = $rpc->spamfilter()->getAll();
 </form></div></div>
 
 
-<?php require_once 'footer.php'; ?>
+<?php require_once 'inc/footer.php'; ?>