[mod] Spam Block Prevention mod - Bad Behaviour 2

3rd party code for phpList

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby jsherk » 4:49am, Sun 18 Dec, 2011

Best explanation would be to read the website:
http://bad-behavior.ioerror.us/

But in a nutshell, most robots that try to spam your site have malformed user agents or customized user agents so the first thing it does is check the user agent and then deny if there is some kind of match. It has additional features that can be added on, like project honeypot, which is a database of known spam ip addresses, so it can block them based on that as well.

Hoep that helps.
jsherk
PL Geek
 
Posts: 101
Joined: 11:37pm, Mon 28 May, 2007

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby cjb » 1:13am, Wed 25 Jul, 2012

Hi I tried installing this as per previous post and my pages are blank until I comment out the include once in the pagetop.php line to turn it off again.

I have all the details configured correctly in the bad-behavior-phplist.php as copied direct from config.php for database connection so I can't see why it's not working.

I do note however that there have been no database tables created by the script.

Is there something I am doing wrong here?

Thanks
cj
cjb
phpLister
 
Posts: 11
Joined: 2:04am, Wed 30 Jun, 2010

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby jsherk » 1:30am, Wed 25 Jul, 2012

Its been a while since I played with this stuff, but I believe you will have to create all the database tables manually ahead of time.
jsherk
PL Geek
 
Posts: 101
Joined: 11:37pm, Mon 28 May, 2007

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby cjb » 1:36am, Wed 25 Jul, 2012

Thanks... I will give that a try. CJ
cjb
phpLister
 
Posts: 11
Joined: 2:04am, Wed 30 Jun, 2010

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby cjb » 6:52am, Wed 25 Jul, 2012

I know it may be obvious to others but I can't seem to figure out what table to create in my phpmyadmin...

Could someone please make a list of them here so I don't feel so thick?

Thanks C
cjb
phpLister
 
Posts: 11
Joined: 2:04am, Wed 30 Jun, 2010

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby jsherk » 12:41pm, Wed 25 Jul, 2012

Can you post the exact code you have used?

What directory is this code in?

What directory is the bad behavior code in?
jsherk
PL Geek
 
Posts: 101
Joined: 11:37pm, Mon 28 May, 2007

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby cjb » 9:11pm, Wed 25 Jul, 2012

I ended up using all the code from your post as quoted below :

jsherk wrote:After all that hard work by dragonrider I ended up playing around with the bad behavior plugin for WordPress and then discovered a MUCH simpler method to apply it to phpList (I really didn't know much about php when I first put the hack together), and I also got DB logging working.

So here are the EASY mod instructions!!! All previous mods are no longer necessary or relevant! This should work with any version of phpList and bad behavior, including v2.10.10 ( I tested this with Bad Behavior v2.0.28).

STEP #1 - Download/Unzip/Upload
Before I start here is a really cool trick... if you are already using Bad Behavior as plugin on your WordPress blog, then you do not need to download another copy for phpList... it can use the same files as the WordPress plugin is using, and even better that means when the plugin gets upgraded so does the version that phpList is using! Anyways, if you already have it installed as part WordPress then you can skip this downloading step.

Download latest version from here (zip file):
http://www.bad-behavior.ioerror.us/

Unzip the file, then upload the bad-behavior folder to your phpList admin directory (/lists/admin/). If you have a folder called something like 'bad-behavior.2.0.28' , don't upload that folder, but the 'bad-behavior' folder that is inside it.

STEP #2 - Modify pagetop.php file
This is the ONLY phpList file that needs to be modified.

Find the /lists/admin/pagetop.php file and make a copy of it, and call it something like pagetop.php.ORIG just in case there is a problem with the mod, then you can revert.

At the very top of the file, AFTER the <?php line but BEFORE the /* line, insert the following code. This code MUST be the VERY first thing in the file, before everything else (except the <?php) otherwise it will generate errors:
Code: Select all
//Bad Behavior
include_once('/home/path-to/admin/bad-behavior/bad-behavior-phplist.php');

Change the 'path-to' in include_once statement line to reflect the location of your bad-behavior folder.

Now further down in the same file, in the HEAD section, find this line:
Code: Select all
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $strCharSet?>" />

Right AFTER the above line, insert this code:
Code: Select all
<?php
//Bad Behavior
if (function_exists('bb2_insert_head')) {
  bb2_insert_head();
}
?>

STEP #3 - Create & modify bad-behavior-phplist.php file
Copy and paste the following code below into a new file called
bad-behavior-phplist.php
Code: Select all
<?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
*/

###############################################################################
###############################################################################
/*

SAMPLE CODE - SCREENER:
-----------------------
<?php
//Bad Behavior - This include_once statement MUST be the very first item at the
//top of your page, or it will generate an WARNING and the following functions
//may not work: bb2_insert_head(), bb2_insert_stats(), bb2_db_viewer()
// NOTE: It MUST be the very first item on the page or you will get an error.
//       It needs to be BEFORE all tags (before <html>, <head>, <!DOCTYPE>, etc).
include_once('/home/path-to/bad-behavior/bad-behavior-generic-mysql.php');
?>

<?php
//Bad Behavior - This code should appear in the <HEAD> section of your page
// and will add the required JavaScript to your page.
if (function_exists('bb2_insert_head')) {
  bb2_insert_head();
}
?>


SAMPLE CODE - STATS:
--------------------
<?php
//Bad Behavior - This include_once statement MUST be the very first item at the
//top of your page, or it will generate an WARNING and the following functions
//may not work: bb2_insert_head(), bb2_insert_stats(), bb2_db_viewer()
// NOTE: It MUST be the very first item on the page or you will get an error.
//       It needs to be BEFORE all tags (before <html>, <head>, <!DOCTYPE>, etc).
include_once('/home/path-to/bad-behavior/bad-behavior-generic-mysql.php');
?>

<?php
//Bad Behavior - This code can appear anywhere in your page (usually in your
// footer) and will show how many blocks Bad Behavior has made (if you have
// display_stats=true in the config file). 
if (function_exists('bb2_insert_stats')) {
  bb2_insert_stats();
}
?>


SAMPLE CODE - SIMPLE DB VIEWER:
-------------------------------
See the file: bad-behavior-simple-db-viewer.php

*/
###############################################################################
###############################################################################

///////////////////////////////////////////////////////////////////////////////
//Settings for email and database access
//Change these as appropriate
define('BB2_EMERG_EMAIL','email@email.com'); //Change this
define('BB2_DB_TABLE', 'phplist_bad_behavior'); // Choose your table
define('BB2_DB_NAME', 'db-name'); // The name of the database
define('BB2_DB_USER', 'db-user'); // Your DB username
define('BB2_DB_PASSWORD', 'db-user-password'); // Your DB user password
define('BB2_DB_HOST', 'localhost'); //Probably can leave this as localhost
define('BB2_CWD', dirname(__FILE__)); //Do not change this

///////////////////////////////////////////////////////////////////////////////
// More settings you can adjust for Bad Behavior.
// Most of these are unused in non-database mode.
// More details below...
$bb2_settings_defaults = array(
   'log_table' => BB2_DB_TABLE,
   'display_stats' => true,
   'strict' => false,
   'verbose' => false,
   'logging' => true,
   'httpbl_key' => '',
   'httpbl_threat' => '25',
   'httpbl_maxage' => '30',
);
// Here is what the settings above mean...
//
// - log_table
//   Leave this as BB2_DB_TABLE (do NOT change it). Make your change up above
//   in the line that says: define('BB2_DB_TABLE', 'phplist_bad_behavior')
//   Change 'phplist_bad_behavior' to whatever table you want to use.
//   This table will be created automatically if it does not already exist.
//
// - display_stats
//   TRUE=Display stats on page that has the bb2_insert_stats() function on it.
//   FALSE=Do not display stats.
//   Default is TRUE
//
// - strict
//   TRUE=Strict checking (blocks more spam but may block some people)
//   FALSE=Recommended setting
//   
// - verbose
//   TRUE=This will log EVERY access attempt to webpage, including valid
//        permitted ones. Good for testing to see if logging is working,
//        but can cause your DB table to become huge fairly quickly.
//   FALSE=Log only denied access attempts or permitted ones that were
//         questionable. This is the recommended default setting.
//
// - logging
//   TRUE=Log info to database table.
//   FALSE=Do not log anything.
//
// - httpbl_key
//   To use Bad Behavior's http:BL features you must have an http:BL Access Key.
//   Sign up for a free account to get a key here:
//   http://www.projecthoneypot.org/httpbl_configure.php?rf=24694
//
// - httpbl_threat
//   Minimum Threat Level (25 is recommended)
//
// - httpbl_maxage
//   Maximum Age of Data (30 is recommended)


///////////////////////////////////////////////////////////////////////////////
//Open and connect to DB
$dblinkid = mysql_connect(BB2_DB_HOST, BB2_DB_USER, BB2_DB_PASSWORD); //Connect to DB
define('BB2_DB_LINK_ID', $dblinkid); //Setup the Resource Link ID so it's available in other functions.
if (!BB2_DB_LINK_ID) {
  die('Could not connect to DB: ' . mysql_error()); //Not pretty but at least you know there is a problem!
}

$dbselect = mysql_select_db(BB2_DB_NAME, BB2_DB_LINK_ID); //Choose connection Table in DB
if (!$dbselect) {
  die ('Can not use selected DB: ' . mysql_error()); //Not pretty but at least you know there is a problem!
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
///////////////////////////////////////////////////////////////////////////////
// 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
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Escape a string for database usage
// TO DO: Figure out what this should do and how to implement it
function bb2_db_escape($string) {
   return $string;   // No-op ... see TO DO
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Return affected rows from most recent query.
function bb2_db_affected_rows() {
  return mysql_affected_rows(BB2_DB_LINK_ID);
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Return the number of rows in a particular query.
function bb2_db_num_rows($link) {
  return mysql_num_rows($link);
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Run a query and return the results, if any.
// Will return FALSE if an error occurred.
// Bad Behavior will use the return value here in other callbacks.
// WRITE operations will return TRUE for successful and FALSE for nothing written
// READ operations will return an associative array of the result set, or FALSE if no rows were returned
//  It will return array[0] with first row, then array[1] with second row, etc.
function bb2_db_query($query) {
  $link = mysql_query($query, BB2_DB_LINK_ID);

  if (!$link) { //If it's 0/FALSE then there was some kind of error
    //die('There was a problem with $query: '.mysql_error()); //Uncomment this line for debugging
    return false; //Return false if there is an error
  }

  if ($link === TRUE) { //If it's exactly TRUE then it was a succesful WRITE operation
    $affected_rows = bb2_db_affected_rows(); //how many affected rows in a WRITE query?
    if ($affected_rows >= 1) {
      return true; //Something was succesfully written
    } else {
      return false; //Nothing was written
    } 
  } else { //If it's not 0/FALSE and it's not exactly TRUE then it was a READ operation
    $number_of_rows = bb2_db_num_rows($link); //number of rows read the READ query?
    if ($number_of_rows == '0') {
      return false; //No rows were found for query
    }
  }

  $result = bb2_db_rows($link); //Go get all the rows and put them an array

  return $result;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Return all rows in a particular READ query.
// Will contain an array of all rows generated by calling mysql_fetch_assoc()
// and appending the result of each call to an array. It will return array[0]
// with first row, then array[1] with second row, etc.
function bb2_db_rows($linkid) {
  $i = 0;
  while ($row = mysql_fetch_assoc($linkid)) { //Get each row from query
    $result[$i] = $row;
    $i++;
  }
  if (empty($result)) {
    $result = $linkid; //If there were no rows, then just return the id
  }
 
  return $result;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Return emergency contact email address.
function bb2_email() {
   return BB2_EMERG_EMAIL;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Retrieve settings
// Currently they are hard coded in this file.
// TO DO: Retrieve from DB... need to implement bb2_write_settings() first.
function bb2_read_settings() {
   global $bb2_settings_defaults;
   return $bb2_settings_defaults;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Write settings to database
// Currently not implemented. Settings are hard coded in this file.
// TO DO: Add another table to DB to store these settings in?
function bb2_write_settings($settings) {
   return false;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Installation
// Will automatically create the table if it does not exist yet.
function bb2_install() {
  $settings = bb2_read_settings();
  if (!$settings['logging']) return;
   bb2_db_query(bb2_table_structure($settings['log_table']));
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Screener
// See example at top of this file
function bb2_insert_head() {
   global $bb2_javascript;
   echo $bb2_javascript;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Display stats (optional)
// See example at top of this file
function bb2_insert_stats($force = false) {
   $settings = bb2_read_settings();
   if ($force || $settings['display_stats']) {
      $blocked = bb2_db_query("SELECT COUNT(*) FROM ".$settings['log_table']." WHERE `key` NOT LIKE '00000000'");
      $totals = bb2_db_query("SELECT COUNT(*) FROM ".$settings['log_table']);
    if ($blocked !== FALSE) {
         echo '<p><a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> has blocked <strong>'.$blocked[0]['COUNT(*)'].'</strong> access attempts to date. ('.$totals[0]['COUNT(*)'].' db entries).</p>';
      }
  }
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Return the top-level relative path of wherever we are (for cookies)
// You should provide in $url the top-level URL for your site.
// TO DO: What is this actually used for? Seems to work fine if you leave it as '/'
function bb2_relative_path() {
  return '/';
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 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_install(); //Check if table exists and create it if it does not

bb2_start(bb2_read_settings());


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//SIMPLE DB VIEWER
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Simple display of what's in DB
//See bad-behavior-simple-db-viewer.php for sample of how to use it
// VALID OPTIONS FOR THIS FUNCTIONS ARE:
//  $what:  0=ALL entries  1=Permitted entries only  2=Denied entries only
//  $page_num:  Any integer 1 or greater.
//  $per_page:  Number of entries per page to display. Any integer 1 or greater.
//  $sort_by:  'date' or 'request_uri' or 'key'
//  $order_by: 'ASC' or 'DESC'
// RETURN VALUES:
//  Function will return an array($limit_start, $limit_end, $total_count, $page_num, $display)
//  $limit_start: This is the first record number that it is displaying
//  $limit_end:  This is the last record number that it is displaying
//  $total_count: This is the total number of entries in the database
//  $page_num: The actual page number that was displayed
//  $display: This contains the html for the <table> that will be displayed
function bb2_simple_db_viewer($what=0, $page_num=1, $per_page=25, $sort_by='date', $order='DESC') {
  if ($what !== 0 && $what !== 1 && $what !== 2) {
    $what = 0;
  }
  if ($page_num < 1) {
    $page_num = 1;
  }
  if ($per_page < 1) {
    $per_page = 1;
  }
  if ($sort_by !== 'date' && $sort_by !== 'request_uri' && $sort_by !== 'key') {
    $sort_by='date';
  }
  if ($order !== 'ASC' && $order !== 'DESC') {
    $order='DESC';
  }
 
  $where = '';
  if ($what == 1) {
    $where = "WHERE `key` = '00000000' ";
  } elseif ($what == 2) {
    $where = "WHERE `key` NOT LIKE '00000000' ";
  }

  $total_result = bb2_db_query("SELECT COUNT(*) FROM ".BB2_DB_TABLE." ".$where);
  $total_count = $total_result[0]['COUNT(*)'];

  $orderby = "ORDER BY `".$sort_by."` ".$order." ";
 
  $limit_start = ($page_num * $per_page) - $per_page;
  if ($limit_start > $total_count) {
    $limit_start = $total_count-1;
  }

  if ($per_page > $total_count) { //
    $per_page = $total_count;
  }
 
  $limit_end = $limit_start + $per_page;
 
  if ($limit_end > $total_count) {
    $limit_end = $total_count;
  }

  for ($i=$page_num; $i>1; $i--) { //Make sure the page number requested actually exists
    if ( ( ($page_num * $per_page) - $per_page) > $total_count) {
      $page_num--;
    }
  }

  $limit = "LIMIT ".$limit_start.", ".$per_page;

  $query = "SELECT * FROM `".BB2_DB_TABLE."` ".$where.$orderby.$limit;
  $result = bb2_db_query($query);
 
  //Display string of table to return
  $display .= '<br><span style="color: red;">Query... '.$query.'</span>';
  $display .= '<br><table border="1" style="color: #555555; font-size: small; background-color: white;">';
  $display .= '<tr style="color: black; font-weight: bold; text-decoration: underline; text-align: center; background-color: #888888;"><td>ID</td><td>IP</td><td>DATE</td><td>METHOD</td><td>URI</td><td>PROTOCOL</td><td>HEADERS</td><td>AGENT</td><td>ENTITY</td><td>KEY</td></tr>';
 
  $alternate_rows = 'even';
  if ($result) { //Make sure it found some rows
    foreach ($result as $array) {

      if (empty($array['request_entity'])) { //This field can be blank alot, so put a space in it.
        $array['request_entity'] = '&nbsp;';
      }

      if ($array['key'] == '00000000') { //Assumes that only 00000000 is permitted. Check with Michael
        $array['key'] = 'Permitted<br>'.$array['key'];
      } else {
        $array['key'] = 'DENIED<br>'.$array['key'];
      }

      if ($alternate_rows == 'even') { //Alternating colors for each row
        $alternate_rows = 'odd';
        $row_color = '#FFFFFF';
      } else {
        $alternate_rows = 'even';
        $row_color = '#DDDDDD';
      }
 
      $display .= '<tr style="background-color: '.$row_color.';"><td>'.$array['id'].'</td><td>'.$array['ip'].'</td><td>'.$array['date'].'</td><td>'.$array['request_method'].'</td><td>'.$array['request_uri'].'</td><td>'.$array['server_protocol'].'</td><td>'.$array['http_headers'].'</td><td>'.$array['user_agent'].'</td><td>'.$array['request_entity'].'</td><td>'.$array['key'].'</td></tr>';
    }
   
    $limit_start++; //Since record 0 is actually the 1st record, we will add one to make the first record=1
 
  } else { //No rows found
    $total_count = 0;
    $display .= '<tr style="background-color: '.$row_color.';"><td colspan="10">No records exist in that range</td>';
  }

  $display .= '</table>';
 
  //This returns all the info you need to display
  // RETURN VALUES:
  //  Function will return an array($limit_start, $limit_end, $total_count, $page_num, $display)
  //  $limit_start: This is the first record number that it is displaying
  //  $limit_end:  This is the last record number that it is displaying
  //  $total_count: This is the total number of entries in the database
  //  $page_num: The actual page number that was displayed
  //  $display: This contains the html for the <table> that will be displayed
  $return_array = array($limit_start, $limit_end, $total_count, $page_num, $display);

return $return_array;
}

?>

You will need to change a few settings and enter your database info like your email, db-name, db-username, and db-password. You can also change the name of table if you want. Whatever table name you choose will be automatically created and setup properly for you.

Save this file as bad-behavior-phplist.php into the bad-behavior folder (the same folder where you find the bad-behavior-generic.php).

STEP 4 - Test it
Go to one your phpList subscribe pages or to an admin page, then select View Source from your browser, and you should see a couple bb2 javascript functions after the META tags in the HEAD section of the page.

Now if you set 'verbose'=TRUE in the bad-behavior-phplist.php file, this will log ALL activity to your phplist pages, including all permitted valid activity. Visit a couple different pages again, then check the database and you should see a couple entries have been added. You probably want to set 'verbose'=FALSE when you are done testing, otherwise it will create a HUGE db table very quickly.

That's it! Much easier than all the previous steps!!!

BONUS - DB Viewer
Okay, as a bonus I created a simple database viewer so you can actually see whats in the table without having to use a tool like phpMyAdmin.

Copy and paste the following code below into a file called
bad-behavior-simple-db-viewer.php
Code: Select all
<?php
//Bad Behavior - This include_once statement MUST be the very first item at the
//top of your page, or it will generate an WARNING and the following functions
//may not work: bb2_insert_head(), bb2_insert_stats(), bb2_db_viewer()
include_once('/home/path-to/bad-behavior/bad-behavior-phplist.php');
?>


<HTML>

<HEAD>


<!-- SAMPLE SCREENER FUNCTION INCLUDE -->
<?php
//Bad Behavior - This code should appear in the <HEAD> section of your page
// and will add the required JavaScript to your page.
if (function_exists('bb2_insert_head')) {
  bb2_insert_head();
}
?>
<!-- END screener function include -->


</HEAD>

<BODY>


<!-- SAMPLE STATS DISPLAY -->
<?php
//Bad Behavior - This code can appear anywhere in your page (usually in your
// footer) and will show how many blocks Bad Behavior has made (if you have
// display_stats=true in the config file).
if (function_exists('bb2_insert_stats')) {
  bb2_insert_stats();
}
?>
<!-- END stats display -->


<!-- SAMPLE DB VIEWER -->
<FORM action="" method="post">
<span style="font-size: large; text-decoration: underline; font-weight: bold;">BAD BEHAVIOR - Simple Database Viewer</span>
<br>

<?php
if (function_exists('bb2_simple_db_viewer')) {
 
  $next =$_POST['next'];
  $prev = $_POST['prev'];
  $what = $_POST['what'];
  $page_num = $_POST['page_num'];
  $per_page = $_POST['per_page'];
  $sort_by = $_POST['sort_by'];
  $order_by = $_POST['order_by'];
  if (empty($what)) {
    $what = 0;
  }
  if (!isset($page_num)) {
    $page_num = 1;
  }
  if (!isset($per_page)) {
    $per_page = 5;
  }
  if (!isset($sort_by)) {
    $sort_by = 'date' ;
  }
  if (!isset($order_by)) {
    $order_by = 'DESC';
  }
 
  if (isset($next)) {
    $page_num = $page_num + 1;
  }
  if (isset($prev)) {
    $page_num = $page_num - 1;
    if ($page_num < 1) {
      $page_num = 1;
    }
  }
 
  if ($what == '0') {
    $select_view0 = 'selected="yes"';
    $what = 0;
  } elseif ($what == '1') {
    $select_view1 = 'selected="yes"';
    $what = 1;
  } elseif ($what == '2') {
    $select_view2 = 'selected="yes"';
    $what = 2;
  }
 
  if ($per_page == '5') {
    $select_pp5 = 'selected="yes"';
  } elseif ($per_page == '10') {
    $select_pp10 = 'selected="yes"';
  } elseif ($per_page == '15') {
    $select_pp15 = 'selected="yes"';
  } elseif ($per_page == '20') {
    $select_pp20 = 'selected="yes"';
  } elseif ($per_page == '25') {
    $select_pp25 = 'selected="yes"';
  } elseif ($per_page == '50') {
    $select_pp50 = 'selected="yes"';
  } elseif ($per_page == '100') {
    $select_pp100 = 'selected="yes"';
  }

  if ($sort_by == 'date') {
    $select_sort1 = 'selected="yes"';
  } elseif ($sort_by == 'request_uri') {
    $select_sort2 = 'selected="yes"';
  } elseif ($sort_by == 'key') {
    $select_sort3 = 'selected="yes"';
  }

  if ($order_by == 'ASC') {
    $select_order1 = 'selected="yes"';
  } elseif ($order_by == 'DESC') {
    $select_order2 = 'selected="yes"';
  }
 
  ///////////////////////////////////////////////////////////////////////////
  //bb2_simple_db_viewer()
  // VALID OPTIONS FOR THIS FUNCTIONS ARE:
  //  $what:  0=ALL entries  1=Permitted entries only  2=Denied entries only
  //  $page_num:  Any integer 1 or greater.
  //  $per_page:  Number of entries per page to display. Any integer 1 or greater.
  //  $sort_by:  'date' or 'request_uri' or 'key'
  //  $order_by: 'ASC' or 'DESC'
  // RETURN VALUES:
  //  Function will return an array($limit_start, $limit_end, $total_count, $page_num, $display)
  //  $limit_start: This is the first record number that it is displaying
  //  $limit_end:  This is the last record number that it is displaying
  //  $total_count: This is the total number of entries in the database
  //  $page_num: This is the actual page number being displayed
  //  $display: This contains the html for the <table> that will be displayed
  $result = bb2_simple_db_viewer($what, $page_num, $per_page, $sort_by, $order_by);
 
  $page_num = $result[3];

  $type = 'ALL records';
  if ($what == 1) {
  $type = 'PERMITTED records only';
  } elseif ($what == 2) {
    $type = 'DENIED records only';
  }

  echo '<input type="hidden" name="page_num" value="'.$page_num.'">';

  echo 'Displaying record(s)&nbsp;&nbsp;<b>'.$result[0].'</b> to <b>'.$result[1].'</b>&nbsp;&nbsp;of <b>'.$result[2].'</b> total ('.$type.').';
  echo '&nbsp;&nbsp;<input type="submit" name="prev" value="PREV">&nbsp;&nbsp;<input type="submit" name="next" value="NEXT">';
 
  echo '<br>VIEW:<select name="what"><option value="0" '.$select_view0.'>ALL entries<option value="1" '.$select_view1.'>PERMITTED entries<option value="2" '.$select_view2.'>DENIED entries</select>&nbsp;&nbsp;';
  echo 'SORT BY:<select name="sort_by"><option value="date" '.$select_sort1.'>Date<option value="request_uri" '.$select_sort2.'>Request Uri<option value="key" '.$select_sort3.'>Key</select>&nbsp;&nbsp;';
  echo 'ORDER BY:<select name="order_by"><option value="ASC" '.$select_order1.'>Ascending<option value="DESC" '.$select_order2.'>Descending</select>&nbsp;&nbsp;';
  echo 'PER PAGE:<select name="per_page"><option value="5" '.$select_pp5.'>5<option value="10" '.$select_pp10.'>10<option value="15" '.$select_pp15.'>15<option value="20" '.$select_pp20.'>20<option value="25" '.$select_pp25.'>25<option value="50" '.$select_pp50.'>50<option value="100" '.$select_pp100.'>100</select>&nbsp;<input type="submit" value="GO">';
 
  echo $result[4]; //display the <table>

  echo 'Displaying record(s)&nbsp;&nbsp;<b>'.$result[0].'</b> to <b>'.$result[1].'</b>&nbsp;&nbsp;of <b>'.$result[2].'</b> total ('.$type.').';
  echo '&nbsp;&nbsp;<input type="submit" name="prev" value="PREV">&nbsp;&nbsp;<input type="submit" name="next" value="NEXT">';

}
?>
<!-- END db viewer -->


</FORM>

</BODY>

</HTML>

Change the 'path-to' in include_once statement line to reflect the location of your bad-behavior folder.

You can this put this file pretty much anywhere you want on your site (probably a password protected directory), and then just access it from your browser and you are good to go.
cjb
phpLister
 
Posts: 11
Joined: 2:04am, Wed 30 Jun, 2010

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby psykotik » 7:39am, Tue 24 Sep, 2013

For the record: on phlist version 3, files to be modified are located in /admin/ui/dressprow/

You have to both modify publicpagetop.php and pagetop_minimal.php
psykotik
phpLister
 
Posts: 6
Joined: 10:50am, Sat 24 Dec, 2011

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby farmrchrys » 8:20pm, Sat 02 Nov, 2013

Hello, I followed cjb's instructions and the last add on about modifying the two files in version 3, but running the test (admin pages load normally) I see no bb2 javascript functions in the header and no table was created in the db. Any suggestions?
farmrchrys
phpLister
 
Posts: 11
Joined: 7:43pm, Sat 02 Nov, 2013

Re: [mod] Spam Block Prevention mod - Bad Behaviour 2

Postby alloallo » 4:52am, Mon 24 Feb, 2014

Anyone know if phpList now includes Bad Behaviour or something similar? If not, why not?
alloallo
PL Nut
 
Posts: 42
Joined: 3:59am, Fri 30 May, 2008
Location: Toronto

Previous

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests