diff --git a/web/download/file/index.php b/web/download/file/index.php index 6065d0fc..97afa8f7 100644 --- a/web/download/file/index.php +++ b/web/download/file/index.php @@ -1,11 +1,18 @@ 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('
Error while saving file
');//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('Error while saving file
'); + 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 = ''; } - ?>