[geeklog-cvs] Geeklog-1.x/plugins/spamx EditIP.Admin.class.php, 1.5.2.1, 1.5.2.2 IP.Examine.class.php, 1.9, 1.9.2.1
Dirk Haun
dhaun at qs1489.pair.com
Sun Dec 16 12:14:40 EST 2007
Update of /cvsroot/geeklog/Geeklog-1.x/plugins/spamx
In directory qs1489.pair.com:/tmp/cvs-serv81350/plugins/spamx
Modified Files:
Tag: geeklog_1_4_1_1
EditIP.Admin.class.php IP.Examine.class.php
Log Message:
Allow blocking of IP ranges, using CIDR or simple x-y notation (ported over from the trunk)
Index: IP.Examine.class.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/plugins/spamx/IP.Examine.class.php,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -C2 -d -r1.9 -r1.9.2.1
*** IP.Examine.class.php 6 Sep 2006 05:31:00 -0000 1.9
--- IP.Examine.class.php 16 Dec 2007 17:14:38 -0000 1.9.2.1
***************
*** 5,9 ****
* This is the IP BlackList Examine class for the Geeklog Spam-X plugin
*
! * Copyright (C) 2004-2006 by the following authors:
* Author Tom Willett tomw AT pigstye DOT net
*
--- 5,9 ----
* This is the IP BlackList Examine class for the Geeklog Spam-X plugin
*
! * Copyright (C) 2004-2007 by the following authors:
* Author Tom Willett tomw AT pigstye DOT net
*
***************
*** 20,24 ****
* Include Abstract Examine Class
*/
! require_once($_CONF['path'] . 'plugins/spamx/' . 'BaseCommand.class.php');
/**
--- 20,24 ----
* Include Abstract Examine Class
*/
! require_once $_CONF['path'] . 'plugins/spamx/' . 'BaseCommand.class.php';
/**
***************
*** 58,73 ****
function reexecute($comment, $date, $ip, $type)
{
! return $this->_process($ip);
}
! /**
! * Private internal method, this actually processes a given ip
! * address against a blacklist of IP regular expressions.
! *
! * @param $ip string IP address of comment poster
! */
function _process($ip)
{
! global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
--- 58,149 ----
function reexecute($comment, $date, $ip, $type)
{
! return $this->_process($ip);
}
! /**
! * Private internal method to match an IP address against a CIDR
! *
! * @param string $iptocheck IP address to check
! * @param string $CIDR IP address range to check against
! * @return boolean true if IP falls into the CIDR, else false
! *
! * Original author: Ian B, taken from
! * http://www.php.net/manual/en/function.ip2long.php#71939
! *
! */
! function _matchCIDR ($iptocheck, $CIDR)
! {
! // get the base and the bits from the ban in the database
! list($base, $bits) = explode('/', $CIDR);
!
! // now split it up into its classes
! $classes = explode('.', $base);
! $elements = count($classes);
! if ($elements < 4) {
! for ($i = $elements; $i < 4; $i++) {
! $classes[$i] = 0;
! }
! }
! list($a, $b, $c, $d) = $classes;
!
! // now do some bit shifting/switching to convert to ints
! $i = ($a << 24) + ($b << 16) + ($c << 8) + $d;
! $mask = $bits == 0 ? 0 : (~0 << (32 - $bits));
!
! // here's our lowest int
! $low = $i & $mask;
!
! // here's our highest int
! $high = $i | (~$mask & 0xFFFFFFFF);
!
! // now split the ip were checking against up into classes
! list($a, $b, $c, $d) = explode('.', $iptocheck);
!
! // now convert the ip we're checking against to an int
! $check = ($a << 24) + ($b << 16) + ($c << 8) + $d;
!
! // if the ip is within the range, including
! // highest/lowest values, then it's witin the CIDR range
! if (($check >= $low) && ($check <= $high)) {
! return true;
! }
!
! return false;
! }
!
! /**
! * Private internal method to match an IP address against an address range
! *
! * @param string $ip IP address to check
! * @param string $range IP address range to check against
! * @return boolean true if IP falls into the IP range, else false
! *
! * Original authors: dh06 and Stephane, taken from
! * http://www.php.net/manual/en/function.ip2long.php#70707
! *
! */
! function _matchRange ($ip, $range)
! {
! $d = strpos ($range, '-');
! if ($d !== false) {
! $from = ip2long (trim (substr ($range, 0, $d)));
! $to = ip2long (trim (substr ($range, $d + 1)));
!
! $ip = ip2long ($ip);
! return (($ip >= $from) && ($ip <= $to));
! }
!
! return false;
! }
!
! /**
! * Private internal method, this actually processes a given ip
! * address against a blacklist of IP regular expressions.
! *
! * @param $ip string IP address of comment poster
! */
function _process($ip)
{
! global $_CONF, $_TABLES, $_USER, $LANG_SX00, $result;
if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
***************
*** 84,90 ****
$ans = 0;
! for ($i = 1; $i <= $nrows; $i++) {
list ($val) = DB_fetchArray ($result);
! if ( preg_match ("#$val#i", $ip)) {
$ans = 1; // quit on first positive match
SPAMX_log ($LANG_SX00['foundspam'] . $val .
--- 160,176 ----
$ans = 0;
! for ($i = 0; $i < $nrows; $i++) {
list ($val) = DB_fetchArray ($result);
!
! $matches = false;
! if (strpos ($val, '/') !== false) {
! $matches = $this->_matchCIDR ($ip, $val);
! } else if (strpos ($val, '-') !== false) {
! $matches = $this->_matchRange ($ip, $val);
! } else {
! $matches = (preg_match ("#$val#i", $ip) == 0 ? false : true);
! }
!
! if ($matches) {
$ans = 1; // quit on first positive match
SPAMX_log ($LANG_SX00['foundspam'] . $val .
***************
*** 94,97 ****
--- 180,184 ----
}
}
+
return $ans;
}
Index: EditIP.Admin.class.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/plugins/spamx/EditIP.Admin.class.php,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -C2 -d -r1.5.2.1 -r1.5.2.2
*** EditIP.Admin.class.php 6 May 2007 08:26:36 -0000 1.5.2.1
--- EditIP.Admin.class.php 16 Dec 2007 17:14:38 -0000 1.5.2.2
***************
*** 68,72 ****
$display .= '<p>' . $LANG_SX00['e2'] . '</p>' . LB;
$display .= '<form method="POST" action="' . $_CONF['site_admin_url'] . '/plugins/spamx/index.php?command=EditIP">' . LB;
! $display .= '<input type="text" size ="30" name="pentry"> ';
$display .= '<input type="submit" name="paction" value="' . $LANG_SX00['addentry'] . '">' . LB;
$display .= '</form>' . LB;
--- 68,72 ----
$display .= '<p>' . $LANG_SX00['e2'] . '</p>' . LB;
$display .= '<form method="POST" action="' . $_CONF['site_admin_url'] . '/plugins/spamx/index.php?command=EditIP">' . LB;
! $display .= '<input type="text" size ="31" name="pentry"> ';
$display .= '<input type="submit" name="paction" value="' . $LANG_SX00['addentry'] . '">' . LB;
$display .= '</form>' . LB;
More information about the geeklog-cvs
mailing list