check if extension directory is writable

This commit is contained in:
Uwe Steinmann 2018-03-14 11:47:06 +01:00
parent cbd04698ea
commit b1a9ade799
3 changed files with 31 additions and 8 deletions

View File

@ -91,7 +91,7 @@ class SeedDMS_Extension_Mgr {
* configuration file if it does not exist and the extension dir
* is given
*/
public function __construct($extdir = '', $cachedir = '') {
public function __construct($extdir = '', $cachedir = '') { /* {{{ */
$this->cachedir = $cachedir;
$this->extdir = $extdir;
$this->extconf = array();
@ -104,7 +104,7 @@ class SeedDMS_Extension_Mgr {
$this->extconf = $EXT_CONF;
}
}
}
} /* }}} */
protected function getExtensionsConfFile() { /* {{{ */
return $this->cachedir."/extensions.php";
@ -119,6 +119,15 @@ class SeedDMS_Extension_Mgr {
return $this->extconf;
} /* }}} */
/**
* Check if extension directory is writable
*
* @return boolean
*/
public function isWritableExitDir() { /* {{{ */
return is_writable($this->extdir);
} /* }}} */
/**
* Create the cached file containing extension information
*
@ -332,10 +341,13 @@ class SeedDMS_Extension_Mgr {
/**
* Import list of extension from repository
*
* @param boolean $force force download even if file already exists
*/
public function importExtensionList($url) { /* {{{ */
public function importExtensionList($url, $force=false) { /* {{{ */
if(!file_exists($this->cachedir."/repository.json") || $force) {
$file = file_get_contents($url."/repository.json");
file_put_contents($this->cachedir."/repository.json", $file);
}
return file($this->cachedir."/repository.json");
} /* }}} */

View File

@ -69,6 +69,9 @@ elseif ($action == "refresh") { /* {{{ */
header("Location:../out/out.ExtensionMgr.php");
} /* }}} */
elseif ($action == "upload") { /* {{{ */
if(!$extmgr->isWritableExitDir()) {
UI::exitError(getMLText("admin_tools"),getMLText("extension_mgr_no_upload"));
}
if($_FILES['userfile']['error']) {
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}

View File

@ -81,6 +81,9 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
?>
<div class="row-fluid">
<div class="span4">
<?php
if($extmgr->isWritableExitDir()) {
?>
<form class="form-horizontal" method="post" enctype="multipart/form-data" action="../op/op.ExtensionMgr.php">
<?= createHiddenFieldWithKey('extensionmgr') ?>
<input type="hidden" name="action" value="upload" />
@ -97,11 +100,16 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
</div>
</div>
</form>
<?php
} else {
echo "<div class=\"alert alert-warning\">".getMLText('extension_mgr_no_upload')."</div>";
}
?>
</div>
<div class="span8">
<ul class="nav nav-tabs" id="extensionstab">
<li class="<?php if(!$currenttab || $currenttab == 'installed') echo 'active'; ?>"><a data-target="#installed" data-toggle="tab"><?= getMLText('extensions_installed'); ?></a></li>
<li class="<?php if($currenttab == 'repository') echo 'active'; ?>"><a data-target="#repository" data-toggle="tab"><?= getMLText('extensions_repository'); ?></a></li>
<li class="<?php if(!$currenttab || $currenttab == 'installed') echo 'active'; ?>"><a data-target="#installed" data-toggle="tab"><?= getMLText('extension_mgr_installed'); ?></a></li>
<li class="<?php if($currenttab == 'repository') echo 'active'; ?>"><a data-target="#repository" data-toggle="tab"><?= getMLText('extension_mgr_repository'); ?></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane <?php if(!$currenttab || $currenttab == 'installed') echo 'active'; ?>" id="installed">
@ -193,7 +201,7 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
echo "<td nowrap>".$re['author']['name']."<br /><small>".$re['author']['company']."</small></td>";
echo "<td nowrap>";
echo "<div class=\"list-action\">";
if($needsupdate && !$checkmsgs)
if($needsupdate && !$checkmsgs && $extmgr->isWritableExitDir())
echo "<form style=\"display: inline-block; margin: 0px;\" method=\"post\" action=\"../op/op.ExtensionMgr.php\" id=\"".$extname."-import\">".createHiddenFieldWithKey('extensionmgr')."<input type=\"hidden\" name=\"action\" value=\"import\" /><input type=\"hidden\" name=\"url\" value=\"".$re['filename']."\" /><a class=\"import\" data-extname=\"".$extname."\" title=\"".getMLText('import_extension')."\"><i class=\"icon-download\"></i></a></form>";
echo "</div>";
echo "</td>";