add download/upload of extensions to extension mgr

This commit is contained in:
Uwe Steinmann 2018-03-12 18:33:30 +01:00
parent 36e711f905
commit 5cfc52f1fc
3 changed files with 185 additions and 12 deletions

View File

@ -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;
} /* }}} */
}

View File

@ -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");
?>

View File

@ -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': '<?= createFormKey('extensionmgr') ?>', 'extname': element.data('extname')},
success: function(data) {
noty({
text: data.msg,
type: (data.error) ? 'error' : 'success',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500,
});
}
});
*/
});
});
<?php
} /* }}} */
function show() { /* {{{ */
$dms = $this->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 "<table class=\"table table-condensed\">\n";
$this->contentHeading(getMLText("extension_manager"));
?>
<div class="row-fluid">
<div class="span4">
<form class="form-horizontal" method="post" enctype="multipart/form-data" action="../op/op.ExtensionMgr.php">
<?= createHiddenFieldWithKey('extensionmgr') ?>
<input type="hidden" name="action" value="upload" />
<div class="control-group">
<label class="control-label" for="upload"><?= getMLText('extension_archive'); ?></label>
<div class="controls">
<?php $this->printFileChooser('userfile', false); ?>
</div>
</div>
<div class="control-group">
<label class="control-label" for="enddate"></label>
<div class="controls">
<button id="upload" type="_submit" class="btn"><i class="icon-upload"></i> <?= getMLText("upload_extension"); ?></button>
</div>
</div>
</form>
</div>
<div class="span8">
<?php
// $this->contentContainerStart();
echo "<table class=\"table _table-condensed\">\n";
print "<thead>\n<tr>\n";
print "<th></th>\n";
print "<th>".getMLText('name')."</th>\n";
@ -95,21 +152,29 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
if($errmsgs)
echo "<div><img src=\"".$this->getImgPath("attention.gif")."\"> ".implode('<br /><img src="'.$this->getImgPath("attention.gif").'"> ', $errmsgs)."</div>";
echo "</td>";
echo "<td>".$extconf['version']."<br /><small>".$extconf['releasedate']."</small>";
echo "<td nowrap>".$extconf['version']."<br /><small>".$extconf['releasedate']."</small>";
echo "<div class=\"list-action\">";
if($extconf['config'])
echo "<div class=\"list-action\"><a href=\"../out/out.Settings.php?currenttab=extensions#".$extname."\"><i class=\"icon-cogs\"></i></a></div>";
echo "<a href=\"../out/out.Settings.php?currenttab=extensions#".$extname."\" title=\"".getMLText('configure_extension')."\"><i class=\"icon-cogs\"></i></a>";
echo "<form style=\"display: inline-block; margin: 0px;\" method=\"post\" action=\"../op/op.ExtensionMgr.php\" id=\"".$extname."-download\">".createHiddenFieldWithKey('extensionmgr')."<input type=\"hidden\" name=\"action\" value=\"download\" /><input type=\"hidden\" name=\"extname\" value=\"".$extname."\" /><a class=\"download\" data-extname=\"".$extname."\" title=\"".getMLText('download_extension')."\"><i class=\"icon-download\"></i></a></form>";
echo "</div>";
echo "</td>";
echo "<td><a href=\"mailto:".$extconf['author']['email']."\">".$extconf['author']['name']."</a><br /><small>".$extconf['author']['company']."</small></td>";
echo "<td nowrap><a href=\"mailto:".$extconf['author']['email']."\">".$extconf['author']['name']."</a><br /><small>".$extconf['author']['company']."</small></td>";
echo "</tr>\n";
}
echo "</table>\n";
?>
<form action="../op/op.ExtensionMgr.php" name="form1" method="post">
<?php echo createHiddenFieldWithKey('extensionmgr'); ?>
<input type="hidden" name="action" value="refresh" />
<p><button type="submit" class="btn"><i class="icon-refresh"></i> <?php printMLText("refresh");?></button></p>
</form>
<?php
$this->contentContainerEnd();
// $this->contentContainerEnd();
?>
</div>
</div>
<?php
$this->contentEnd();
$this->htmlEndPage();
} /* }}} */