--- httpbl.module.orig 2009-09-19 11:42:46.000000000 -0500 +++ httpbl.module 2009-09-19 12:58:04.000000000 -0500 @@ -191,15 +191,21 @@ function httpbl_check() { $result = HTTPBL_LIST_SAFE; } - // Cache results + // Cache results - Use Blacklist offset settings (default 1 year) + // or Greylist offset settings (default 1 day) if ($cache) { - _httpbl_cache_set($ip, $result, 7200); + if ($result == HTTPBL_LIST_BLACK) { + _httpbl_cache_set($ip, $result, variable_get('httpbl_blacklist_offset', 31536000)); + } + else if ($result == HTTPBL_LIST_GREY){ + _httpbl_cache_set($ip, $result, variable_get('httpbl_greylist_offset', 86400)); + } } - } - // No result, safe + } + // No result, safe - with offset settings (default 3 hours) else { if ($cache) { - _httpbl_cache_set($ip, HTTPBL_LIST_SAFE, 10800); + _httpbl_cache_set($ip, HTTPBL_LIST_SAFE, variable_get('httpbl_safe_offset', 10800)); } $result = HTTPBL_LIST_SAFE; } @@ -305,6 +311,33 @@ function httpbl_admin_settings() { '#description' => t('Whether to enable database-based caching. Note that when this is disabled, IPs that fail the session whitelist test cannot be banned. The Drupal access table allows visitors to be blocked in the early stages of the bootstrap.'), ); + $cache_period = drupal_map_assoc(array(10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval'); + $form['advanced']['httpbl_safe_offset'] = array( + '#type' => 'select', + '#title' => t('Safe Visitor Cache Expires in...'), + '#default_value' => variable_get('httpbl_safe_offset', 10800), + '#options' => $cache_period, + '#description' => t('How long to keep safe or white-listed IPs in cache.'), + ); + + $cache_period2 = drupal_map_assoc(array(43200, 86400, 172800, 259200, 604800, 1209600, 1814400, 2419200), 'format_interval'); + $form['advanced']['httpbl_greylist_offset'] = array( + '#type' => 'select', + '#title' => t('Grey Listed Visitor Cache Expires in...'), + '#default_value' => variable_get('httpbl_greylist_offset', 86400), + '#options' => $cache_period2, + '#description' => t('How long to keep grey-listed IPs in cache.'), + ); + + $cache_period3 = drupal_map_assoc(array(604800, 1209600, 1814400, 2419200, 7257600, 15724800, 31536000, 63072000, 94608000), 'format_interval'); + $form['advanced']['httpbl_blacklist_offset'] = array( + '#type' => 'select', + '#title' => t('Black Listed Visitor Cache Expires in...'), + '#default_value' => variable_get('httpbl_blacklist_offset', 31536000), + '#options' => $cache_period3, + '#description' => t('How long to keep black-listed IPs in cache (and also banned in Access table, when applicable).'), + ); + return system_settings_form($form); } @@ -547,9 +580,10 @@ function httpbl_request_whitelist_valida if ($form_state['values']['block'] || $form_state['values']['leave']) { if (variable_get('httpbl_cache', HTTPBL_CACHE_OFF)) { - _httpbl_cache_update($ip, 1, 86400); - watchdog('httpbl', '%ip failed session whitelist request, blacklisted for 24 hours.', array('%ip' => $ip), WATCHDOG_WARNING, $iplink); - print t('Whitelist request failed; your IP has been blacklisted for 24 hours.'); + _httpbl_cache_update($ip, HTTPBL_LIST_BLACK, variable_get('httpbl_blacklist_offset', 31536000)); + $return_date = format_interval(variable_get('httpbl_blacklist_offset', 31536000), $granularity = 2, $langcode = NULL); + watchdog('httpbl', '%ip failed session whitelist request, blacklisted for %return_date.', array('%ip' => $ip, '%return_date' => $return_date), WATCHDOG_WARNING, $iplink); + print t('Whitelist request failed; your IP has been blacklisted for ' . $return_date .'.'); exit(); } else {