From 5cfc52f1fca835abdef8b2f15a4c293a5f6c1050 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 12 Mar 2018 18:33:30 +0100 Subject: [PATCH] add download/upload of extensions to extension mgr --- inc/inc.ClassExtensionMgr.php | 63 +++++++++++++++++++++ op/op.ExtensionMgr.php | 57 +++++++++++++++++-- views/bootstrap/class.ExtensionMgr.php | 77 ++++++++++++++++++++++++-- 3 files changed, 185 insertions(+), 12 deletions(-) diff --git a/inc/inc.ClassExtensionMgr.php b/inc/inc.ClassExtensionMgr.php index 163893206..2ab452e6e 100644 --- a/inc/inc.ClassExtensionMgr.php +++ b/inc/inc.ClassExtensionMgr.php @@ -90,4 +90,67 @@ class SeedDMS_Extension_Mgr { } return $extensions; } /* }}} */ + + public function createArchive($extname, $version) { /* {{{ */ + if(!is_dir($this->extdir ."/". $extname)) + return false; + + $tmpfile = $this->cachedir."/".$extname."-".$version.".zip"; + + $cmd = "cd ".$this->extdir."/".$extname."; zip -r ".$tmpfile." ."; + exec($cmd); + + return $tmpfile; + } /* }}} */ + + static protected function rrmdir($dir) { /* {{{ */ + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir") self::rrmdir($dir."/".$object); else unlink($dir."/".$object); + } + } + reset($objects); + rmdir($dir); + } + } /* }}} */ + + public function updateExtension($file) { /* {{{ */ + $newdir = $this->cachedir ."/ext.new"; + if(!mkdir($newdir, 0755)) { + return false; + } + $cmd = "cd ".$newdir."; unzip ".$file; + exec($cmd); + + if(!file_exists($newdir."/conf.php")) { + self::rrmdir($newdir); + return false; + } + + include($newdir."/conf.php"); + if(!isset($EXT_CONF)) { + self::rrmdir($newdir); + return false; + } + $extname = key($EXT_CONF); + if(!$extname || !preg_match('/[a-zA-Z_]*/', $extname)) { + self::rrmdir($newdir); + return false; + } + + if(!is_dir($this->extdir)) { + if(!mkdir($this->extdir, 0755)) { + self::rrmdir($newdir); + return false; + } + } elseif(is_dir($this->extdir ."/". $extname)) { + $this->rrmdir($this->extdir ."/". $extname); + } + rename($newdir, $this->extdir ."/". $extname); + + return true; + } /* }}} */ + } diff --git a/op/op.ExtensionMgr.php b/op/op.ExtensionMgr.php index 24266d17d..f65388f2a 100644 --- a/op/op.ExtensionMgr.php +++ b/op/op.ExtensionMgr.php @@ -21,10 +21,13 @@ include("../inc/inc.Language.php"); include("../inc/inc.Init.php"); include("../inc/inc.LogInit.php"); include("../inc/inc.DBInit.php"); +include("../inc/inc.Extension.php"); include("../inc/inc.ClassUI.php"); +include("../inc/inc.ClassController.php"); include("../inc/inc.Authentication.php"); -require "../inc/inc.ClassExtensionMgr.php"; +$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME'])); +$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user)); if (!$user->isAdmin()) { UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); } @@ -34,10 +37,52 @@ if(!checkFormKey('extensionmgr')) { UI::exitError(getMLText("admin_tools"),getMLText("invalid_request_token")); } -$extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir); -$extconffile = $extMgr->getExtensionsConfFile(); -$extMgr->createExtensionConf(); +if (isset($_POST["action"])) $action=$_POST["action"]; +else $action=NULL; + +// add new attribute definition --------------------------------------------- +if ($action == "download") { + if (!isset($_POST["extname"])) { + UI::exitError(getMLText("admin_tools"),getMLText("unknown_id")); + } + $extname = trim($_POST["extname"]); + if (!file_exists($settings->_rootDir.'/ext/'.$extname) ) { + UI::exitError(getMLText("admin_tools"),getMLText("missing_extension")); + } + $extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir); + $controller->setParam('extmgr', $extMgr); + $controller->setParam('extname', $extname); + if (!$controller($_POST)) { + echo json_encode(array('success'=>false, 'error'=>'Could not download extension')); + } + add_log_line(); +} /* }}} */ +elseif ($action == "refresh") { + $extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir); + $extMgr->createExtensionConf(); + $controller->setParam('extmgr', $extMgr); + if (!$controller($_POST)) { + UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); + } + add_log_line(); + header("Location:../out/out.ExtensionMgr.php"); +} +elseif ($action == "upload") { + if($_FILES['userfile']['error']) { + UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); + } + if($_FILES['userfile']['type'] != 'application/zip') { + UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); + } + $extMgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir); + $controller->setParam('extmgr', $extMgr); + $controller->setParam('file', $_FILES['userfile']['tmp_name']); + if (!$controller($_POST)) { + UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); + } + add_log_line(); + header("Location:../out/out.ExtensionMgr.php"); +} + -add_log_line(); -header("Location:../out/out.ExtensionMgr.php"); ?> diff --git a/views/bootstrap/class.ExtensionMgr.php b/views/bootstrap/class.ExtensionMgr.php index 489660c73..6881fffd3 100644 --- a/views/bootstrap/class.ExtensionMgr.php +++ b/views/bootstrap/class.ExtensionMgr.php @@ -27,6 +27,40 @@ require_once("class.Bootstrap.php"); */ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style { + function js() { /* {{{ */ + $partitionsize = $this->params['partitionsize']; + $maxuploadsize = $this->params['maxuploadsize']; + + header('Content-Type: application/javascript'); +?> + $(document).ready( function() { + $('a.download').click(function(ev){ + var element = $(this); + $('#'+element.data('extname')+'-download').submit(); +/* + var element = $(this); + ev.preventDefault(); + $.ajax({url: '../op/op.ExtensionMgr.php', + type: 'POST', + dataType: "json", + data: {action: 'download', 'formtoken': '', 'extname': element.data('extname')}, + success: function(data) { + noty({ + text: data.msg, + type: (data.error) ? 'error' : 'success', + dismissQueue: true, + layout: 'topRight', + theme: 'defaultTheme', + timeout: 1500, + }); + } + }); +*/ + }); + }); +params['dms']; $user = $this->params['user']; @@ -37,8 +71,31 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style { $this->globalNavigation(); $this->contentStart(); $this->pageNavigation(getMLText("admin_tools"), "admin_tools"); - $this->contentContainerStart(); - echo "\n"; + $this->contentHeading(getMLText("extension_manager")); +?> +
+
+
+ + +
+ +
+ printFileChooser('userfile', false); ?> +
+
+
+ +
+ +
+
+ +
+
+contentContainerStart(); + echo "
\n"; print "\n\n"; print "\n"; print "\n"; @@ -95,21 +152,29 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style { if($errmsgs) echo "
getImgPath("attention.gif")."\"> ".implode('
', $errmsgs)."
"; echo ""; - echo ""; - echo ""; + echo ""; echo "\n"; } echo "
".getMLText('name')."".$extconf['version']."
".$extconf['releasedate'].""; + echo "
".$extconf['version']."
".$extconf['releasedate'].""; + echo "
"; if($extconf['config']) - echo "
"; + echo ""; + echo "
".createHiddenFieldWithKey('extensionmgr')."
"; + echo "
"; echo "
".$extconf['author']['name']."
".$extconf['author']['company']."
".$extconf['author']['name']."
".$extconf['author']['company']."
\n"; ?>
+

contentContainerEnd(); +// $this->contentContainerEnd(); +?> + + +contentEnd(); $this->htmlEndPage(); } /* }}} */