TightURL

TightURL Git Source Tree

Root/bad-behavior/bad-behavior-generic.php

1<?php
2/*
3Bad Behavior - detects and blocks unwanted Web accesses
4Copyright (C) 2005-2006 Michael Hampton
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11As a special exemption, you may link this program with any of the
12programs listed below, regardless of the license terms of those
13programs, and distribute the resulting program, without including the
14source code for such programs: ExpressionEngine
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25Please report any problems to badbots AT ioerror DOT us
26*/
27
28###############################################################################
29###############################################################################
30
31define('BB2_CWD', dirname(__FILE__));
32
33// Settings you can adjust for Bad Behavior.
34// Most of these are unused in non-database mode.
35$bb2_settings_defaults = array(
36    'log_table' => 'bad_behavior',
37    'display_stats' => true,
38    'strict' => false,
39    'verbose' => false,
40    'logging' => true,
41    'httpbl_key' => '',
42    'httpbl_threat' => '25',
43    'httpbl_maxage' => '30',
44);
45
46// Bad Behavior callback functions.
47
48// Return current time in the format preferred by your database.
49function bb2_db_date() {
50    return gmdate('Y-m-d H:i:s'); // Example is MySQL format
51}
52
53// Return affected rows from most recent query.
54function bb2_db_affected_rows() {
55    return false;
56}
57
58// Escape a string for database usage
59function bb2_db_escape($string) {
60    // return mysql_real_escape_string($string);
61    return $string; // No-op when database not in use.
62}
63
64// Return the number of rows in a particular query.
65function bb2_db_num_rows($result) {
66    if ($result !== FALSE)
67        return count($result);
68    return 0;
69}
70
71// Run a query and return the results, if any.
72// Should return FALSE if an error occurred.
73// Bad Behavior will use the return value here in other callbacks.
74function bb2_db_query($query) {
75    return FALSE;
76}
77
78// Return all rows in a particular query.
79// Should contain an array of all rows generated by calling mysql_fetch_assoc()
80// or equivalent and appending the result of each call to an array.
81function bb2_db_rows($result) {
82    return $result;
83}
84
85// Return emergency contact email address.
86function bb2_email() {
87    // return "example@example.com"; // You need to change this.
88    return "badbots@ioerror.us"; // You need to change this.
89}
90
91// retrieve settings from database
92// Settings are hard-coded for non-database use
93function bb2_read_settings() {
94    global $bb2_settings_defaults;
95    return $bb2_settings_defaults;
96}
97
98// write settings to database
99function bb2_write_settings($settings) {
100    return false;
101}
102
103// installation
104function bb2_install() {
105    return false;
106}
107
108// Screener
109// Insert this into the <head> section of your HTML through a template call
110// or whatever is appropriate. This is optional we'll fall back to cookies
111// if you don't use it.
112function bb2_insert_head() {
113    global $bb2_javascript;
114    echo $bb2_javascript;
115}
116
117// Display stats? This is optional.
118function bb2_insert_stats($force = false) {
119    $settings = bb2_read_settings();
120
121    if ($force || $settings['display_stats']) {
122        $blocked = bb2_db_query("SELECT COUNT(*) FROM " . $settings['log_table'] . " WHERE `key` NOT LIKE '00000000'");
123        if ($blocked !== FALSE) {
124            echo sprintf('<p><a href="http://www.bad-behavior.ioerror.us/">%1$s</a> %2$s <strong>%3$s</strong> %4$s</p>', __('Bad Behavior'), __('has blocked'), $blocked[0]["COUNT(*)"], __('access attempts in the last 7 days.'));
125        }
126    }
127}
128
129// Return the top-level relative path of wherever we are (for cookies)
130// You should provide in $url the top-level URL for your site.
131function bb2_relative_path() {
132    //$url = parse_url(get_bloginfo('url'));
133    //return $url['path'] . '/';
134    return '/';
135}
136
137// Calls inward to Bad Behavor itself.
138require_once(BB2_CWD . "/bad-behavior/version.inc.php");
139require_once(BB2_CWD . "/bad-behavior/core.inc.php");
140bb2_install(); // FIXME: see above
141
142bb2_start(bb2_read_settings());
143
144?>
145

Archive Download this file

Branches