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.
This commit is contained in:
Sarah Hoffmann 2020-12-15 11:04:19 +01:00
parent b5480f6e36
commit ac116980ac
6 changed files with 36 additions and 23 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -14,6 +14,8 @@ $aCMDOptions
);
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
setupHTTPProxy();
include(CONST_Phrase_Config);
if (true) {

View File

@ -49,6 +49,8 @@ $aCMDOptions
// $aCMDOptions passed to getCmdOpt by reference
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
setupHTTPProxy();
$bDidSomething = false;
//*******************************************************

View File

@ -14,6 +14,8 @@ $aCMDOptions
);
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
setupHTTPProxy();
include(CONST_Phrase_Config);
if ($aCMDResult['wiki-import']) {

View File

@ -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;