Merge pull request #3138 from sebastiendu/16686_proxy_settings

Set relevant environment variables http*_proxy - refs BT#16686
pull/3151/head
Nicolas Ducoulombier 6 years ago committed by GitHub
commit d0dddad968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      main/auth/cas/cas_var.inc.php
  2. 19
      main/inc/global.inc.php
  3. 41
      main/inc/lib/api.lib.php

@ -48,19 +48,6 @@ if (api_is_cas_activated()) {
phpCAS::setNoCasServerValidation();
}
$proxySettings = api_get_configuration_value('proxy_settings');
if (false !== $proxySettings) {
if (is_array($proxySettings) && array_key_exists('https', $proxySettings)) {
$https = $proxySettings['https'];
if (is_array($https) && array_key_exists('proxy', $https)) {
$proxy = $https['proxy'];
if (is_string($proxy) && !empty($proxy)) {
phpCAS::setExtraCurlOption(CURLOPT_PROXY, $proxy);
}
}
}
}
if (is_array($cas) && array_key_exists('fixedServiceURL', $cas)) {
$fixedServiceURL = $cas['fixedServiceURL'];
if (is_string($fixedServiceURL)) {

@ -80,6 +80,25 @@ define('USERNAME_MAX_LENGTH', $defaultUserNameLength);
// Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
api_request_uri();
// Set web proxy environment variables
foreach ([
'proxy_settings/stream_context_create/https/proxy',
'proxy_settings/stream_context_create/http/proxy',
'proxy_settings/curl_setopt_array/CURLOPT_PROXY',
] as $path) {
$value = api_get_configuration_sub_value($path);
if (!empty($value) && is_string($value)) {
// libcurl reads environment variable https_proxy: https://curl.haxx.se/libcurl/c/libcurl-env.html
// \GuzzleHttp\Client::configureDefaults reads environment variable HTTPS_PROXY
foreach (['https_proxy', 'http_proxy', 'HTTPS_PROXY', 'HTTP_PROXY'] as $envVar) {
if (false === getenv($envVar)) {
putenv("$envVar=$value");
}
}
break;
}
}
define('_MPDF_TEMP_PATH', __DIR__.'/../../app/cache/mpdf/');
define('_MPDF_TTFONTDATAPATH', __DIR__.'/../../app/cache/mpdf/');

@ -8654,6 +8654,47 @@ function api_get_configuration_value($variable)
return false;
}
/**
* Retreives and returns a value in a hierarchical configuration array
* api_get_configuration_sub_value('a/b/c') returns api_get_configuration_value('a')['b']['c'].
*
* @param string $path the successive array keys, seperated by the separator
* @param mixed $default value to be returned if not found, null by default
* @param string $separator '/' by default
* @param array $array the active configuration array by default
*
* @return mixed the found value or $default
*/
function api_get_configuration_sub_value($path, $default = null, $separator = '/', $array = null)
{
$pos = strpos($path, $separator);
if (false === $pos) {
if (is_null($array)) {
return api_get_configuration_value($path);
}
if (is_array($array) && array_key_exists($path, $array)) {
return $array[$path];
}
return $default;
}
$key = substr($path, 0, $pos);
if (is_null($array)) {
$newArray = api_get_configuration_value($key);
} elseif (is_array($array) && array_key_exists($key, $array)) {
$newArray = $array[$key];
} else {
return $default;
}
if (is_array($newArray)) {
$newPath = substr($path, $pos + 1);
return api_get_configuration_sub_value($newPath, $default, $separator, $newArray);
}
return $default;
}
/**
* Returns supported image extensions in the portal.
*

Loading…
Cancel
Save