FM changes

This commit is contained in:
Serghey Rodin 2015-11-05 03:17:21 +02:00
commit d207b7a752
9 changed files with 117 additions and 136 deletions

View file

@ -1,31 +1,7 @@
<?php
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
$user = $_SESSION['user'];
/*
if (empty($panel)) {
$command = VESTA_CMD."v-list-user '".$user."' 'json'";
exec ($command, $output, $return_var);
if ( $return_var > 0 ) {
header("Location: /error/");
exit;
}
$panel = json_decode(implode('', $output), true);
}
*/
/*
// Check user session
if ((!isset($_SESSION['user'])) && (!defined('NO_AUTH_REQUIRED'))) {
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
header("Location: /login/");
exit;
}
*/
// Check module activation
if (!$_SESSION['FILEMANAGER_KEY']) {
@ -34,6 +10,11 @@ if (!$_SESSION['FILEMANAGER_KEY']) {
exit;
}
// Check login_as feature
if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
$user=$_SESSION['look'];
}
?>
@ -55,66 +36,46 @@ if (!$_SESSION['FILEMANAGER_KEY']) {
if (!empty($_REQUEST['path'])) {
$content = '';
$path = $_REQUEST['path'];
if (is_readable($path)) {
$image = getimagesize($path) ? true : false;
if ($image) {
header('Location: /view/file/?path='.$path);
exit;
}
if (!empty($_POST['save'])) {
$fn = tempnam ('/tmp', 'vst-save-file-');
if ($fn) {
$f = fopen ($fn, 'w+');
fwrite($f, $_POST['contents']);
fclose($f);
chmod($fn, 0644);
if ($f) {
//copy($fn, $path);
exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}", $output, $return_var);
if (!empty($_POST['save'])) {
$fn = tempnam ('/tmp', 'vst-save-file-');
if ($fn) {
$contents = $_POST['contents'];
$contents = preg_replace("/\r/", "", $contents);
$f = fopen ($fn, 'w+');
fwrite($f, $contents);
fclose($f);
chmod($fn, 0644);
$error = check_return_code($return_var, $output);
if ($return_var != 0) {
/*var_dump(VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}");
var_dump($path);
var_dump($output);*/
die('<p style="color: white">Error while saving file</p>');//echo '0';
}
if ($f) {
exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} {$path}", $output, $return_var);
$error = check_return_code($return_var, $output);
if ($return_var != 0) {
print('<p style="color: white">Error while saving file</p>');
exit;
}
unlink($fn);
}
unlink($fn);
}
// $content = file_get_contents($path);
// v-open-fs-file
//print file_get_contents($path);
exec (VESTA_CMD . "v-check-fs-permission {$user} {$path}", $content, $return_var);
if ($return_var != 0) {
print 'Error while opening file'; // todo: handle this more styled
exit;
}
/*exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var);
if ($return_var != 0) {
print 'Error while opening file'; // todo: handle this more styled
exit;
}
$content = implode("\n", $content);*/
$content = file_get_contents($path);
}
}
else {
exec (VESTA_CMD . "v-check-fs-permission {$user} '{$path}'", $content, $return_var);
if ($return_var != 0) {
var_dump($return_var);
var_dump($content);
exit;
print 'Error while opening file'; // todo: handle this more styled
exit;
}
exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var);
if ($return_var != 0) {
print 'Error while opening file'; // todo: handle this more styled
exit;
}
$content = implode("\n", $content)."\n";
} else {
$content = '';
}
?>
<form id="edit-file-form" method="post">
@ -131,9 +92,11 @@ if (!$_SESSION['FILEMANAGER_KEY']) {
$('.editor').ace({ theme: 'twilight', lang: 'ruby' });
var dcrt = $('#editor').data('ace');
var editor = dcrt.editor.ace;
editor.gotoLine(0);
editor.focus();
dcrt.editor.ace.getSession().setNewLineMode('unix');
var aceInstance = dcrt.editor.ace;
aceInstance.gotoLine(0);
aceInstance.focus();
var makeBackup = function() {