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.
*/
-// $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');
$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");
}
}
// 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();
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')");
}
}