From: Sarah Hoffmann Date: Tue, 15 Dec 2020 10:04:19 +0000 (+0100) Subject: make HTTP proxy setup explicit X-Git-Tag: v3.7.0~66^2~16 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/ac116980ac78b74dbc1e0ae7ff2d329d7e581ba5 make HTTP proxy setup explicit The setup relies on the project configuration which we want to explicitly set up in later steps. Therefore proxy setup needs to be done explicitly as well. There is the added bonus that the setup is done only for the utils which try to call outside. --- diff --git a/lib/cmd.php b/lib/cmd.php index 3eac3e8f..b72c1bb4 100644 --- a/lib/cmd.php +++ b/lib/cmd.php @@ -195,3 +195,31 @@ function runSQLScript($sScript, $bfatal = true, $bVerbose = false, $bIgnoreError fail("pgsql returned with error code ($iReturn)"); } } + +function setupHTTPProxy() +{ + if (!CONST_HTTP_Proxy) { + return; + } + + $sProxy = 'tcp://'.CONST_HTTP_Proxy_Host.':'.CONST_HTTP_Proxy_Port; + $aHeaders = array(); + + if (CONST_HTTP_Proxy_Login != null + && CONST_HTTP_Proxy_Login != '' + && CONST_HTTP_Proxy_Password != null + && CONST_HTTP_Proxy_Password != '' + ) { + $sAuth = base64_encode(CONST_HTTP_Proxy_Login.':'.CONST_HTTP_Proxy_Password); + $aHeaders = array('Proxy-Authorization: Basic '.$sAuth); + } + + $aProxyHeader = array( + 'proxy' => $sProxy, + 'request_fulluri' => true, + 'header' => $aHeaders + ); + + $aContext = array('http' => $aProxyHeader, 'https' => $aProxyHeader); + stream_context_set_default($aContext); +} diff --git a/lib/init-cmd.php b/lib/init-cmd.php index 50c709c9..b7645cd5 100644 --- a/lib/init-cmd.php +++ b/lib/init-cmd.php @@ -3,26 +3,3 @@ require_once('init.php'); require_once('cmd.php'); require_once('DebugNone.php'); - -// handle http proxy when using file_get_contents -if (CONST_HTTP_Proxy) { - $proxy = 'tcp://' . CONST_HTTP_Proxy_Host . ':' . CONST_HTTP_Proxy_Port; - $aHeaders = array(); - if (CONST_HTTP_Proxy_Login != null && CONST_HTTP_Proxy_Login != '' && CONST_HTTP_Proxy_Password != null && CONST_HTTP_Proxy_Password != '') { - $auth = base64_encode(CONST_HTTP_Proxy_Login . ':' . CONST_HTTP_Proxy_Password); - $aHeaders = array("Proxy-Authorization: Basic $auth"); - } - $aContext = array( - 'http' => array( - 'proxy' => $proxy, - 'request_fulluri' => true, - 'header' => $aHeaders - ), - 'https' => array( - 'proxy' => $proxy, - 'request_fulluri' => true, - 'header' => $aHeaders - ) - ); - stream_context_set_default($aContext); -} diff --git a/utils/country_languages.php b/utils/country_languages.php index c9aa391b..8bd85b8a 100644 --- a/utils/country_languages.php +++ b/utils/country_languages.php @@ -14,6 +14,8 @@ $aCMDOptions ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); +setupHTTPProxy(); + include(CONST_Phrase_Config); if (true) { diff --git a/utils/setup.php b/utils/setup.php index 82c821eb..95ad7992 100644 --- a/utils/setup.php +++ b/utils/setup.php @@ -49,6 +49,8 @@ $aCMDOptions // $aCMDOptions passed to getCmdOpt by reference getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); +setupHTTPProxy(); + $bDidSomething = false; //******************************************************* diff --git a/utils/specialphrases.php b/utils/specialphrases.php index d6979d58..d2bc7041 100644 --- a/utils/specialphrases.php +++ b/utils/specialphrases.php @@ -14,6 +14,8 @@ $aCMDOptions ); getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true); +setupHTTPProxy(); + include(CONST_Phrase_Config); if ($aCMDResult['wiki-import']) { diff --git a/utils/update.php b/utils/update.php index 7e020b42..ff8b0c00 100644 --- a/utils/update.php +++ b/utils/update.php @@ -46,6 +46,8 @@ $aCMDOptions getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true); +setupHTTPProxy(); + if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1; if (!isset($aResult['index-rank'])) $aResult['index-rank'] = 0;