Fix: filesystem report
[gnucomo.git] / src / gcm_daemon / gcm_daemon.php
index a9da99b..38e0d3a 100755 (executable)
@@ -484,7 +484,13 @@ function match_log_patterns($logstart)
                //echo "Recording abuse for address ", $srv_pat->argument, "\n  Log entry:\n  ";
                //echo $logentry->rawdata, "\n  Pattern:\n  ", $srv_pat->pattern, "\n\n";
 
-               if (record_abuse($logentry->logid, $logentry->objectid, $srv_pat->argument, 1) >= 32)
+               $nr_abuses = record_abuse($logentry->logid, $logentry->objectid, $srv_pat->argument, 1);
+               if ($nr_abuses < 0)
+               {
+                  echo "ERROR in recording abuse for address ", $srv_pat->argument, "\n  Log entry:\n  ";
+                  echo $logentry->rawdata, "\n  Pattern:\n  ", $srv_pat->pattern, "\n\n";
+               }
+               if ($nr_abuses >= 32)
                {
                   $source_ip = gethostbyname($srv_pat->argument);
                   $notif = 'abuses exceeded';
@@ -556,36 +562,43 @@ function record_abuse($logid, $objectid, $sourceip, $points)
 
    $abres = $dbms->query("SELECT * FROM object_abuse WHERE objectid='$objectid' AND source='$sourceip'");
 
-   if (pg_numrows($abres) == 0 && $points > 0)
+   if ($abres == false)
    {
-      //echo "$sourceip is new.\n";
-      $dbms->query("INSERT INTO object_abuse VALUES ('$objectid', '$sourceip', '$points', '', NOW())");
-      $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
+      $abuse_points = -1;   // return an error
    }
-   else if (pg_numrows($abres) != 0)
+   else
    {
-      $abuse = $dbms->fetch_object($abres, 0);
-      if ($abuse->status == '' || $abuse->status == 'dropped')
+      if (pg_numrows($abres) == 0 && $points > 0)
+      {
+         //echo "$sourceip is new.\n";
+         $dbms->query("INSERT INTO object_abuse VALUES ('$objectid', '$sourceip', '$points', '', NOW())");
+         $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
+      }
+      else if (pg_numrows($abres) != 0)
       {
-         $abuse_points = $abuse->nr_abuses + $points;
-         if ($abuse_points < 0)
+         $abuse = $dbms->fetch_object($abres, 0);
+         if ($abuse->status == '' || $abuse->status == 'dropped')
          {
-            $abuse_points = 0;
-         }
-         //echo $sourceip . " will get " . $abuse_points . " abuse points, ";
-         //echo "Status was " . $abuse->status . "\n";
-         $dbms->query("UPDATE object_abuse SET nr_abuses='$abuse_points'" .
-                     ", last_change=NOW() WHERE objectid='$objectid' AND source='$sourceip'");
+            $abuse_points = $abuse->nr_abuses + $points;
+            if ($abuse_points < 0)
+            {
+               $abuse_points = 0;
+            }
+            //echo $sourceip . " will get " . $abuse_points . " abuse points, ";
+            //echo "Status was " . $abuse->status . "\n";
+            $dbms->query("UPDATE object_abuse SET nr_abuses='$abuse_points'" .
+                        ", last_change=NOW() WHERE objectid='$objectid' AND source='$sourceip'");
 
-         if ($points > 0)
-         {
-            $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
-         }
-         if ($abuse_points >= 32)
-         {
-            //echo "      BLOCK IP adrress $sourceip on the firewall.\n";
-            $dbms->query("UPDATE object_abuse SET status='dropped'" .
-                     " WHERE objectid='$objectid' AND source='$sourceip'");
+            if ($points > 0)
+            {
+               $dbms->query("INSERT INTO log_abuse VALUES ('$logid', '$objectid', '$sourceip')");
+            }
+            if ($abuse_points >= 32)
+            {
+               //echo "      BLOCK IP adrress $sourceip on the firewall.\n";
+               $dbms->query("UPDATE object_abuse SET status='dropped'" .
+                        " WHERE objectid='$objectid' AND source='$sourceip'");
+            }
          }
       }
    }