[FIXED] Upgrade not showing in version box


#1

I am running version 1.2 behind a firewall/proxy server for local servers. Working great!!! But the new version is not showing up in the version/status box for one-click upgrade. Will it not work behind a firewall/proxy? Will I have to do the 3 step process?

Thanks for the help and a great tool!


(vipsoft) #2

Piwik tries to connect directly to the piwik.org servers. Your firewall may be blocking these outgoing http requests.

Do you have a proxy for outgoing connections? If there’s sufficient interest, we’ll add outgoing proxy support.


#3

Yes we have an outgoing proxy.


#4

Little Patch for core/Http.php from behind A proxy. (Works only with PHP CuRL-Pugin yet!)

It has to be discussed if the Password should be in this form in the config-file.


--- core/Http.php       2011-01-26 16:53:24.000000000 +0100
+++ core/Http.php.new   2011-04-19 16:02:03.294925000 +0200
@@ -95,6 +95,18 @@
                $contentLength = 0;
                $fileLength = 0;

+               $proxyHost = "";
+               $proxyPort = "";
+               $proxyUser = "";
+               $proxyPass = "";
+
+               if ( Zend_Registry::get('config')->General->proxyhost ) {
+                       $proxyHost = Zend_Registry::get('config')->General->proxyhost;
+                       $proxyPort = Zend_Registry::get('config')->General->proxyport;
+                       $proxyUser = Zend_Registry::get('config')->General->proxyuser;
+                       $proxyPass = Zend_Registry::get('config')->General->proxypass;
+               }
+
                if($method == 'socket')
                {
                        // initialization
@@ -284,6 +296,30 @@
                {
                        $ch = @curl_init();

+                       if ( $proxyHost )
+                       {
+                               if ( $proxyPort ) {
+                                       @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+                                       @curl_setopt($ch, CURLOPT_PROXY, $proxyHost.':'.$proxyPort);
+                                       @curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort.':'.$proxyPort);
+                               }
+                               else
+                               {
+                                        throw new Exception('curl_config: proxyhost but no port in [General]-section defined!');
+                               }
+                               if ( $proxyUser )
+                               {
+                                       if ( $proxyPass )
+                                       {
+                                               @curl_setopt($ch, CURLOPT_USERPWD, $proxyUser.':'.$proxyPass);
+                                       }
+                                       else
+                                       {
+                                                throw new Exception('curl_config: proxyuser but no proxypass in [General]-section defined!');
+                                       }
+                               }
+                       }
+
                        $curl_options = array(
                                // internal to ext/curl
                                CURLOPT_BINARYTRANSFER => is_resource($file),

Then you have to add this Lines to the “General” section in your config.ini.php:


[general]
proxyhost = "your proxy"
proxyport = "your proxy port"

And if needed:


;proxyuser = "your proxy user"
;proxypass = "your proxy pass"


(vipsoft) #5

Thanks. I’ve added a link to your example in the ticket. Outgoing HTTP proxy (host:port and authorization) · Issue #1869 · matomo-org/matomo · GitHub


#6

Hello,

here is an patch who also works with fopen and socket.

I coudn’t test the authentication for the proxy-server.

Beware of the smilies in the source code :wink: !


--- core/Http.php       2011-04-20 14:20:22.232017000 +0200
+++ core/Http.php.new   2011-04-20 14:22:37.108235000 +0200
@@ -95,6 +95,18 @@
                $contentLength = 0;
                $fileLength = 0;

+               $proxyHost = "";
+               $proxyPort = "";
+               $proxyUser = "";
+               $proxyPass = "";
+
+               if ( Zend_Registry::get('config')->General->proxyhost ) {
+                       $proxyHost = Zend_Registry::get('config')->General->proxyhost;
+                       $proxyPort = Zend_Registry::get('config')->General->proxyport;
+                       $proxyUser = Zend_Registry::get('config')->General->proxyuser;
+                       $proxyPass = Zend_Registry::get('config')->General->proxypass;
+               }
+
                if($method == 'socket')
                {
                        // initialization
@@ -111,6 +123,10 @@
                        $host = $url['host'];
                        $port = isset($url['port)']) ? $url['port'] : 80;
                        $path = isset($url['path']) ? $url['path'] : '/';
+
+                       $connectHost = $host;
+                       $connectPort = $port;
+
                        if(isset($url['query']))
                        {
                                $path .= '?'.$url['query'];
@@ -118,8 +134,21 @@
                        $errno = null;
                        $errstr = null;

+                       if ($proxyHost)
+                       {
+                               if ($proxyPort)
+                               {
+                                       $connectHost = $proxyHost;
+                                       $connectPort = $proxyPort;
+                               }
+                               else
+                               {
+                                       throw new Exception('socket_config: proxyhost but no proxyport in [General]-section defined!' );
+                               }
+                       }
+
                        // connection attempt
-                       if (($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout)) === false || !is_resource($fsock))
+                       if (($fsock = @fsockopen($connectHost, $connectPort, $errno, $errstr, $timeout)) === false || !is_resource($fsock))
                        {
                                if(is_resource($file)) { @fclose($file); }
                                throw new Exception("Error while connecting to: $host. Please try again later. $errstr");
@@ -132,8 +161,22 @@
                                ."User-Agent: Piwik/".Piwik_Version::VERSION.($userAgent ? " $userAgent" : '')."\r\n"
                                .'Referer: http://'.Piwik_Common::getIpString()."/\r\n"
                                ."Connection: close\r\n"
-                               ."\r\n"
                        );
+                       if ($proxyHost)
+                       {
+                               if ($proxyUser)
+                               {
+                                       if ($proxyPass)
+                                       {
+                                               fwrite($fsock,"Proxy-Authorization: Basic ".base64_encode("$proxyuser:$proxypass") ."\r\n");
+                                       }
+                                       else
+                                       {
+                                               throw new Exception('socket_config: proxyuser  but no proxypass in [General]-section defined!');
+                                       }
+                               }
+                       }
+                       fwrite($fsock,"\r\n");

                        $streamMetaData = array('timed_out' => false);
                        @stream_set_blocking($fsock, true);
@@ -262,6 +305,30 @@
                                                'timeout' => $timeout, // PHP 5.2.1
                                        )
                                );
+                               if ($proxyHost)
+                               {
+                                       if ($proxyPort)
+                                       {
+                                               $stream_options['http']['proxy'] = 'tcp://'.$proxyHost.':'.$proxyPort;
+                                       }
+                                       else
+                                       {
+                                               throw new Exception('fopen_config: proxyhost but no port in [General]-section defined!');
+                                       }
+                                       if ($proxyUser)
+                                       {
+                                               if ($proxyPass)
+                                               {
+                                                       $stream_options['http']['header'] = $stream_options['http']['header']."\r\n"
+                                                                                         . "Proxy-Authorization: Basic "
+                                                                                         . base64_encode("$proxyUser:$proxyPass") . "\r\n\r\n";
+                                               }
+                                               else
+                                               {
+                                                       throw new Exception('fopen_config: proxyUser but no proxyPass in [General]-section defined!');
+                                               }
+                                       }
+                               }
                                $ctx = stream_context_create($stream_options);
                        }

@@ -284,6 +351,30 @@
                {
                        $ch = @curl_init();

+                       if ( $proxyHost )
+                       {
+                               if ( $proxyPort ) {
+                                       @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+                                       @curl_setopt($ch, CURLOPT_PROXY, $proxyHost.':'.$proxyPort);
+                                       @curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort.':'.$proxyPort);
+                               }
+                               else
+                               {
+                                        throw new Exception('curl_config: proxyhost but no port in [General]-section defined!');
+                               }
+                               if ( $proxyUser )
+                               {
+                                       if ( $proxyPass )
+                                       {
+                                               @curl_setopt($ch, CURLOPT_USERPWD, $proxyUser.':'.$proxyPass);
+                                       }
+                                       else
+                                       {
+                                                throw new Exception('curl_config: proxyuser but no proxypass in [General]-section defined!');
+                                       }
+                               }
+                       }
+
                        $curl_options = array(
                                // internal to ext/curl
                                CURLOPT_BINARYTRANSFER => is_resource($file),


Greetings,
Ralf


(vipsoft) #7

Thanks for patch. I’ve fixed the problems with proxyauth, so this will be in 1.5. (Look for the [proxy] section in global.ini.php.)