<?php
// cron для переноса статистики из мемкешед в базу
if (!isset($ab_version)) die('stop cron');
$ab_time_cron = $ab_config['time'];
for ($x = 0; $x < 2; $x++) {
$date = date('Ymd', $ab_time_cron);
clearstatcache();
$test = (int) @filesize(__DIR__.'/../data/counters/test_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/test_'.$date);
$auto = (int) @filesize(__DIR__.'/../data/counters/auto_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/auto_'.$date);
$post = (int) @filesize(__DIR__.'/../data/counters/post_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/post_'.$date);
$allow = (int) @filesize(__DIR__.'/../data/counters/allow_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/allow_'.$date);
$goodip = (int) @filesize(__DIR__.'/../data/counters/goodip_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/goodip_'.$date);
$local = (int) @filesize(__DIR__.'/../data/counters/local_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/local_'.$date);
$block = (int) @filesize(__DIR__.'/../data/counters/block_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/block_'.$date);
$fakes = (int) @filesize(__DIR__.'/../data/counters/fakes_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/fakes_'.$date);
$husers = (int) @filesize(__DIR__.'/../data/counters/husers_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/husers_'.$date);
$uusers = (int) @filesize(__DIR__.'/../data/counters/uusers_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/uusers_'.$date);
$google = (int) @filesize(__DIR__.'/../data/counters/google_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/google_'.$date);
$yandex = (int) @filesize(__DIR__.'/../data/counters/yandex_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/yandex_'.$date);
$bing = (int) @filesize(__DIR__.'/../data/counters/bing_'.$date) + 0;
@unlink(__DIR__.'/../data/counters/bing_'.$date);

$update = @$antibot_db->exec("UPDATE counters SET test = test + ".$test.", auto = auto + ".$auto.", post = post + ".$post.", allow = allow + ".$allow.", goodip = goodip + ".$goodip.", local = local + ".$local.", block = block + ".$block.", fakes = fakes + ".$fakes.", husers = husers + ".$husers.", uusers = uusers + ".$uusers.", google = google + ".$google.", yandex = yandex + ".$yandex.", bing = bing + ".$bing." WHERE date = '".$date."';");

$lastErrorMsg = $antibot_db->lastErrorMsg();

if ($antibot_db->changes() == 0) {
$add = @$antibot_db->exec("INSERT INTO counters (test, auto, post, allow, goodip, local, block, fakes, husers, uusers, google, yandex, bing, date) VALUES ('".$test."', '".$auto."', '".$post."', '".$allow."', '".$goodip."', '".$local."', '".$block."', '".$fakes."', '".$husers."', '".$uusers."', '".$google."', '".$yandex."', '".$bing."', '".$date."');");
}
$ab_time_cron = $ab_time_cron - 86400;
}

// удаление истекших правил:
$del = $antibot_db->exec("DELETE FROM ipv4rules WHERE expires < ".$ab_config['time'].";");
$del = $antibot_db->exec("DELETE FROM ipv6rules WHERE expires < ".$ab_config['time'].";");
$del = $antibot_db->exec("DELETE FROM rules WHERE expires < ".$ab_config['time'].";");

clearstatcache();
