#29151 [Ana]: bugs.php.net fails to insert vote
| From: | jacques@php.net | Date: | Wed, 04 Aug 2004 17:27:44 +0000 |
| Subject: | #29151 [Ana]: bugs.php.net fails to insert vote | ||
| References: | 1 | Groups: | php.mirrors |
| Request: | Send a blank email to php-mirrors+get-25669@lists.php.net to get a copy of this message | ||
ID: 29151
Updated by: jacques@php.net
Reported By: fdsoft at pganet dot com
Status: Analyzed
Bug Type: Website problem
Operating System: irrelevant
PHP Version: Irrelevant
Assigned To: jacques
New Comment:
I've updated the patchfile and uploaded it to
http://www.powertrip.co.za/patches/php-bugs-web-29151.diff
for review.
Previous Comments:
------------------------------------------------------------------------
[2004-08-04 19:23:17] jacques@php.net
Okay I've slightly changed the patch. Which uses ip2long on the
current IP it's working through to validate if the string is really an
ip address (http://php.mirrors.powertrip.co.za/ip2long) if we get -1
back from ip2long we know this a valid ip address.
if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
if (ip2long($ips[$i]) != -1) {
$ip = $ips[$i];
break;
}
}
My pseudo code test returns the expected ip address even when I use
'unknown' and various other varients for the forwarded address.
------------------------------------------------------------------------
[2004-08-04 15:49:55] goba@php.net
OK then it still needs to be tested whether the found IP matches an IP
address regexp.
------------------------------------------------------------------------
[2004-08-04 15:26:14] fdsoft at pganet dot com
I have a feeling this still isn't going to work for me.
As I said, $_SERVER['HTTP_X_FORWARED_FOR"] is set to the
string "unknown"
No IP numbers anywhere at all in it, or any kind of a
number.
This is a common configuration option for the Squid
proxy.
------------------------------------------------------------------------
[2004-08-04 14:19:26] derick@php.net
Make sure to test it carefully!
------------------------------------------------------------------------
[2004-08-04 14:08:48] jacques@php.net
I'll commit the following patch later today if there are no problems
with the suggested patch. It's based on a patch from phpweb.
--jm
cvs diff -u include/functions.inc vote.php
Index: include/functions.inc
===================================================================
RCS file: /repository/php-bugs-web/include/functions.inc,v
retrieving revision 1.127
diff -u -r1.127 functions.inc
--- include/functions.inc 13 Jul 2004 21:51:25 -0000 1.127
+++ include/functions.inc 4 Aug 2004 12:04:10 -0000
@@ -578,4 +578,35 @@
return array(" AND MATCH (bugdb.email,sdesc,ldesc) AGAINST ('"
. addslashes($search) . "')", $ignored);
}
+/* Figure out which IP the user is coming from avoiding RFC 1918 space
*/
+function get_real_ip () {
+ $ip = false;
+
+ /**
+ * User is behind a proxy and check that we discard RFC1918 IP
+ * addresses if they are behind a proxy then only figure out
which
+ * IP belongs to the user. Might not need any more hacking
if
+ * there is a squid reverse proxy infront of apache.
+ */
+ if (!empty($HTTP_X_FORWARDED_FOR)) {
+ $ips = explode (", ", $HTTP_X_FORWARDED_FOR);
+ if ($ip) { array_unshift($ips, $ip); $ip = false; }
+ for ($i = 0; $i < count($ips); $i++) {
+ /**
+ * Skip RFC 1918 IP's 10.0.0.0/8, 172.16.0.0/12
and
+ * 192.168.0.0/16 -- jim kill me later with my
regexp pattern
+ * below.
+ */
+ if (!eregi ("^(10|172\.16|192\.168)\.",
$ips[$i])) {
+ $ip = $ips[$i];
+ break;
+ }
+ }
+ }
+
+ /**
+ * Return with the found IP or the remote address
+ */
+ return ($ip ? $ip : $REMOTE_ADDR);
+}
?>
Index: vote.php
===================================================================
RCS file: /repository/php-bugs-web/vote.php,v
retrieving revision 1.9
diff -u -r1.9 vote.php
--- vote.php 23 Jan 2004 03:05:28 -0000 1.9
+++ vote.php 4 Aug 2004 12:04:10 -0000
@@ -21,7 +21,7 @@
or die("Unable to connect to SQL server.");
@mysql_select_db("php3");
-$ip = ip2long($HTTP_X_FORWARDED_FOR ? $HTTP_X_FORWARDED_FOR :
$REMOTE_ADDR);
+$ip = ip2long(get_real_ip());
// TODO: check if ip address has been banned. hopefully this will
// never need to be implemented.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29151
--
Edit this bug report at http://bugs.php.net/?id=29151&edit=1