add new method getExtensionFromRepository(), support for proxy

This commit is contained in:
Uwe Steinmann 2020-03-02 09:16:45 +01:00
parent 6454f466cf
commit 02dd7989fb

View File

@ -103,10 +103,13 @@ class SeedDMS_Extension_Mgr {
* configuration file if it does not exist and the extension dir * configuration file if it does not exist and the extension dir
* is given * is given
*/ */
public function __construct($extdir = '', $cachedir = '', $reposurl = '') { /* {{{ */ public function __construct($extdir = '', $cachedir = '', $reposurl = '', $proxyurl='', $proxyuser='', $proxypass='') { /* {{{ */
$this->cachedir = $cachedir; $this->cachedir = $cachedir;
$this->extdir = $extdir; $this->extdir = $extdir;
$this->reposurl = $reposurl; $this->reposurl = $reposurl;
$this->proxyurl = $proxyurl;
$this->proxyuser = $proxyuser;
$this->proxypass = $proxypass;
$this->extconf = array(); $this->extconf = array();
if($extdir) { if($extdir) {
if(!file_exists($this->getExtensionsConfFile())) { if(!file_exists($this->getExtensionsConfFile())) {
@ -119,6 +122,29 @@ class SeedDMS_Extension_Mgr {
} }
} /* }}} */ } /* }}} */
private function getStreamContext() { /* {{{ */
if(!$this->proxyurl)
return null;
$url = parse_url($this->proxyurl);
$opts = [
$url['scheme'] => [
'proxy' => 'tcp://'.$url['host'].($url['port'] ? ':'.$url['port'] : ''),
'request_fulluri' => true,
]
];
if($this->proxyuser && $this->proxypass) {
$auth = base64_encode($this->proxyurl.':'.$this->proxypass);
$opts[$url['scheme']] = [
'header' => [
'Proxy-Authorization: Basic '.$auth
]
];
}
$context = stream_context_create($opts);
return $context;
} /* }}} */
protected function getExtensionsConfFile() { /* {{{ */ protected function getExtensionsConfFile() { /* {{{ */
return $this->cachedir."/extensions.php"; return $this->cachedir."/extensions.php";
} /* }}} */ } /* }}} */
@ -539,7 +565,7 @@ class SeedDMS_Extension_Mgr {
public function updateExtensionList($version='', $force=false) { /* {{{ */ public function updateExtensionList($version='', $force=false) { /* {{{ */
if($this->reposurl) { if($this->reposurl) {
if(!file_exists($this->cachedir."/".self::repos_list_file) || $force) { if(!file_exists($this->cachedir."/".self::repos_list_file) || $force) {
if($file = @file_get_contents($this->reposurl.($version ? '?seeddms_version='.$version : ''))) { if($file = @file_get_contents($this->reposurl.($version ? '?seeddms_version='.$version : ''), false, $this->getStreamContext())) {
if(is_array($http_response_header)) { if(is_array($http_response_header)) {
$parts=explode(' ',$http_response_header[0]); $parts=explode(' ',$http_response_header[0]);
if(count($parts)>1) //HTTP/1.0 <code> <text> if(count($parts)>1) //HTTP/1.0 <code> <text>
@ -559,6 +585,18 @@ class SeedDMS_Extension_Mgr {
} }
} /* }}} */ } /* }}} */
/**
* Download an extension from the repository
*
* @param string $file filename of extension
*/
public function getExtensionFromRepository($file) { /* {{{ */
$content = file_get_contents($this->reposurl."/".$file, false, $this->getStreamContext());
$tmpfile = tempnam(sys_get_temp_dir(), '');
file_put_contents($tmpfile, $content);
return $tmpfile;
} /* }}} */
/** /**
* Return last error message * Return last error message
* *