You are here

function httpbl_cron in http:BL 7

Same name and namespace in other branches
  1. 8 httpbl.module \httpbl_cron()
  2. 5 httpbl.module \httpbl_cron()
  3. 6.2 httpbl.module \httpbl_cron()
  4. 6 httpbl.module \httpbl_cron()

Implementation of hook_cron().

Cleans old results from the cache table and also Drupal's blocked_ips table if appropriate.

File

./httpbl.module, line 370
Implementation of http:BL for Drupal. It provides IP-based blacklisting through http:BL and allows linking to a honeypot.

Code

function httpbl_cron() {

  // Only continue when caching is enabled
  if (variable_get('httpbl_cache', HTTPBL_CACHE_OFF)) {
    if (variable_get('httpbl_cache', HTTPBL_CACHE_OFF) == HTTPBL_CACHE_DBDRUPAL) {

      // Also check status so that we do not accidentally delete the site's custom access rules.
      db_delete('blocked_ips')
        ->where('ip IN (SELECT hostname FROM {httpbl} WHERE status > 0 AND expire <= :time)', array(
        ':time' => REQUEST_TIME,
      ))
        ->execute();
    }
    db_delete('httpbl')
      ->condition('expire', REQUEST_TIME, '<=')
      ->execute();
  }
}