diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 79901007a..6d31dda82 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -462,6 +462,29 @@ function getFilenameByDocname($content) { /* {{{ */ return mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename); } /* }}} */ +function getStreamContext($proxyurl, $proxyuser, $proxypass) { /* {{{ */ + if(!$proxyurl) + return null; + $url = parse_url($proxyurl); + $opts = [ + $url['scheme'] => [ + 'proxy' => 'tcp://'.$url['host'].($url['port'] ? ':'.$url['port'] : ''), + 'request_fulluri' => true, + ] + ]; + if($proxyuser && $proxypass) { + $auth = base64_encode($proxyurl.':'.$this->proxypass); + $opts[$url['scheme']] = [ + 'header' => [ + 'Proxy-Authorization: Basic '.$auth + ] + ]; + } + + $context = stream_context_create($opts); + return $context; +} /* }}} */ + function getLogger($prefix='', $mask=PEAR_LOG_INFO) { /* {{{ */ global $settings;