"Fossies" - the Fresh Open Source Software Archive

Member "bad-behavior/bad-behavior-generic.php" (12 Jul 2018, 4792 Bytes) of package /linux/www/bad-behavior.2.2.22.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bad-behavior-generic.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.2.20_vs_2.2.21.

    1 <?php
    2 /*
    3 Bad Behavior - detects and blocks unwanted Web accesses
    4 Copyright (C) 2005,2006,2007,2008,2009,2010,2011,2012 Michael Hampton
    5 
    6 Bad Behavior is free software; you can redistribute it and/or modify it under
    7 the terms of the GNU Lesser General Public License as published by the Free
    8 Software Foundation; either version 3 of the License, or (at your option) any
    9 later version.
   10 
   11 This program is distributed in the hope that it will be useful, but WITHOUT ANY
   12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   13 PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
   14 
   15 You should have received a copy of the GNU Lesser General Public License along
   16 with this program. If not, see <http://www.gnu.org/licenses/>.
   17 
   18 Please report any problems to bad . bots AT ioerror DOT us
   19 http://bad-behavior.ioerror.us/
   20 */
   21 
   22 ###############################################################################
   23 ###############################################################################
   24 
   25 define('BB2_CWD', dirname(__FILE__));
   26 
   27 // Settings you can adjust for Bad Behavior.
   28 // Most of these are unused in non-database mode.
   29 // DO NOT EDIT HERE; instead make changes in settings.ini.
   30 // These settings are used when settings.ini is not present.
   31 $bb2_settings_defaults = array(
   32     'log_table' => 'bad_behavior',
   33     'display_stats' => false,
   34     'strict' => false,
   35     'verbose' => false,
   36     'logging' => true,
   37     'httpbl_key' => '',
   38     'httpbl_threat' => '25',
   39     'httpbl_maxage' => '30',
   40     'offsite_forms' => false,
   41     'reverse_proxy' => false,
   42     'reverse_proxy_header' => 'X-Forwarded-For',
   43     'reverse_proxy_addresses' => array(),
   44 );
   45 
   46 // Bad Behavior callback functions.
   47 
   48 // Return current time in the format preferred by your database.
   49 function 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.
   54 function bb2_db_affected_rows() {
   55     return false;
   56 }
   57 
   58 // Escape a string for database usage
   59 function 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.
   65 function 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.
   74 function 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.
   81 function bb2_db_rows($result) {
   82     return $result;
   83 }
   84 
   85 // Create the SQL query for inserting a record in the database.
   86 // See example for MySQL elsewhere.
   87 function bb2_insert($settings, $package, $key)
   88 {
   89     return "--";
   90 }
   91 
   92 // Return emergency contact email address.
   93 function bb2_email() {
   94     return "example@example.com";   // You need to change this.
   95 }
   96 
   97 // retrieve whitelist
   98 function bb2_read_whitelist() {
   99     return @parse_ini_file(dirname(BB2_CORE) . "/whitelist.ini");
  100 }
  101 
  102 // retrieve settings from database
  103 // Settings are hard-coded for non-database use
  104 function bb2_read_settings() {
  105     global $bb2_settings_defaults;
  106     $settings = @parse_ini_file(dirname(__FILE__) . "/settings.ini");
  107     if (!$settings) $settings = array();
  108     return @array_merge($bb2_settings_defaults, $settings);
  109 }
  110 
  111 // write settings to database
  112 function bb2_write_settings($settings) {
  113     return false;
  114 }
  115 
  116 // installation
  117 function bb2_install() {
  118     return false;
  119 }
  120 
  121 // Screener
  122 // Insert this into the <head> section of your HTML through a template call
  123 // or whatever is appropriate. This is optional we'll fall back to cookies
  124 // if you don't use it.
  125 function bb2_insert_head() {
  126     global $bb2_javascript;
  127     echo $bb2_javascript;
  128 }
  129 
  130 // Display stats? This is optional.
  131 function bb2_insert_stats($force = false) {
  132     $settings = bb2_read_settings();
  133 
  134     if ($force || $settings['display_stats']) {
  135         $blocked = bb2_db_query("SELECT COUNT(*) FROM " . $settings['log_table'] . " WHERE `key` NOT LIKE '00000000'");
  136         if ($blocked !== FALSE) {
  137             echo sprintf('<p><a href="http://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.'));
  138         }
  139     }
  140 }
  141 
  142 // Return the top-level relative path of wherever we are (for cookies)
  143 // You should provide in $url the top-level URL for your site.
  144 function bb2_relative_path() {
  145     //$url = parse_url(get_bloginfo('url'));
  146     //return $url['path'] . '/';
  147     return '/';
  148 }
  149 
  150 // Calls inward to Bad Behavor itself.
  151 require_once(BB2_CWD . "/bad-behavior/core.inc.php");
  152 bb2_install();  // FIXME: see above
  153 
  154 bb2_start(bb2_read_settings());