tuxsoul / bad-behavior

Bad Behavior is a unique way of blocking link spam and the robots which deliver it to your blog, forum, wiki or CMS. It operates in a completely different manner from other spam prevention services and is meant to operate alongside and in conjunction with other spam prevention software.

This URL has Read+Write access

bad-behavior / bad-behavior-lifetype.php
100644 173 lines (142 sloc) 5.602 kb
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
<?php
/*
http://blog.markplace.net
Bad Behavior - LifeType Plugin
Copyright (C) 2006 Mark Wu http://blog.markplace.net
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 in LifeType.
 
if (!defined('PLOG_CLASS_PATH')) die('No cheating!');
 
// Timer start
$bb2_mtime = explode(" ", microtime());
$bb2_timer_start = $bb2_mtime[1] + $bb2_mtime[0];
 
define('BB2_CWD', PLOG_CLASS_PATH . "plugins/badbehavior/" );
define('BB2_EMERGENCY_EMAIL', "admin@yourblog.com" );
define('BB2_DEFAULT_LOG_TABLE', "bad_behavior" );
 
// Bad Behavior callback functions.
 
// Return current time in the format preferred by your database.
function bb2_db_date() {
return gmdate('Y-m-d H:i:s');
}
 
// Return affected rows from most recent query.
function bb2_db_affected_rows() {
lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
$db =& Db::getDb();
 
return $db->Affected_Rows();
}
 
// Escape a string for database usage
function bb2_db_escape($string) {
lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
 
return Db::qstr($string);
}
 
// Return the number of rows in a particular query.
function bb2_db_num_rows($result) {
return $result->RecordCount();
}
 
// Run a query and return the results, if any.
// Should return FALSE if an error occurred.
function bb2_db_query($query) {
lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
$db =& Db::getDb();
 
$result = $db->Execute( $query );
 
if (!$result)
return FALSE;
 
return $result;
}
 
// 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) {
$rows = array();
while( $row = $result->FetchRow()) {
$rows[] = $row;
}
 
return $rows;
}
 
// Return emergency contact email address.
function bb2_email() {
return BB2_EMERGENCY_EMAIL;
}
 
// retrieve settings from lifetype config
function bb2_read_settings() {
lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
$config =& Config::getConfig();
$prefix = Db::getPrefix();
$logTable = $config->getValue( 'bb2_log_table', BB2_DEFAULT_LOG_TABLE );
$displayStats = $config->getValue( 'bb2_display_stats', true );
$strict = $config->getValue( 'bb2_strict', false );
$verbose = $config->getValue( 'bb2_verbose', false );
$isInstalled = $config->getValue( 'bb2_installed', false );
$logging = $config->getValue( 'bb2_logging', true );
$httpbl_key = $config->getValue( 'bb2_httpbl_key', '' );
$httpbl_threat = $config->getValue( 'bb2_httpbl_threat', '25' );
$httpbl_maxage = $config->getValue( 'bb2_httpbl_maxage', '30' );
 
return array('log_table' => $prefix . $logTable,
'display_stats' => $displayStats,
'strict' => $strict,
'verbose' => $verbose,
'logging' => $logging,
'httpbl_key' => $httpbl_key,
'httpbl_threat' => $httpbl_threat,
'httpbl_maxage' => $httpbl_maxage,
'is_installed' => $isInstalled );
}
 
// write settings to lifetype config
function bb2_write_settings($settings) {
lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
$config =& Config::getConfig();
$config->setValue( 'bb2_log_table', BB2_DEFAULT_LOG_TABLE );
$config->setValue( 'bb2_display_stats', $settings['display_stats'] );
$config->setValue( 'bb2_strict', $settings['strict'] );
$config->setValue( 'bb2_verbose', $settings['verbose'] );
$config->setValue( 'bb2_httpbl_key', $settings['httpbl_key'] );
$config->setValue( 'bb2_httpbl_threat', $settings['httpbl_threat'] );
$config->setValue( 'bb2_httpbl_maxage', $settings['httpbl_maxage'] );
$config->setValue( 'bb2_installed', $settings['is_installed'] );
$config->save();
}
 
// installation
function bb2_install() {
$settings = bb2_read_settings();
        if( $settings['is_installed'] == false && $settings['logging'] )
{
bb2_db_query(bb2_table_structure($settings['log_table']));
$settings['is_installed'] = true;
bb2_write_settings( $settings );
}
}
 
// Return the top-level relative path of wherever we are (for cookies)
function bb2_relative_path() {
lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
$config =& Config::getConfig();
 
$url = parse_url( $config->getValue( 'base_url' ) );
if( empty($url['path']) )
return '/';
else {
if( substr( $url['path'], -1, 1 ) == '/' )
return $url['path'];
else
return $url['path'] . '/';
}
}
 
// Load Bad Behavior Core
lt_include(BB2_CWD . "bad-behavior/core.inc.php");
bb2_install();
$settings = bb2_read_settings();
bb2_start($settings);
 
// Time Stop
$bb2_mtime = explode(" ", microtime());
$bb2_timer_stop = $bb2_mtime[1] + $bb2_mtime[0];
$bb2_timer_total = $bb2_timer_stop - $bb2_timer_start;
?>