Proxy Hide URL shows internal IP of server sending info Part 2:

Well per Matt’s instructions I have updated to the most recent Beta build of Piwik. 1.12 p19. This did solve one problem normal tracking is back to working BUT the Hide URL is still sending the internal IP of the server sending the hide url request to the Piwik server. So starting the new thread per his request.

Server specs:
Web server with Piwik Hide URL on it:
Arch Linux on ec2

php --version
PHP 5.4.15 (cli) (built: May 12 2013 13:11:23) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

nginx version: nginx/1.4.1

PHP 5.4.15 (fpm-fcgi) (built: May 12 2013 13:12:40)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Web server with Piwik installed on it:
Arch Linux on ec2

nginx version: nginx/1.4.1

mysql  Ver 15.1 Distrib 5.5.31-MariaDB, for Linux (x86_64) using readline 5.1

PHP 5.4.15 (fpm-fcgi) (built: May 12 2013 13:12:40)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

PHP 5.4.15 (cli) (built: May 12 2013 13:11:23) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Log from Piwik server for the request from the web server.

Internal.IP.Here - - [24/May/2013:10:52:42 -0700] "GET /piwik.js HTTP/1.0" 200 22142 "-" "-"
Internal.IP.Here - - [24/May/2013:10:52:44 -0700] "GET /piwik.php?cip=CLI.ENT.I.P.HERE&token_auth=MyTokenAuthCode&action_name=Page+Title+Here%21&idsite=2&rec=1&r=029089&h=10&m=52&s=11&url=http%3A%2F%2Fwww.MySiteBeingTracked.com%2F&_id=c19cd83bbc6163cc&_idts=1369113127&_idvc=15&_idn=0&_refts=0&_viewts=1369415672&pdf=0&qt=0&realp=0&wma=0&dir=0&fla=1&java=1&gears=0&ag=0&cookie=1&res=1680x945&gt_ms=241& HTTP/1.0" 200 43 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0"

Log from Web Server serving the site being tracked:

Client.IP.Here - - [24/May/2013:17:52:44 +0000] "GET /piwik.php?action_name=Site%20Title%20Here!&idsite=2&rec=1&r=029089&h=10&m=52&s=11&url=http%3A%2F%2Fwww.MySiteBeingTracked.com%2F&_id=c19cd83bbc6163cc&_idts=1369113127&_idvc=15&_idn=0&_refts=0&_viewts=1369415672&pdf=0&qt=0&realp=0&wma=0&dir=0&fla=1&java=1&gears=0&ag=0&cookie=1&res=1680x945&gt_ms=241 HTTP/1.1" 200 54 "http://www.MySiteBeingTracked.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0"

How to duplicate:

  1. Install Piwik tracking code on webserver site to be tracked. Per the instruction in the wiki/FAQ
  2. Hit the page
  3. See the internal IP of the web server serving the web site to be tracked.

1a. Add in normal tracking code to the web site.
2a. Hit the page
3a. See the internal IP show up of the web server AND see the actual client IP show up.
4. Remove Hide URL tracking
5. Hit Page
6. See only the client IP as one would expect for tracking.

The web server serving the site is NOT behind a proxy, web accelerator or anything of that nature.

The only other issue I see is that the JS tracking does not register the hit either, even though the Piwik server sees the hits per the access logs.

Client.IP.Here - - [24/May/2013:11:02:55 -0700] "GET /piwik.php?idsite=1&rec=1 HTTP/1.1" 200 54 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0"
Client.IP.Here - - [24/May/2013:11:02:56 -0700] "GET /piwik.php?idsite=1&rec=1 HTTP/1.1" 200 54 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0"

So does anyone have any ideas on this? Before posting and updating to these Beta builds, I had setup Piwik and the webserver twice, to make sure I did not miss something. I have almost an identical setup on another network where these issues are not present. Would posting my tracking code that I have put in my web page help any? I can post any other info that is required to help sort this out.

Thanks for the time and help!!!

EDIT: Forgot to state the web server serving the website being tracked was initially on Apache, but setup NGINX this go around as I prefer this webserver personally and the exact same issue showed up.

Such hit: Client.IP.Here - - [24/May/2013:11:02:55 -0700] “GET /piwik.php?idsite=1&rec=1 HTTP/1.1” 200 54 “-” “Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0”

this will not record anything as there is not enough data to track.

However this should work: Client.IP.Here - - [24/May/2013:17:52:44 +0000] “GET /piwik.php?action_name=Site%20Title%20Here!&idsite=2&rec=1&r=029089&h=10&m=52&s=11&url=http%3A%2F%2Fwww.MySiteBeingTracked.com%2F&_id=c19cd83bbc6163cc&_idts=1369113127&_idvc=15&_idn=0&_refts=0&_viewts=1369415672&pdf=0&qt=0&realp=0&wma=0&dir=0&fla=1&java=1&gears=0&ag=0&cookie=1&res=1680x945&gt_ms=241 HTTP/1.1” 200 54 “http://www.MySiteBeingTracked.com/” “Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0”

so not sure why you have these “empty requests” piwik.php?idsite=1&rec=1 ?

I am not sure either but that is exactly how a single hit is registered in the logs, first the empty set then the one with more data. But still regardless its putting the client’s IP as the internal IP of the webserver sending the Proxy Hide URL to the Piwik server.

I even setup 2 new servers all using your beta builds and not a single thing different in the stats. So what is going on here. I have an entire other Piwik install that is setup identically to this that this does not happen on. I have tried the webserver with Apache and NGINX and the Piwik server with NGINX and Apache.

Anything I can actually try other than updating more beta builds to see if it just automagically gets fixed.

Thanks.

EDIT: Forgot to state that I am on 1.12-b22

EDIT2: Also normal tracking shows sites properly it is only the Hide URL script that does not take the proper IP. So what I am thinking is that its actually taking the first IP entry that shows in the logs and not the actual IP that is placed after
cip=
in the string that gets sent. At least that is the best I can come up with at this point.

EDIT3: Not sure if this applies but I am getting this error in the browser popping up randomly with b22

Script: https://www.piwik.mysite/index.php?module=Proxy&action=getJs&cb=b29be1ae4ad133e49d7d8bdeb72f3d40:1029

has the option to let the script keep running or stop the script or debug. If I click debug it does nothing. So been clicking stop.

I have an idea. IN the piwik.php on the tracked website (the proxy) add at the top: var_dump($_SERVER);

Then go to this page and copy here ( or email me matt@piwik.org) the result (with link to this forum).

I suspect the IP is set in the _SERVER but not in REMOTE_ADDR which is what we read to send the IP: https://github.com/piwik/piwik/blob/master/misc/proxy-hide-piwik-url/piwik.php#L62

Add what you suggested and also the same with REMOTE_ADDR and both give NULL as the result.

Here is how I added snipped to save space


<?php
var_dump($SERVER);
var_dump($REMOTE_ADDR);

/**
 * Piwik - Open source web analytics
 * Piwik Proxy Hide URL
 *
 * @link http://piwik.org/faq/how-to/#faq_132
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */


Result


NULL
NULL
/*!
 * Piwik - Web Analytics
 *
 * JavaScript tracking client
 *
 * @link http://piwik.org
 * @source https://github.com/piwik/piwik/blob/master/js/piwik.js
 * @license http://piwik.org/free-software/bsd/ Simplified BSD (also in js/LICENSE.txt)
 */

Could the issue maybe be the server where the proxy script is, is not setting either properly for some reason?

Thanks

Change to $_SERVER only

Matt,

You were correct its reading SERVER_ADDR.

The internal IP is listed as SERVER_ADDR string(12) and the client IP is REMOTE_ADDR string(14).

EDIT: Matt if you need the full output to verify let me know and I will email it to you, but the above listed is how the IP is recognized. Thanks.

So what is the proper way to make it read REMOTE_ADDR instead?

I have also now run into the same issue as BeekerMeep in this thread 301 Moved Permanently So I am thinking Hide URL is in need of some love as that was the last part for Hide URL I needed to test and setup but hit his problem as well.

Replace REMOTE_ADDR with REMOTE_ADDR in the piwik.php proxy file, it should then work!

Is there a typo in that? You said to replace with the same thing, or am I not getting what you mean?

replace REMOTE_ADDR by SERVER_ADDR in piwik.php

It is still showing the Internal IP for the hit and not the client IP.

I changed the line as so.

$url = sprintf("%spiwik.php?cip=%s&token_auth=%s&", $PIWIK_URL, @$_SERVER['SERVER_ADDR'], $TOKEN_AUTH);

output from that var dump


["REMOTE_ADDR"]=>
  string(14) "248.XX.XXX.XXX"
  ["REMOTE_PORT"]=>
  string(5) "44609"
  ["SERVER_ADDR"]=>
  string(12) "10.254.58.85"
  ["SERVER_PORT"]=>
  string(2) "80"

That is the output from when I had SERVER_ADDR in there over the REMOTE_ADDR setting. So there was no difference in what Piwik sees as the client’s actual IP.

If one of these IP is correct, and you set it in the cip=XXX
then Piwik should track it correctly (assuming you set the token_auth to “admin” user )