-
Notifications
You must be signed in to change notification settings - Fork 1
/
bad-behavior-fluxbb.php
executable file
·176 lines (145 loc) · 5.14 KB
/
bad-behavior-fluxbb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*
http://www.bad-behavior.ioerror.us/
Bad Behavior - detects and blocks unwanted Web accesses
Copyright (C) 2005 Michael Hampton
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// This file is the entry point for Bad Behavior.
if (!defined('PUN_ROOT')) exit;
define('BB2_CWD', dirname(__FILE__));
// Settings you can adjust for Bad Behavior.
// Most of these are unused in non-database mode.
$bb2_settings_defaults = array(
'log_table' => $db->prefix.'bad_behavior',
'display_stats' => true,
'strict' => false,
'verbose' => false,
'logging' => true,
'httpbl_key' => '',
'httpbl_threat' => '25',
'httpbl_maxage' => '30',
'offsite_forms' => false,
'eu_cookie' => false,
'reverse_proxy' => false,
'reverse_proxy_header' => 'X-Forwarded-For',
'reverse_proxy_addresses' => array(),
);
// Bad Behavior callback functions.
require_once(BB2_CWD . "/bad-behavior-mysql.php");
// 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
}
// Return affected rows from most recent query.
function bb2_db_affected_rows($result) {
global $db;
return $db->affected_rows();
}
// Escape a string for database usage
function bb2_db_escape($string) {
global $db;
return $db->escape($string);
}
// Return the number of rows in a particular query.
function bb2_db_num_rows($result) {
global $db;
return $db->num_rows($result);
}
// Run a query and return the results, if any.
// Should return FALSE if an error occurred.
// Bad Behavior will use the return value here in other callbacks.
function bb2_db_query($query) {
global $db;
return $db->query($query);
}
// Return all rows in a particular query.
// Should contain an array of all rows generated by calling mysql_fetch_assoc()
// or equivalent and appending the result of each call to an array.
function bb2_db_rows($result) {
global $db;
$return = array();
while ($data = $db->fetch_assoc($result))
$return[] = $data;
return $return;
}
// Return emergency contact email address.
function bb2_email() {
global $pun_config;
return $pun_config['o_webmaster_email'];
}
// retrieve settings from database
// Settings are hard-coded for non-database use
function bb2_read_settings() {
global $bb2_settings_defaults, $pun_config, $db;
// It's installed
if (isset($pun_config['o_badbehavior_display_stats']))
{
return array_merge($bb2_settings_defaults, array(
'log_table' => $db->prefix.'bad_behavior',
'display_stats' => (bool)$pun_config['o_badbehavior_display_stats'],
'verbose' => (bool)$pun_config['o_badbehavior_verbose'],
'strict' => (bool)$pun_config['o_badbehavior_strict'],
'is_installed' => true,
));
}
else
return $bb2_settings_defaults;
}
// write settings to database
function bb2_write_settings($settings, $install = false) {
global $db;
while (list($key, $input) = @each($settings))
{
if ($key == 'log_table')
continue;
$input = intval($input);
if ($install)
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_badbehavior_'.$db->escape($key).'\', '.$input.')') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
else
$db->query('UPDATE '.$db->prefix.'config SET conf_value='.$input.' WHERE conf_name=\'o_badbehavior_'.$db->escape($key).'\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
}
// Regenerate the config cache
require_once PUN_ROOT.'include/cache.php';
generate_config_cache();
}
// installation
function bb2_install() {
$settings = bb2_read_settings();
if (!isset($settings['is_installed']))
{
bb2_db_query(bb2_table_structure($settings['log_table']));
bb2_write_settings($settings, true);
}
}
// Display stats?
function bb2_insert_stats($force = false) {
global $bb2_stats;
$settings = bb2_read_settings();
if ($force || $settings['display_stats']) {
$blocked = bb2_db_rows(bb2_db_query("SELECT COUNT(*) FROM " . $settings['log_table'] . " WHERE `key` NOT LIKE '00000000'"));
if ($blocked !== FALSE) {
echo sprintf('<span><a href="http://www.bad-behavior.ioerror.us/">%1$s</a> %2$s <strong>%3$s</strong> %4$s</span>', 'Bad Behavior', 'has blocked', $blocked[0]["COUNT(*)"], 'access attempt(s) in the last 7 days.');
}
}
}
// Return the top-level relative path of wherever we are (for cookies)
// You should provide in $url the top-level URL for your site.
function bb2_relative_path() {
global $cookie_path;
return $cookie_path;
}
// Calls inward to Bad Behavor itself.
require_once(BB2_CWD . "/bad-behavior/core.inc.php");
bb2_install();
bb2_start(bb2_read_settings());