Ticket #2727 (closed Patches: fixed)

Opened 9 months ago

Last modified 5 months ago

Online Upgrade not possible behind a proxy server

Reported by: millst Assigned to: gregmac
Priority: trivial Milestone: 2.5
Component: Core - Module Admin Version: SVN-HEAD
Keywords: proxy Cc:
Confirmation: Need testing SVN Revision (if applicable):
Backend Engine: All Backend Engine Version:

Description (Last modified by p_lindheimer)

It is not possible to upgrade freepbx if the server is behind a proxy server. The module admin simply reports it is unable to access mirror.freepbx.org.

The following patch is suggested to make online upgrades more flexible and to enable them to work in a variety of network scenarios including behind a proxy server.

The patch would allow freepbx to use the http_proxy environment variable for upgrades.

The patch downloads the upgrade file to a temporary location in the file system using the standard wget command and then opens the file directly from the file system rather than trying to connect directly over the internet. Wget is a standard application available on nearly all systems and support http proxy functions.

the following goes in functions.inc.php in function module_getonlinexml

Index: functions.inc.php
===================================================================
--- functions.inc.php   (revision 5723)
+++ functions.inc.php   (working copy)
@@ -2129,7 +2129,11 @@
                }
                //$fn = "/usr/src/freepbx-modules/modules.xml";
                $data = @ file_get_contents($fn);
-               $module_getonlinexml_error = empty($data);
+               if (empty($data)) {
+                       exec("wget -O - $fn 2> /dev/null", $data_arr, $retcode);
+                       $data = implode("\n",$data_arr);
+                       $module_getonlinexml_error = ($retcode == 0)?false:true;
+               }
 
                $old_xml = array();
                $got_new = false;

then these three lines go just before the $headers = get_headers_assoc($url); line

        $dl_module = basename($url);
        system("wget $url -O /tmp/freepbx/$dl_module");
        $url = "/tmp/freepbx/$dl_module";
        $headers = get_headers_assoc($url);

This will make proxy and connection issues almost redundant as it uses wget which is much more configurable for the various networks around.

Attachments

functions.inc.php.patch (1.8 kB) - added by millst on 03/11/08 20:27:57.

Change History

03/07/08 09:02:23 changed by p_lindheimer

  • confirmation changed from Unreviewed to Need Feedback.
  • description changed.
  • milestone changed from Cut Line to 3.0.

can you provide those as a patch file and attach them to this ticket please:

diff -ubB functions.inc.php.original functions.inc.php.modified > functions.inc.php.patch

03/10/08 14:35:11 changed by millst

ok, added the patch file, my apologies, first time I've done this.

03/10/08 17:35:13 changed by p_lindheimer

  • description changed.

I like the concept. I'm thinking it may be better to first try the file_get_contents() directly and fallback on the wget. I also don't like the idea of a temporary file fi it can be helped. Here is some code that I think will replace the first part of the patch:

Index: functions.inc.php
===================================================================
--- functions.inc.php   (revision 5723)
+++ functions.inc.php   (working copy)
@@ -2129,7 +2129,11 @@
                }
                //$fn = "/usr/src/freepbx-modules/modules.xml";
                $data = @ file_get_contents($fn);
-               $module_getonlinexml_error = empty($data);
+               if (empty($data)) {
+                       exec("wget -O - $fn 2> /dev/null", $data_arr, $retcode);
+                       $data = implode("\n",$data_arr);
+                       $module_getonlinexml_error = ($retcode == 0)?true:false;
+               }
 
                $old_xml = array();
                $got_new = false;

If you could test it, and it works, then is there something we could do like that for your other part of the patch. I didn't get a chance to look at that code carefully. My change from yours is simply replacing the temp file with '-' for stdout...

03/10/08 21:36:28 changed by millst

I checked your code and it works great, although I can't test the direct connection scenario (only the failure scenario). I really like that it only tries wget if the direct connection fails which makes it fairly transparent from a users perspective. The failure message could be changed to say "Connection failed, if you are behind a proxy try setting the http_proxy environment variable". Haven't had a chance to look at doing the same thing for the other call but may get a chance tomorrow, don't see why it won't work for that as well.

03/11/08 20:27:57 changed by millst

  • attachment functions.inc.php.patch added.

03/11/08 20:32:33 changed by millst

retested and added the additional call (see attached file). I'm a little dubious about the second call and whether I have that right.

this works behind a proxy but i have no way of testing a direct connection, or which method it is using and when (not a php expert in case you haven't guessed).

05/20/08 12:45:31 changed by otbl

Update behind a proxy

I found the following article:

http://bugs.php.net/bug.php?id=29280

The issue is that php use a defaul streaming context that not includes any proxy you have to set it up manualy in "/var/www/html/admin/functions.inc.php"

$opts = array('http' => array('request_fulluri' => true, 'proxy' =>'tcp://192.168.0.1:8080')); $context _stream = stream_context_create($opts);

That create a new context using proxy address.

These 2 line should be present before each file_get_contents invoking an URL or fopen for retrieving modules.

Also you need to modify each file_get_contents and fopen adding ".false,$context_stream" as leadin parameters

Add the following 2 line at the top of these functions :

function module_getonlinexml function module_get_annoucements function module_download function _module_readxml

Near line 1725 :

change : $data = @ file_get_contents($fn); by : $data = @ file_get_contents($fn,false,$context _stream );

Near line 2929 :

change : $announcement = @ file_get_contents("http://mirror.freepbx.org/version-".getversion().".html".$options); by : $announcement = @ file_get_contents("http://mirror.freepbx.org/version-".getversion().".html".$options,false,$context _stream);

Near line 2335: change : if (!$dp = @fopen($url,'r')) { by : if (!$dp = @fopen($url,'r,'false,$context _stream)) {

Near line 2705 : change : $data = file_get_contents($xmlfile); by : $data = file_get_contents($xmlfile,false,$context_stream);

It should not be too difficult to add this code in the source of freepbx and adding the proxy parameters in the general tab of the configuration.

07/01/08 23:22:00 changed by p_lindheimer

  • status changed from new to closed.
  • confirmation changed from Need Feedback to Need testing.
  • resolution set to fixed.
  • version changed from 2.4-branch to SVN-HEAD.

r5871 - please test and provide feedback if it works, we can re-open the bug if there are still issues. Note this is in svn trunk, which will become 2.5. We will be pushing out a tarball shortly.

Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads