[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_module/mod_bad-behavior/ -> bad-behavior-phpwcms.php (source)

   1  <?php
   2  /*
   3  Bad Behavior - detects and blocks unwanted Web accesses
   4  Copyright (C) 2005-2006 Michael Hampton
   5  
   6  This program is free software; you can redistribute it and/or modify
   7  it under the terms of the GNU General Public License as published by
   8  the Free Software Foundation; either version 2 of the License, or
   9  (at your option) any later version.
  10  
  11  As a special exemption, you may link this program with any of the
  12  programs listed below, regardless of the license terms of those
  13  programs, and distribute the resulting program, without including the
  14  source code for such programs: ExpressionEngine
  15  
  16  This program is distributed in the hope that it will be useful,
  17  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  GNU General Public License for more details.
  20  
  21  You should have received a copy of the GNU General Public License
  22  along with this program; if not, write to the Free Software
  23  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24  
  25  Please report any problems to badbots AT ioerror DOT us
  26  */
  27  
  28  // This file is the entry point for Bad Behavior 2 in phpwcms.
  29  
  30  // obligate check for phpwcms constants
  31  if (!defined('PHPWCMS_ROOT')) {
  32     die("You Cannot Access This Script Directly, Have a Nice Day.");
  33  }
  34  // ----------------------------------------------------------------
  35  
  36  $_SERVER['REMOTE_ADDR'] = getRemoteIP();
  37  
  38  
  39  define('BB2_CWD', PHPWCMS_ROOT.'/include/inc_module/mod_bad-behavior');
  40  
  41  // core path setting based on phpwcms' values
  42  define('BB2_CORE', BB2_CWD.'/bad-behavior');
  43  
  44  // Settings you can adjust for Bad Behavior.
  45  // Most of these are unused in non-database mode.
  46  $bb2_settings_defaults = array(
  47      'log_table' => DB_PREPEND.'phpwcms_bad_behavior',
  48      'display_stats' => true,
  49      'strict' => false,
  50      'verbose' => false,
  51      'logging' => true
  52  );
  53  
  54  // Bad Behavior callback functions.
  55  
  56  // Return current time in the format preferred by your database.
  57  function bb2_db_date() {
  58      return gmdate('Y-m-d H:i:s');    // Example is MySQL format
  59  }
  60  
  61  // Return affected rows from most recent query.
  62  function bb2_db_affected_rows() {
  63      return false;
  64  }
  65  
  66  // Escape a string for database usage
  67  function bb2_db_escape($string) {
  68      // return mysql_real_escape_string($string);
  69      return aporeplace($string);    // No-op when database not in use.
  70  }
  71  
  72  // Return the number of rows in a particular query.
  73  function bb2_db_num_rows($result) {
  74      if ($result !== FALSE)
  75          return count($result);
  76      return 0;
  77  }
  78  
  79  // Run a query and return the results, if any.
  80  // Should return FALSE if an error occurred.
  81  // Bad Behavior will use the return value here in other callbacks.
  82  function bb2_db_query($query) {
  83  
  84      $result = @mysql_query($query, $GLOBALS['db']);
  85      
  86      if($result === false) {
  87          return false;
  88      } elseif($result === true) {
  89          return true;    
  90      } else {
  91          $query_result = array();
  92          while($row = mysql_fetch_assoc($result)) {
  93              $query_result[] = $row;
  94          }
  95          mysql_free_result($result);
  96          return $query_result;
  97      }
  98      return false;
  99  }
 100  
 101  // Return all rows in a particular query.
 102  // Should contain an array of all rows generated by calling mysql_fetch_assoc()
 103  // or equivalent and appending the result of each call to an array.
 104  function bb2_db_rows($result) {
 105      return $result;
 106  }
 107  
 108  // Return emergency contact email address.
 109  function bb2_email() {
 110      return $GLOBALS['phpwcms']['admin_email'];
 111  }
 112  
 113  // retrieve settings from database
 114  // Settings are hard-coded for non-database use
 115  function bb2_read_settings() {
 116  
 117      if(isset($GLOBALS['phpwcms']['bad_behavior_settings']) && is_array($GLOBALS['phpwcms']['bad_behavior_settings'])) {
 118          $settings = $GLOBALS['phpwcms']['bad_behavior_settings'];
 119      } else {
 120          $settings = array();
 121      }
 122      $bb2_settings_defaults = array(
 123          'log_table' => DB_PREPEND.'phpwcms_bad_behavior',
 124          'display_stats' => true,
 125          'strict' => false,
 126          'verbose' => false,
 127          'db_installed' => true,
 128          'logging' => true
 129      );
 130  
 131      return array_merge($bb2_settings_defaults, $settings);
 132  }
 133  
 134  // write settings to database
 135  function bb2_write_settings($settings) {
 136      return false;
 137  }
 138  
 139  // installation
 140  function bb2_install() {
 141      $settings = bb2_read_settings();
 142      if(empty($settings['db_installed'])) {
 143          bb2_db_query(bb2_table_structure($settings['log_table']));
 144      }
 145  }
 146  
 147  // Screener
 148  // Insert this into the <head> section of your HTML through a template call
 149  // or whatever is appropriate. This is optional we'll fall back to cookies
 150  // if you don't use it.
 151  function bb2_insert_head() {
 152      global $bb2_javascript;
 153      //echo $bb2_javascript;
 154      $GLOBALS['block']['custom_htmlhead']['bad_behavior'] = '  '.$bb2_javascript;
 155  }
 156  
 157  // Display stats? This is optional.
 158  function bb2_insert_stats($force = false) {
 159      $settings = bb2_read_settings();
 160  
 161      if ($force || $settings['display_stats']) {
 162          $blocked = bb2_db_query("SELECT COUNT(*) FROM " . $settings['log_table'] . " WHERE `key` NOT LIKE '00000000'");
 163          if ($blocked !== FALSE) {
 164              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.'));
 165          }
 166      }
 167  }
 168  
 169  // Return the top-level relative path of wherever we are (for cookies)
 170  // You should provide in $url the top-level URL for your site.
 171  function bb2_relative_path() {
 172      //$url = parse_url(get_bloginfo('url'));
 173      //return $url['path'] . '/';
 174      return PHPWCMS_URL;
 175  }
 176  
 177  // Calls inward to Bad Behavor itself.
 178  require_once (BB2_CWD . '/bad-behavior/version.inc.php');
 179  require_once (BB2_CWD . '/bad-behavior/core.inc.php');
 180  //bb2_install();    // FIXME: see above
 181  /*
 182  if(VISIBLE_MODE === 2) {
 183      require_once(BB2_CWD . '/bad-behavior/admin.inc.php');
 184  }
 185  */
 186  
 187  bb2_start(bb2_read_settings());
 188  
 189  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7