Check if target directories are writable when adding, updating, or removing plugin repos
This commit is contained in:
parent
40e3d37a72
commit
c7698e4dc3
@ -1726,8 +1726,13 @@ class Admin extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
$repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName;
|
$repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName;
|
||||||
if (!is_dir($repoDir)) {
|
if (!is_dir($repoDir)) {
|
||||||
|
logger('Repo directory does not exist: ' . $repoDir);
|
||||||
json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false));
|
json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false));
|
||||||
}
|
}
|
||||||
|
if (!is_writable($repoDir)) {
|
||||||
|
logger('Repo directory not writable to web server: ' . $repoDir);
|
||||||
|
json_return_and_die(array('message' => 'Repo directory not writable to web server.', 'success' => false));
|
||||||
|
}
|
||||||
$git = new GitRepo('sys', null, false, $repoName, $repoDir);
|
$git = new GitRepo('sys', null, false, $repoName, $repoDir);
|
||||||
try {
|
try {
|
||||||
if ($git->pull()) {
|
if ($git->pull()) {
|
||||||
@ -1746,8 +1751,13 @@ class Admin extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
$repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName;
|
$repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName;
|
||||||
if (!is_dir($repoDir)) {
|
if (!is_dir($repoDir)) {
|
||||||
|
logger('Repo directory does not exist: ' . $repoDir);
|
||||||
json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false));
|
json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false));
|
||||||
}
|
}
|
||||||
|
if (!is_writable($repoDir)) {
|
||||||
|
logger('Repo directory not writable to web server: ' . $repoDir);
|
||||||
|
json_return_and_die(array('message' => 'Repo directory not writable to web server.', 'success' => false));
|
||||||
|
}
|
||||||
// TODO: remove directory and unlink /addon/files
|
// TODO: remove directory and unlink /addon/files
|
||||||
if (rrmdir($repoDir)) {
|
if (rrmdir($repoDir)) {
|
||||||
json_return_and_die(array('message' => 'Repo deleted.', 'success' => true));
|
json_return_and_die(array('message' => 'Repo deleted.', 'success' => true));
|
||||||
@ -1772,6 +1782,10 @@ class Admin extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!is_writable($extendDir)) {
|
||||||
|
logger('Directory not writable to web server: ' . $extendDir);
|
||||||
|
json_return_and_die(array('message' => 'Directory not writable to web server.', 'success' => false));
|
||||||
|
}
|
||||||
$repoName = null;
|
$repoName = null;
|
||||||
if (array_key_exists('repoName', $_REQUEST) && $_REQUEST['repoName'] !== '') {
|
if (array_key_exists('repoName', $_REQUEST) && $_REQUEST['repoName'] !== '') {
|
||||||
$repoName = $_REQUEST['repoName'];
|
$repoName = $_REQUEST['repoName'];
|
||||||
@ -1783,13 +1797,21 @@ class Admin extends \Zotlabs\Web\Controller {
|
|||||||
json_return_and_die(array('message' => 'Invalid git repo', 'success' => false));
|
json_return_and_die(array('message' => 'Invalid git repo', 'success' => false));
|
||||||
}
|
}
|
||||||
$repoDir = $addonDir . '/' . $repoName;
|
$repoDir = $addonDir . '/' . $repoName;
|
||||||
$tempAddonDir = __DIR__ . '/../../store/git/sys/temp/' . $repoName;
|
$tempRepoBaseDir = __DIR__ . '/../../store/git/sys/temp/';
|
||||||
|
$tempAddonDir = $tempRepoBaseDir . $repoName;
|
||||||
|
|
||||||
|
if (!is_writable($addonDir) || !is_writable($tempAddonDir)) {
|
||||||
|
logger('Temp repo directory or /extend/addon not writable to web server: ' . $tempAddonDir);
|
||||||
|
json_return_and_die(array('message' => 'Temp repo directory not writable to web server.', 'success' => false));
|
||||||
|
}
|
||||||
rename($tempAddonDir, $repoDir);
|
rename($tempAddonDir, $repoDir);
|
||||||
|
|
||||||
|
if (!is_writable(realpath(__DIR__ . '/../../addon/'))) {
|
||||||
|
logger('/addon directory not writable to web server: ' . $tempAddonDir);
|
||||||
|
json_return_and_die(array('message' => '/addon directory not writable to web server.', 'success' => false));
|
||||||
|
}
|
||||||
$files = array_diff(scandir($repoDir), array('.', '..'));
|
$files = array_diff(scandir($repoDir), array('.', '..'));
|
||||||
logger('files: ' . json_encode($files));
|
foreach ($files as $file) {
|
||||||
foreach ($files as $file)
|
|
||||||
{
|
|
||||||
if (is_dir($repoDir . '/' . $file) && $file !== '.git') {
|
if (is_dir($repoDir . '/' . $file) && $file !== '.git') {
|
||||||
$source = '../extend/addon/' . $repoName . '/' . $file;
|
$source = '../extend/addon/' . $repoName . '/' . $file;
|
||||||
$target = realpath(__DIR__ . '/../../addon/') . '/' . $file;
|
$target = realpath(__DIR__ . '/../../addon/') . '/' . $file;
|
||||||
@ -1834,6 +1856,10 @@ class Admin extends \Zotlabs\Web\Controller {
|
|||||||
json_return_and_die(array('message' => 'Invalid git repo: ' . $repoName, 'success' => false));
|
json_return_and_die(array('message' => 'Invalid git repo: ' . $repoName, 'success' => false));
|
||||||
}
|
}
|
||||||
$repoDir = $tempAddonDir . '/' . $repoName;
|
$repoDir = $tempAddonDir . '/' . $repoName;
|
||||||
|
if (!is_writable($tempAddonDir)) {
|
||||||
|
logger('Temporary directory for new addon repo is not writable to web server: ' . $tempAddonDir);
|
||||||
|
json_return_and_die(array('message' => 'Temporary directory for new addon repo is not writable to web server.', 'success' => false));
|
||||||
|
}
|
||||||
// clone the repo if new automatically
|
// clone the repo if new automatically
|
||||||
$git = new GitRepo('sys', $repoURL, true, $repoName, $repoDir);
|
$git = new GitRepo('sys', $repoURL, true, $repoName, $repoDir);
|
||||||
|
|
||||||
@ -1856,7 +1882,6 @@ class Admin extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
json_return_and_die(array('repo' => $repo, 'message' => '', 'success' => true));
|
json_return_and_die(array('repo' => $repo, 'message' => '', 'success' => true));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
json_return_and_die(array('message' => 'No repo URL provided', 'success' => false));
|
json_return_and_die(array('message' => 'No repo URL provided', 'success' => false));
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
<div class="section-content-info-wrapper">
|
<div class="section-content-info-wrapper">
|
||||||
<h3>Installed Addon Repositories</h3>
|
<h3>Installed Plugin Repositories</h3>
|
||||||
{{foreach $addonrepos as $repo}}
|
{{foreach $addonrepos as $repo}}
|
||||||
<!-- <div class="section-content-tools-wrapper"> -->
|
<!-- <div class="section-content-tools-wrapper"> -->
|
||||||
<div style="margin-left: 30%; margin-right: 30%;">
|
<div style="margin-left: 30%; margin-right: 30%;">
|
||||||
|
Reference in New Issue
Block a user