index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  3. $user = $_SESSION['user'];
  4. // Check login_as feature
  5. if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
  6. $user=$_SESSION['look'];
  7. }
  8. if (!empty($_REQUEST['path'])) {
  9. $content = '';
  10. $path = $_REQUEST['path'];
  11. if (!empty($_POST['save'])) {
  12. $fn = tempnam ('/tmp', 'vst-save-file-');
  13. if ($fn) {
  14. $contents = $_POST['contents'];
  15. $contents = preg_replace("/\r/", "", $contents);
  16. $f = fopen ($fn, 'w+');
  17. fwrite($f, $contents);
  18. fclose($f);
  19. chmod($fn, 0644);
  20. if ($f) {
  21. exec (VESTA_CMD . "v-copy-fs-file {$user} {$fn} ".escapeshellarg($path), $output, $return_var);
  22. $error = check_return_code($return_var, $output);
  23. if ($return_var != 0) {
  24. $error = 'Error while saving file';
  25. exit;
  26. }
  27. }
  28. unlink($fn);
  29. }
  30. }
  31. exec (VESTA_CMD . "v-open-fs-file {$user} ".escapeshellarg($path), $content, $return_var);
  32. if ($return_var != 0) {
  33. $error = 'Error while opening file'; // todo: handle this more styled
  34. exit;
  35. }
  36. $content = implode("\n", $content)."\n";
  37. } else {
  38. $content = '';
  39. }
  40. $result = array(
  41. 'error' => $error,
  42. 'content' => $content
  43. );
  44. echo json_encode($result);