View source
<?php
define('BB2_CWD', './sites/all/libraries');
function badbehavior_help($path, $arg) {
$output = '';
switch ($path) {
case "admin/reports/badbehavior":
$output .= '<p>' . t("The Bad Behavior module examines HTTP requests of visits to your web site, and any suspicious requests are logged for later review. The suspicious visit is shown an error page with instructions on how to view the site without triggering the bad behavior error message.") . '</p>';
break;
}
return $output;
}
function badbehavior_perm() {
return array(
'administer bad behavior',
'bypass bad behavior protection',
);
}
function badbehavior_menu() {
$items['admin/settings/badbehavior'] = array(
'title' => 'Bad Behavior',
'description' => 'Configure automatic spam blocking for your site.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'badbehavior_settings_form',
),
'access arguments' => array(
'administer bad behavior',
),
'file' => 'badbehavior.admin.inc',
);
$items['admin/reports/badbehavior'] = array(
'title' => 'Bad Behavior',
'description' => 'Examine the spam blocking logs for your web site.',
'page callback' => 'badbehavior_overview',
'access arguments' => array(
'administer bad behavior',
),
'file' => 'badbehavior.admin.inc',
);
$items['admin/reports/badbehavior/event'] = array(
'title' => 'Details',
'page callback' => 'badbehavior_event',
'access arguments' => array(
'administer bad behavior',
),
'type' => MENU_CALLBACK,
'file' => 'badbehavior.admin.inc',
);
return $items;
}
function badbehavior_boot() {
if (!$GLOBALS['user']->uid) {
badbehavior_start_badbehavior();
}
}
function badbehavior_init() {
if ($GLOBALS['user']->uid) {
badbehavior_start_badbehavior();
}
}
function badbehavior_start_badbehavior() {
if (function_exists('user_access') && user_access('bypass bad behavior protection')) {
return;
}
elseif (badbehavior_load_includes()) {
bb2_install();
bb2_start(bb2_read_settings());
}
}
function badbehavior_load_includes($files = array()) {
static $included;
if (!isset($included)) {
$included = TRUE;
array_unshift($files, 'core', 'version');
}
foreach ($files as $file) {
$file = BB2_CWD . "/bad-behavior/{$file}.inc.php";
if (is_file($file)) {
require_once $file;
}
else {
return FALSE;
}
}
return TRUE;
}
function bb2_db_date() {
return gmdate('Y-m-d H:i:s');
}
function bb2_db_affected_rows() {
return db_affected_rows();
}
function bb2_db_escape($string) {
return db_escape_string($string);
}
function bb2_db_num_rows($result) {
if ($result != FALSE) {
return count($result);
}
return 0;
}
function badbehavior_db_errortrap($errno, $string) {
}
function bb2_db_query($query) {
set_error_handler('badbehavior_db_errortrap');
$result = db_query($query);
restore_error_handler();
if ($result == FALSE) {
return FALSE;
}
return db_affected_rows();
}
function bb2_db_rows($result) {
return $result;
}
function bb2_email() {
return variable_get('badbehavior_mail', variable_get('site_mail', ini_get('sendmail_from')));
}
function bb2_write_settings($settings) {
return;
}
function bb2_read_settings() {
$logging = variable_get('badbehavior_logging', 1);
return array(
'log_table' => '{bad_behavior_log}',
'display_stats' => FALSE,
'strict' => variable_get('badbehavior_strict', 0),
'verbose' => $logging == 'verbose',
'logging' => !empty($logging),
'httpbl_key' => variable_get('badbehavior_httpbl_key', ''),
'httpbl_threat' => '25',
'httpbl_maxage' => '30',
'offsite_forms' => FALSE,
);
}
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);
}
}
function bb2_relative_path() {
global $base_path;
return $base_path;
}
function bb2_convertdate($bbdate) {
$timestamp = strtotime($bbdate . ' UTC');
return format_date($timestamp, 'small');
}