Cleanup abuse records only for subnets smaller than /16.
authorarjen <arjen>
Thu, 24 Mar 2011 09:49:20 +0000 (09:49 +0000)
committerarjen <arjen>
Thu, 24 Mar 2011 09:49:20 +0000 (09:49 +0000)
src/gcm_daemon/gcm_maintenance.php

index 0bbb56a..a36c4af 100755 (executable)
                    Andromeda Technology & Automation
 
  $Log: gcm_maintenance.php,v $
- Revision 1.1  2007-12-12 09:06:21  arjen
+ Revision 1.2  2011-03-24 09:49:20  arjen
+ Cleanup abuse records only for subnets smaller than /16.
+
+ Revision 1.1  2007/12/12 09:06:21  arjen
  Added a new script gcm_maintenance.php to cleanup the database
  and check referential integrity. Purging old log entries is
  removed from the gcm_daemon script.
@@ -21,7 +24,7 @@
 
 */
 
-// $Id: gcm_maintenance.php,v 1.1 2007-12-12 09:06:21 arjen Exp $
+// $Id: gcm_maintenance.php,v 1.2 2011-03-24 09:49:20 arjen Exp $
 
 ini_set('include_path', '.:./classes:../phpclasses');
 ini_set('html_errors', 'false');
@@ -105,34 +108,34 @@ if ($dbms->have_db_connection() == "FALSE")
 
 
    $abuse_result = $dbms->query("select source, nr_abuses, masklen(source) from object_abuse
-                                 where status='dropped' and masklen(source)=32 and objectid=1 order by source");
+                                 where (status='dropped' or status='') and masklen(source)>16 and objectid=11 order by source");
    for ($ab = 0; $ab < $dbms->num_rows($abuse_result); $ab++)
    {
       $logentries = 0;
       $abuse = $dbms->fetch_object($abuse_result, $ab);
       $nr_abuses = $abuse->nr_abuses;
-      $log_res = $dbms->query("select logid from log_abuse where source='" . $abuse->source . "' and objectid=1");
+      $log_res = $dbms->query("select logid from log_abuse where source='" . $abuse->source . "' and objectid=11");
 
       if ($dbms->num_rows($log_res) != $nr_abuses)
       {
          echo "Mismatch in nr of abuses. Corrected.\n";
          $dbms->query("update object_abuse set nr_abuses=" . $dbms->num_rows($log_res) .
-                      " where source='" . $abuse->source . "' and objectid=1");
+                      " where source='" . $abuse->source . "' and objectid=11");
       }
       if ($dbms->num_rows($log_res) == 0)
       {
          echo "  Removing ", $abuse->source, "\n";
-         $dbms->query("delete from object_abuse where source='". $abuse->source . "' and objectid=1");
+         $dbms->query("delete from object_abuse where source='". $abuse->source . "' and objectid=11");
       }
       else
       {
          $logref_res = $dbms->query("select logid from log where logid in
-                                    (select logid from log_abuse where source='" . $abuse->source . "' and objectid=1)");
+                                    (select logid from log_abuse where source='" . $abuse->source . "' and objectid=11)");
          $logentries = $dbms->num_rows($logref_res);
          if ($logentries == 0)
          {
             echo "All references to log entries are lost. Purging log_abuse table.\n";
-            $dbms->query("delete from log_abuse where source='" . $abuse->source . "' and objectid=1");
+            $dbms->query("delete from log_abuse where source='" . $abuse->source . "' and objectid=11");
             
          }
       }
@@ -195,7 +198,7 @@ function purge_old_logs($purge_date)
 
    //  Clean up abuses that are left without reference to the log.
 
-   $r = $dbms->query("select source from log_abuse where logid in
+   $r = $dbms->query("select source from log_abuse where masklen(source) > 16 and logid in
                          (select logid from gcm_deamon_old_log) group by source");
    echo "Abusing IP addresses that may be affected:\n";
    $abusers = array();
@@ -215,7 +218,7 @@ function purge_old_logs($purge_date)
       if ($c->count == 0)
       {
          echo "Cleaning up abusing address $src.\n";
-         $dbms->query("delete from object_abuse where source='$src'");
+         $dbms->query("delete from object_abuse where source='$src' and (status='' or status='dropped')");
       }
    }