| 1 | <?php |
| 2 | /* |
| 3 | http://blog.markplace.net |
| 4 | |
| 5 | Bad Behavior - LifeType Plugin |
| 6 | Copyright (C) 2006 Mark Wu http://blog.markplace.net |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | // This file is the entry point for Bad Behavior in LifeType. |
| 24 | |
| 25 | if (!defined('PLOG_CLASS_PATH')) die('No cheating!'); |
| 26 | |
| 27 | // Timer start |
| 28 | $bb2_mtime = explode(" ", microtime()); |
| 29 | $bb2_timer_start = $bb2_mtime[1] + $bb2_mtime[0]; |
| 30 | |
| 31 | define('BB2_CWD', PLOG_CLASS_PATH . "plugins/badbehavior/" ); |
| 32 | define('BB2_EMERGENCY_EMAIL', "admin@yourblog.com" ); |
| 33 | define('BB2_DEFAULT_LOG_TABLE', "bad_behavior" ); |
| 34 | |
| 35 | // Bad Behavior callback functions. |
| 36 | |
| 37 | // Return current time in the format preferred by your database. |
| 38 | function bb2_db_date() { |
| 39 | return gmdate('Y-m-d H:i:s'); |
| 40 | } |
| 41 | |
| 42 | // Return affected rows from most recent query. |
| 43 | function bb2_db_affected_rows() { |
| 44 | lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); |
| 45 | $db =& Db::getDb(); |
| 46 | |
| 47 | return $db->Affected_Rows(); |
| 48 | } |
| 49 | |
| 50 | // Escape a string for database usage |
| 51 | function bb2_db_escape($string) { |
| 52 | lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); |
| 53 | |
| 54 | return Db::qstr($string); |
| 55 | } |
| 56 | |
| 57 | // Return the number of rows in a particular query. |
| 58 | function bb2_db_num_rows($result) { |
| 59 | return $result->RecordCount(); |
| 60 | } |
| 61 | |
| 62 | // Run a query and return the results, if any. |
| 63 | // Should return FALSE if an error occurred. |
| 64 | function bb2_db_query($query) { |
| 65 | lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); |
| 66 | $db =& Db::getDb(); |
| 67 | |
| 68 | $result = $db->Execute( $query ); |
| 69 | |
| 70 | if (!$result) |
| 71 | return FALSE; |
| 72 | |
| 73 | return $result; |
| 74 | } |
| 75 | |
| 76 | // Return all rows in a particular query. |
| 77 | // Should contain an array of all rows generated by calling mysql_fetch_assoc() |
| 78 | // or equivalent and appending the result of each call to an array. |
| 79 | function bb2_db_rows($result) { |
| 80 | $rows = array(); |
| 81 | while( $row = $result->FetchRow()) { |
| 82 | $rows[] = $row; |
| 83 | } |
| 84 | |
| 85 | return $rows; |
| 86 | } |
| 87 | |
| 88 | // Return emergency contact email address. |
| 89 | function bb2_email() { |
| 90 | return BB2_EMERGENCY_EMAIL; |
| 91 | } |
| 92 | |
| 93 | // retrieve settings from lifetype config |
| 94 | function bb2_read_settings() { |
| 95 | lt_include( PLOG_CLASS_PATH."class/database/db.class.php" ); |
| 96 | lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); |
| 97 | $config =& Config::getConfig(); |
| 98 | $prefix = Db::getPrefix(); |
| 99 | $logTable = $config->getValue( 'bb2_log_table', BB2_DEFAULT_LOG_TABLE ); |
| 100 | $displayStats = $config->getValue( 'bb2_display_stats', true ); |
| 101 | $strict = $config->getValue( 'bb2_strict', false ); |
| 102 | $verbose = $config->getValue( 'bb2_verbose', false ); |
| 103 | $isInstalled = $config->getValue( 'bb2_installed', false ); |
| 104 | $logging = $config->getValue( 'bb2_logging', true ); |
| 105 | $httpbl_key = $config->getValue( 'bb2_httpbl_key', '' ); |
| 106 | $httpbl_threat = $config->getValue( 'bb2_httpbl_threat', '25' ); |
| 107 | $httpbl_maxage = $config->getValue( 'bb2_httpbl_maxage', '30' ); |
| 108 | |
| 109 | return array('log_table' => $prefix . $logTable, |
| 110 | 'display_stats' => $displayStats, |
| 111 | 'strict' => $strict, |
| 112 | 'verbose' => $verbose, |
| 113 | 'logging' => $logging, |
| 114 | 'httpbl_key' => $httpbl_key, |
| 115 | 'httpbl_threat' => $httpbl_threat, |
| 116 | 'httpbl_maxage' => $httpbl_maxage, |
| 117 | 'is_installed' => $isInstalled ); |
| 118 | } |
| 119 | |
| 120 | // write settings to lifetype config |
| 121 | function bb2_write_settings($settings) { |
| 122 | lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); |
| 123 | $config =& Config::getConfig(); |
| 124 | $config->setValue( 'bb2_log_table', BB2_DEFAULT_LOG_TABLE ); |
| 125 | $config->setValue( 'bb2_display_stats', $settings['display_stats'] ); |
| 126 | $config->setValue( 'bb2_strict', $settings['strict'] ); |
| 127 | $config->setValue( 'bb2_verbose', $settings['verbose'] ); |
| 128 | $config->setValue( 'bb2_httpbl_key', $settings['httpbl_key'] ); |
| 129 | $config->setValue( 'bb2_httpbl_threat', $settings['httpbl_threat'] ); |
| 130 | $config->setValue( 'bb2_httpbl_maxage', $settings['httpbl_maxage'] ); |
| 131 | $config->setValue( 'bb2_installed', $settings['is_installed'] ); |
| 132 | $config->save(); |
| 133 | } |
| 134 | |
| 135 | // installation |
| 136 | function bb2_install() { |
| 137 | $settings = bb2_read_settings(); |
| 138 | if( $settings['is_installed'] == false && $settings['logging'] ) |
| 139 | { |
| 140 | bb2_db_query(bb2_table_structure($settings['log_table'])); |
| 141 | $settings['is_installed'] = true; |
| 142 | bb2_write_settings( $settings ); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Return the top-level relative path of wherever we are (for cookies) |
| 147 | function bb2_relative_path() { |
| 148 | lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); |
| 149 | $config =& Config::getConfig(); |
| 150 | |
| 151 | $url = parse_url( $config->getValue( 'base_url' ) ); |
| 152 | if( empty($url['path']) ) |
| 153 | return '/'; |
| 154 | else { |
| 155 | if( substr( $url['path'], -1, 1 ) == '/' ) |
| 156 | return $url['path']; |
| 157 | else |
| 158 | return $url['path'] . '/'; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Load Bad Behavior Core |
| 163 | lt_include(BB2_CWD . "bad-behavior/core.inc.php"); |
| 164 | bb2_install(); |
| 165 | $settings = bb2_read_settings(); |
| 166 | bb2_start($settings); |
| 167 | |
| 168 | // Time Stop |
| 169 | $bb2_mtime = explode(" ", microtime()); |
| 170 | $bb2_timer_stop = $bb2_mtime[1] + $bb2_mtime[0]; |
| 171 | $bb2_timer_total = $bb2_timer_stop - $bb2_timer_start; |
| 172 | ?> |
| 173 | |