In the abuse list, IP addresses can be whitelisted.
[gnucomo.git] / src / web / abuse.php
index 28eb373..03347bf 100644 (file)
@@ -9,7 +9,7 @@
 ***********************
 **      FILE NAME      : abuse.php
 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
-**      VERSION NUMBER : $Revision: 1.2 $
+**      VERSION NUMBER : $Revision: 1.3 $
 **
 **  DESCRIPTION      : Abuse list page
 **
 
 /*****************************
    $Log: abuse.php,v $
-   Revision 1.2  2007-01-11 13:44:29  arjen
+   Revision 1.3  2007-10-19 07:15:52  arjen
+   In the abuse list, IP addresses can be whitelisted.
+
+   Revision 1.2  2007/01/11 13:44:29  arjen
    Manually edit parameters.
    View logs from abusing IP addresses.
 
@@ -36,7 +39,7 @@
 
 ******************************/
 
-// RCSID = "$Id: abuse.php,v 1.2 2007-01-11 13:44:29 arjen Exp $";
+// RCSID = "$Id: abuse.php,v 1.3 2007-10-19 07:15:52 arjen Exp $";
 
 ini_set('include_path', '.:./classes:../phpclasses');
 
@@ -66,7 +69,7 @@ class abuse_list extends page
             {
                echo "$Source_IP is new.<br>";
                pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
-                                  "', '$Source_IP', '$abuse_points')");
+                                  "', '$Source_IP', '$abuse_points', '', NOW())");
             }
             else
             {
@@ -75,7 +78,7 @@ class abuse_list extends page
                echo $Source_IP . " will get " . $abuse_points . " abuse points.<br>";
                echo "Status was " . $abuse->status . "<br>";
                pg_exec($this->database, "UPDATE object_abuse SET nr_abuses='$abuse_points'" .
-                           " WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
+                           ", last_change=NOW() WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
 
                if ($abuse_points >= 6)
                {
@@ -87,6 +90,28 @@ class abuse_list extends page
 //select rawdata from log where logid in (select logid from log_abuse where source='');
 
          }
+         else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Whitelist')
+         {
+            $Source_IP = $_POST['source'];
+            echo "Whitelisting " . $_POST['source'] . "<br>\n";
+            $res = pg_exec($this->database, "SELECT * FROM object_abuse
+                                  WHERE objectid='". $_GET['oid'] ."' AND source='$Source_IP'");
+            $Status = $_POST['status'];
+            if (pg_numrows($res) == 0)
+            {
+               echo "$Source_IP is new.<br>";
+               pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
+                                  "', '$Source_IP', 0, '$Status', NOW())");
+            }
+            else
+            {
+               $abuse = pg_fetch_object($res, 0);
+               echo $Source_IP . " will be whitelisted.<br>";
+               echo "Status was " . $abuse->status . "<br>";
+               pg_exec($this->database, "UPDATE object_abuse SET status='$Status'" .
+                           ", last_change=NOW() WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
+            }
+         }
          else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Investigate')
          {
             //  Present a list of abuse addresses in one subnet
@@ -123,23 +148,28 @@ class abuse_list extends page
                                          . "' AND source << '$Subnet'");
             $abuse_points = 8;
             pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
-                                  "', '$Subnet', '$abuse_points', 'dropped')");
+                                  "', '$Subnet', '$abuse_points', 'dropped', NOW())");
          }
 
          if (!empty($_GET['src']))
          {
             $oid = $_GET['oid'];
             $src = $_GET['src'];
-            $res = pg_exec($this->database, "SELECT logid FROM log_abuse WHERE objectid=$oid AND source <<= '$src'");
+            $res = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
+                                     (SELECT logid FROM log_abuse WHERE objectid=$oid AND source <<= '$src')
+                                          ORDER BY object_timestamp");
             echo "<table>";
-            echo "<tr><th>Abused log entry</th></tr>";
+            echo "<tr><th>Time</th><th>Service</th><th>Abused log entry</th></tr>";
             for ($row = 0; $row < pg_numrows($res); $row++)
             {
-               $logid = pg_fetch_object($res, $row);
+               $log = pg_fetch_object($res, $row);
                //$log = pg_fetch_object(pg_exec($this->database, "SELECT rawdata FROM log WHERE logid=" . $logid->logid), 0);
                echo "<tr><td>";
-               //echo $log->rawdata;
-               echo $logid->logid;
+               echo $log->object_timestamp;
+               echo "</td><td>";
+               echo $log->servicecode;
+               echo "</td><td>";
+               echo $log->rawdata;
                echo "</td></tr>";
             }
             echo "</table>";
@@ -149,6 +179,8 @@ class abuse_list extends page
             echo "<form method='post'>";
             echo "Report <input type='submit' name='ACTION' value='Abuse'>";
             echo " for IP address <input type='text' name='source'>";
+            echo " or <input type='submit' name='ACTION' value='Whitelist'>";
+            echo " with status <input type='text' name='status'>";
             echo "</form>"; 
    
             echo "<form method='post'>";
@@ -175,7 +207,7 @@ class abuse_list extends page
                echo "</td><td>";
                echo $abuse->status;
                echo "</td><td>";
-               echo $abuse->last_changed;
+               echo $abuse->last_change;
                echo "</td></tr>";
             }
             echo "</table>";