diff --git a/CHANGELOG b/CHANGELOG index f481aeba4..e6f774d40 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -133,6 +133,7 @@ - Do not use unzip in ExtensionMgr anymore - fix version compare on info page - allow one page mode on search page +- fix import of older extension versions from repository -------------------------------------------------------------------------------- Changes in version 5.1.14 diff --git a/inc/inc.ClassExtensionMgr.php b/inc/inc.ClassExtensionMgr.php index 70c7f4548..2ac5e42e9 100644 --- a/inc/inc.ClassExtensionMgr.php +++ b/inc/inc.ClassExtensionMgr.php @@ -103,10 +103,13 @@ class SeedDMS_Extension_Mgr { * configuration file if it does not exist and the extension dir * is given */ - public function __construct($extdir = '', $cachedir = '', $reposurl = '') { /* {{{ */ + public function __construct($extdir = '', $cachedir = '', $reposurl = '', $proxyurl='', $proxyuser='', $proxypass='') { /* {{{ */ $this->cachedir = $cachedir; $this->extdir = $extdir; $this->reposurl = $reposurl; + $this->proxyurl = $proxyurl; + $this->proxyuser = $proxyuser; + $this->proxypass = $proxypass; $this->extconf = array(); if($extdir) { if(!file_exists($this->getExtensionsConfFile())) { @@ -123,6 +126,29 @@ class SeedDMS_Extension_Mgr { return $this->reposurl; } /* }}} */ + 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() { /* {{{ */ return $this->cachedir."/extensions.php"; } /* }}} */ @@ -544,7 +570,7 @@ class SeedDMS_Extension_Mgr { public function updateExtensionList($version='', $force=false) { /* {{{ */ if($this->reposurl) { 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)) { $parts=explode(' ',$http_response_header[0]); if(count($parts)>1) //HTTP/1.0 @@ -564,6 +590,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 * diff --git a/inc/inc.ClassSettings.php b/inc/inc.ClassSettings.php index af135c4ee..5ccc2310e 100644 --- a/inc/inc.ClassSettings.php +++ b/inc/inc.ClassSettings.php @@ -577,6 +577,9 @@ class Settings { /* {{{ */ $this->_checkOutDir = strval($tab["checkOutDir"]); $this->_createCheckOutDir = Settings::boolVal($tab["createCheckOutDir"]); $this->_repositoryUrl = strval($tab["repositoryUrl"]); + $this->_proxyUrl = strval($tab["proxyUrl"]); + $this->_proxyUser = strval($tab["proxyUser"]); + $this->_proxyPassword = strval($tab["proxyPassword"]); $this->_logFileEnable = Settings::boolVal($tab["logFileEnable"]); $this->_logFileRotation = strval($tab["logFileRotation"]); $this->_enableLargeFileUpload = Settings::boolVal($tab["enableLargeFileUpload"]); @@ -941,6 +944,9 @@ class Settings { /* {{{ */ $this->setXMLAttributValue($node, "checkOutDir", $this->_checkOutDir); $this->setXMLAttributValue($node, "createCheckOutDir", $this->_createCheckOutDir); $this->setXMLAttributValue($node, "repositoryUrl", $this->_repositoryUrl); + $this->setXMLAttributValue($node, "proxyUrl", $this->_proxyUrl); + $this->setXMLAttributValue($node, "proxyUser", $this->_proxyUser); + $this->setXMLAttributValue($node, "proxyPassword", $this->_proxyPassword); $this->setXMLAttributValue($node, "logFileEnable", $this->_logFileEnable); $this->setXMLAttributValue($node, "logFileRotation", $this->_logFileRotation); $this->setXMLAttributValue($node, "enableLargeFileUpload", $this->_enableLargeFileUpload); diff --git a/inc/inc.Extension.php b/inc/inc.Extension.php index c63921076..74088c54c 100644 --- a/inc/inc.Extension.php +++ b/inc/inc.Extension.php @@ -17,7 +17,7 @@ require_once "inc.ClassExtBase.php"; require_once "inc.Version.php"; require_once "inc.Utils.php"; -$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir, $settings->_repositoryUrl); +$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir, $settings->_repositoryUrl, $settings->_proxyUrl, $settings->_proxyUser, $settings->_proxyPassword); $version = new SeedDMS_Version; diff --git a/op/op.ExtensionMgr.php b/op/op.ExtensionMgr.php index e7a8c43a6..c50d6b1e9 100644 --- a/op/op.ExtensionMgr.php +++ b/op/op.ExtensionMgr.php @@ -95,10 +95,13 @@ elseif ($action == "import") { /* {{{ */ if(!$_POST['url']) { UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); } + $file = $extMgr->getExtensionFromRepository($_POST['url']); + /* $reposurl = $settings->_repositoryUrl; $content = file_get_contents($reposurl."/".$_POST['url']); $file = tempnam(sys_get_temp_dir(), ''); file_put_contents($file, $content); + */ // $extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir); $controller->setParam('extmgr', $extMgr); diff --git a/views/bootstrap/class.ExtensionMgr.php b/views/bootstrap/class.ExtensionMgr.php index ac5c537c2..f81709835 100644 --- a/views/bootstrap/class.ExtensionMgr.php +++ b/views/bootstrap/class.ExtensionMgr.php @@ -77,7 +77,7 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style { }); }); - $('a.import').click(function(ev){ + $('body').on('click', 'a.import', function(ev){ var element = $(this); $('#'+element.data('extname')+'-import').submit(); });