index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. ?>
  9. <title>Edit file <?= htmlspecialchars($_REQUEST['path']) ?></title>
  10. <meta charset="utf-8" />
  11. <script src="/js/cheef-editor/jquery/jquery-1.8.3.min.js"></script>
  12. <script src="/js/cheef-editor/ace/ace.js"></script>
  13. <script src="/js/cheef-editor/ace/theme-twilight.js"></script>
  14. <script src="/js/cheef-editor/ace/mode-ruby.js"></script>
  15. <script src="/js/cheef-editor/jquery-ace.min.js"></script>
  16. <div id="message" style="display:none; position: absoulte;background-color: green; color: white; padding: 10px;"></div>
  17. <div id="error-message" style="display:none; position: absoulte;background-color: red; color: white; padding: 10px;"></div>
  18. <?php
  19. if (!empty($_REQUEST['path'])) {
  20. $content = '';
  21. $path = $_REQUEST['path'];
  22. if (!empty($_POST['save'])) {
  23. $fn = tempnam ('/tmp', 'vst-save-file-');
  24. if ($fn) {
  25. $contents = $_POST['contents'];
  26. $contents = preg_replace("/\r/", "", $contents);
  27. $f = fopen ($fn, 'w+');
  28. fwrite($f, $contents);
  29. fclose($f);
  30. chmod($fn, 0644);
  31. if ($f) {
  32. exec (HESTIA_CMD . "v-copy-fs-file {$user} {$fn} ".escapeshellarg($path), $output, $return_var);
  33. $error = check_return_code($return_var, $output);
  34. if ($return_var != 0) {
  35. print('<p style="color: white">Error while saving file</p>');
  36. exit;
  37. }
  38. }
  39. unlink($fn);
  40. }
  41. }
  42. exec (HESTIA_CMD . "v-open-fs-file {$user} ".escapeshellarg($path), $content, $return_var);
  43. if ($return_var != 0) {
  44. print 'Error while opening file'; // todo: handle this more styled
  45. exit;
  46. }
  47. $content = implode("\n", $content)."\n";
  48. } else {
  49. $content = '';
  50. }
  51. ?>
  52. <form id="edit-file-form" method="post">
  53. <!-- input id="do-backup" type="button" onClick="javascript:void(0);" name="save" value="backup (ctrl+F2)" class="backup" / -->
  54. <input type="submit" name="save" value="Save" class="save" />
  55. <textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?=htmlentities($content)?></textarea>
  56. </form>
  57. <script type="text/javascript" src="/js/hotkeys.js"></script>
  58. <script type="text/javascript">
  59. $('.editor').ace({ theme: 'twilight', lang: 'ruby' });
  60. var dcrt = $('#editor').data('ace');
  61. dcrt.editor.ace.getSession().setNewLineMode('unix');
  62. var aceInstance = dcrt.editor.ace;
  63. aceInstance.gotoLine(0);
  64. aceInstance.focus();
  65. var makeBackup = function() {
  66. var params = {
  67. action: 'backup',
  68. path: '<?= $path ?>'
  69. };
  70. }
  71. $('#do-backup').on('click', function(evt) {
  72. evt.preventDefault();
  73. makeBackup();
  74. });
  75. //
  76. // Shortcuts
  77. //
  78. shortcut.add("Ctrl+s",function() {
  79. var inp = $('<input>').attr({'type': 'hidden', 'name': 'save'}).val('Save');
  80. $('#edit-file-form').append(inp);
  81. $('#edit-file-form').submit();
  82. },{
  83. 'type': 'keydown',
  84. 'propagate': false,
  85. 'disable_in_input': false,
  86. 'target': document
  87. });
  88. shortcut.add("Ctrl+F2",function() {
  89. makeBackup();
  90. },{
  91. 'type': 'keydown',
  92. 'propagate': false,
  93. 'disable_in_input': false,
  94. 'target': document
  95. });
  96. </script>