Welcome Guest, Not a member yet? Register   Sign In
Bad-Behavior anti-spam
#1

[eluser]toolwieldingape[/eluser]
I searched and didn't find this posted already, thought I'd share. If it's a duplicate, please feel free to remove the post. Thanks.

Info/Download:
http://www.bad-behavior.ioerror.us/

Quote:Bad Behavior complements other link spam solutions by acting as a gatekeeper, preventing spammers from ever delivering their junk, and in many cases, from ever reading your site in the first place. This keeps your site’s load down, makes your site logs cleaner, and can help prevent denial of service conditions caused by spammers.

Note the table name for your config file:
Code:
CREATE TABLE IF NOT EXISTS `bad_behavior` (
        `id` INT(11) NOT NULL auto_increment,
        `ip` TEXT NOT NULL,
        `date` DATETIME NOT NULL default '0000-00-00 00:00:00',
        `request_method` TEXT NOT NULL,
        `request_uri` TEXT NOT NULL,
        `server_protocol` TEXT NOT NULL,
        `http_headers` TEXT NOT NULL,
        `user_agent` TEXT NOT NULL,
        `request_entity` TEXT NOT NULL,
        `key` TEXT NOT NULL,
        INDEX (`ip`(15)),
        INDEX (`user_agent`(10)),
        PRIMARY KEY (`id`) );

Download the source from the link above, extract and move the bad-behavior folder into app/libraries. create a new file: app/libraries/bad-behavior.php with the contents:
Code:
<?php
/*
Bad Behavior - detects and blocks unwanted Web accesses
Copyright (C) 2005-2006 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.

As a special exemption, you may link this program with any of the
programs listed below, regardless of the license terms of those
programs, and distribute the resulting program, without including the
source code for such programs: ExpressionEngine

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.

Please report any problems to badbots AT ioerror DOT us
*/

###############################################################################
###############################################################################

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

define('BB2_CWD', dirname(__FILE__));

if(!function_exists('get_CI')){
    function &get;_CI($var=null)
    {
        static $CI = null;
        
        if(is_null($CI)){
            $CI =& get_instance();    
        }
        if(!is_null($var) AND isset($CI->$var)){
            return $CI->$var;
        }
        
        return $CI;
    }
}

// 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');    // Example is MySQL format
}

// Return affected rows from most recent query.
function bb2_db_affected_rows() {
    $db = get_CI('db');
    return $db->affected_rows();
}

// Escape a string for database usage
function bb2_db_escape($string) {
    $db = get_CI('db');
    return $db->escape_str($string);
}

// Return the number of rows in a particular query.
function bb2_db_num_rows($result) {
    if ($result !== false) {
        return $result->num_rows();
    } else {
        return 0;
    }
}

// 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) {
    $db = get_CI('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) {
    return $result->result_array();
}

// Return emergency contact email address.
function bb2_email() {
    return '[email protected]';
}

// retrieve settings from database
// Settings are hard-coded for non-database use
function bb2_read_settings() {
    $bb2_settings_defaults = array(
        'log_table'     => 'bad_behavior',
        'display_stats' => false,
        'strict'        => false,
        'verbose'       => false,
        'logging'       => true,
        'httpbl_key'    => '', /* Black list key: http://www.projecthoneypot.org/httpbl_configure.php */
        'httpbl_threat' => '', /* BL threat level: http://www.projecthoneypot.org/httpbl_configure.php?rf=24694 */
        'httpbl_maxage' => '',
        'is_installed'  => true
    );
    return $bb2_settings_defaults;
}

// write settings to database
function bb2_write_settings($settings) {
    return;
}

// installation
function bb2_install() {
    $settings = bb2_read_settings();
    return bb2_db_query(bb2_table_structure($settings['log_table']));
}

// Screener
// Insert this into the <head> section of your HTML through a template call
// or whatever is appropriate. This is optional we'll fall back to cookies
// if you don't use it.
/*
function bb2_insert_head() {
    global $bb2_javascript;
    // add to view or whatever
}
*/

// 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() {
    $config = get_CI('config');
    return $config->config['base_url'];
}


// Calls inward to Bad Behavor itself.
require_once(BB2_CWD . '/bad-behavior/version.inc.php');
require_once(BB2_CWD . '/bad-behavior/core.inc.php');

bb2_start(bb2_read_settings());

?>
#2

[eluser]toolwieldingape[/eluser]
Note the log_table in bb2_read_settings() and the email address in bb2_email().

All that needs to be done for it to "run" is to require/include app/libraries/bad-behavior.php .. whatever method you use is up to you.

if you want to see that it's working, set verbose=>true in bb2_read_settings(), refresh the page that bad-behavior.php has been included in and check for a record.

Enjoy.

PS:
Code:
function &get;_CI($var=null)
remove the semi-colon .. not sure why i can't remove it from the post.




Theme © iAndrew 2016 - Forum software by © MyBB