--- badbehavior.module.orig 2006-04-13 13:01:55.000000000 -0400 +++ badbehavior.module 2006-08-30 20:46:08.000000000 -0400 @@ -1,35 +1,10 @@ t('Response'), 'field' => 'w.http_response'), array('data' => t('Reason'), 'field' => 'w.denied_reason'), array('data' => t('Date'), 'field' => 'w.date', 'sort' => 'desc'), array('data' => t('IP'), 'field' => 'w.ip'), - array('data' => t('Referrer'), 'field' => 'w.http_referrer'), - array('data' => t('Agent'), 'field' => 'w.http_user_agent', 'colspan' => 2) + array('data' => t('Agent'), 'field' => 'w.user_agent', 'colspan' => 2) ); - $sql = 'SELECT w.* FROM {bad_behavior_log} w ' . tablesort_sql($header); + $sql = "SELECT w.* FROM {bad_behavior_log} w WHERE w.key != '00000000' " . tablesort_sql($header); $result = pager_query($sql, 50); + require_once(BB2_CWD . '/bad-behavior/responses.inc.php'); + while ($behave = db_fetch_object($result)) { - $behave->localdate = bb_convertdate($behave->date); + $response = bb2_get_response($behave->key); + if ($response['response'] == '200') + continue; + $behave->localdate = bb2_convertdate($behave->date); $rows[] = array('data' => array( // Cells - $behave->denied_reason, + $response['response'], + $response['log'], $behave->date, $behave->ip, - $behave->http_referrer, - $behave->http_user_agent, + $behave->user_agent, l(t('details'), "admin/logs/badbehavior/event/$behave->id") ) ); } if (!$rows) { - $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7')); - } - - $pager = theme('pager', NULL, 50, 0); - if (!empty($pager)) { - $rows[] = array(array('data' => $pager, 'colspan' => '7')); + $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '6')); } - $output = theme('table', $header, $rows); + $output = theme('table', $header, $rows) . theme('pager', NULL, 50, 0); print theme('page', $output); } @@ -102,22 +77,25 @@ function badbehavior_overview() { function badbehavior_event($id) { $output = ''; $result = db_query('SELECT w.* FROM {bad_behavior_log} w WHERE w.id = %d', $id); + + require_once(BB2_CWD . '/bad-behavior/responses.inc.php'); + if ($behave = db_fetch_object($result)) { - $behave->localdate = bb_convertdate($behave->date); + $response = bb2_get_response($behave->key); + $behave->localdate = bb2_convertdate($behave->date); $output .= ''; $output .= ' '; $output .= ' '; $output .= ' '; $output .= ' '; - $output .= ' '; $output .= ' '; $output .= ' '; - $output .= ' '; - $output .= ' '; + $output .= ' '; $output .= ' '; $output .= ' '; - $output .= ' '; - $output .= ' '; + $output .= ' '; + $output .= ' '; + $output .= ' '; $output .= '
'. t('IP Addr') .'' . $behave->ip . '
'. t('Hostname') .'' . gethostbyaddr($behave->ip) . ' (' . l('whois','http://www.whois.sc/'.$behave->ip) . ')
'. t('Date') .'' . $behave->date . '
'. t('Request type') .'' . $behave->request_method . '
'. t('Host') .'' . $behave->http_host . '
'. t('URI') .'' . $behave->request_uri . '
'. t('Protocol') .'' . $behave->server_protocol . '
'. t('Referrer') .'' . $behave->http_referer . '
'. t('User Agent') .'' . $behave->http_user_agent . '
'. t('User Agent') .'' . $behave->user_agent . '
'. t('Headers') .'' . $behave->http_headers . '
'. t('Request Entity') .'' . $behave->request_entity . '
'. t('Denied Reason') .'' . $behave->denied_reason . '
'. t('Response') .'' . $behave->http_response . '
'. t('Denied Reason') .'' . $response['log'] . '
'. t('Explanation') .'' . $response['explanation'] . '
'. t('Response') .'' . $response['response'] . '
'; } print theme('page', $output); @@ -129,100 +107,118 @@ function badbehavior_perm() { function badbehavior_settings() { $form['badbehavior_email'] = array( - '#type' => 'textfield', - '#title' => t('Administrator Email'), - '#default_value' => variable_get('badbehavior_email','badbots@ioerror.us'), - '#size' => 50, - '#maxlength' => 50, - '#description' => t('Administrator email address for blocked users to contact to gain access'), - ); - $form['log_settings'] = array( - '#type' => 'fieldset', - '#title' => t('Log Settings'), - ); - - $form['log_settings']['badbehavior_logging_enable'] = array( - '#type' => 'radios', - '#title' => 'Enable Logging', - '#default_value' => variable_get('bedbehavior_logging_enable',1), - '#options' => array(t('Disabled'),t('Enabled')), - '#description' => t('Enables or disables logging of spam activity'), - ); - - $form['log_settings']['badbehavior_verbose_logging_enable'] = array( - '#type' => 'radios', - '#title' => 'Enable Verbose Logging', - '#default_value' => variable_get('badbehavior_verbose_logging_enable',0), - '#options' => array(t('Disabled'), - t('Enabled')), - '#description' => t('Enables or disables verbose logging which includes all requests, not just failed ones '), - ); - - $form['log_settings']['badbehavior_logging_duration'] = array( - '#type' => 'textfield', - '#title' => t('Logging Duration'), - '#default_value' => variable_get('badbehavior_logging_duration',7), - '#size' => 6, - '#maxlength' => 6, - '#description' => t('Number of days to hold logs for'), - ); + '#type' => 'textfield', + '#title' => t('Administrator Email'), + '#default_value' => variable_get('badbehavior_email','badbots@ioerror.us'), + '#size' => 50, + '#maxlength' => 50, + '#description' => t('Administrator email address for blocked users to contact to gain access'), + ); + $form['badbehavior_strict_mode_enable'] = array( + '#type' => 'radios', + '#title' => 'Enable Strict Mode', + '#default_value' => variable_get('badbehavior_strict_mode_enable',0), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Enable strict checking (blocks more spam but may block some people)'), + ); + $form['badbehavior_verbose_logging_enable'] = array( + '#type' => 'radios', + '#title' => 'Enable Verbose Logging', + '#default_value' => variable_get('badbehavior_verbose_logging_enable',0), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Enables or disables verbose logging which includes all requests, not just failed ones'), + ); return $form; } -function badbehavior_init() { - define('WP_BB_CWD', dirname(__FILE__)); +// Return current time in the format preferred by your database. +function bb2_db_date() { + return gmdate('Y-m-d H:i:s'); // Example is MySQL format +} - global $wp_bb_approved; - global $wp_bb_db_failure; - global $wp_bb_remote_addr; - global $wp_bb_request_method; - global $wp_bb_http_host; - global $wp_bb_request_uri; - global $wp_bb_server_protocol; - global $wp_bb_http_referer; - global $wp_bb_http_user_agent; - global $wp_bb_server_signature; - global $wp_bb_headers; - global $wp_bb_request_entity; - global $wp_bb_http_headers_mixed; - global $wp_bb_logging; - global $wp_bb_verbose_logging; - global $wp_bb_logging_duration; - global $wp_bb_email; - global $wp_bb_whitelist_ip_ranges; - global $wp_bb_whitelist_user_agents; - - $wp_bb_logging = variable_get('badbehavior_logging_enable', 1); - $wp_bb_verbose_logging = variable_get('badbehavior_verbose_logging_enable', 0); - $wp_bb_logging_duration = variable_get('badbehavior_logging_duration', 7); - $wp_bb_email = variable_get('badbehavior_email',"badbots@ioerror.us"); - - define('WP_BB_LOG', '{bad_behavior_log}'); - - if (file_exists(WP_BB_CWD . "/bad-behavior-core.php")) { - require_once(WP_BB_CWD . "/bad-behavior-core.php"); - } else { - watchdog('badbehavior', t('The third-party bad-behavior files are not installed. Please consult badbehavior/README.txt for details.'), WATCHDOG_ERROR); - } +// Return affected rows from most recent query. +function bb2_db_affected_rows() { + return db_affected_rows(); } -function bb_convertdate($bbdate) { - $timestamp = strtotime($bbdate. ' UTC'); - return format_date($timestamp,'small'); +// Escape a string for database usage +function bb2_db_escape($string) { + return db_escape_string($string); +} + +// Return the number of rows in a particular query. +function bb2_db_num_rows($result) { + if ($result != FALSE) + return count($result); + return 0; } -function wp_bb_date() { - return gmdate('Y-m-d H:i:s'); +function badbehavior_db_errortrap($errno, $string) { } -function wp_bb_db_query($query) { +// Run a query and return the results, if any. +function bb2_db_query($query) { set_error_handler('badbehavior_db_errortrap'); $result = db_query($query); restore_error_handler(); - if ($result == FALSE) { - return $result; - } + if ($result == FALSE) + return FALSE; return db_affected_rows(); } -?> \ No newline at end of file + +// Return all rows in a particular query. +function bb2_db_rows($result) { + return $result; +} + +// Return emergency contact email address. +function bb2_email() { + return variable_get('badbehavior_email',"badbots@ioerror.us"); +} + +// write settings to database +function bb2_write_settings($settings) { + return; +} + +// retrieve settings from database +function bb2_read_settings() { + return array( + 'log_table' => 'bad_behavior_log', + 'strict' => variable_get('badbehavior_strict_checking_enable', 0), + 'verbose' => variable_get('badbehavior_verbose_logging_enable', 0)); +} + +// installation +function bb2_install() { + if (variable_get('badbehavior_db_installed', 0) != BB2_VERSION) { + bb2_db_query(bb2_table_structure('bad_behavior_log')); + variable_set('badbehavior_db_installed', BB2_VERSION); + } +} + +// Return the top-level relative path of wherever we are (for cookies) +function bb2_relative_path() { + global $base_path; + return $base_path; +} + +function badbehavior_init() { + if (file_exists(BB2_CWD . '/bad-behavior/core.inc.php') && file_exists(BB2_CWD . '/bad-behavior/version.inc.php')) { + require_once(BB2_CWD . '/bad-behavior/version.inc.php'); + require_once(BB2_CWD . '/bad-behavior/core.inc.php'); + bb2_install(); + bb2_start(bb2_read_settings()); + } + else { + watchdog('badbehavior', t('The third-party bad-behavior files are not installed. Please consult badbehavior/README.txt for details.'), WATCHDOG_ERROR); + } +} + +function bb2_convertdate($bbdate) { + $timestamp = strtotime($bbdate. ' UTC'); + return format_date($timestamp,'small'); +} + +?>