forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
119 lines (96 loc) · 3.69 KB
/
index.php
File metadata and controls
119 lines (96 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
$user = $_SESSION['user'];
// Check login_as feature
if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
$user=$_SESSION['look'];
}
?>
<title>Edit file <?= htmlspecialchars($_REQUEST['path']) ?></title>
<meta charset="utf-8" />
<script src="/js/cheef-editor/jquery/jquery-1.8.3.min.js"></script>
<script src="/js/cheef-editor/ace/ace.js"></script>
<script src="/js/cheef-editor/ace/theme-twilight.js"></script>
<script src="/js/cheef-editor/ace/mode-ruby.js"></script>
<script src="/js/cheef-editor/jquery-ace.min.js"></script>
<div id="message" style="display:none; position: absoulte;background-color: green; color: white; padding: 10px;"></div>
<div id="error-message" style="display:none; position: absoulte;background-color: red; color: white; padding: 10px;"></div>
<?php
if (!empty($_REQUEST['path'])) {
$content = '';
$path = $_REQUEST['path'];
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);
if ($f) {
exec (HESTIA_CMD . "v-copy-fs-file {$user} {$fn} ".escapeshellarg($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);
}
}
exec (HESTIA_CMD . "v-open-fs-file {$user} ".escapeshellarg($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">
<!-- input id="do-backup" type="button" onClick="javascript:void(0);" name="save" value="backup (ctrl+F2)" class="backup" / -->
<input type="submit" name="save" value="Save" class="save" />
<textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?=htmlentities($content)?></textarea>
</form>
<script type="text/javascript" src="/js/hotkeys.js"></script>
<script type="text/javascript">
$('.editor').ace({ theme: 'twilight', lang: 'ruby' });
var dcrt = $('#editor').data('ace');
dcrt.editor.ace.getSession().setNewLineMode('unix');
var aceInstance = dcrt.editor.ace;
aceInstance.gotoLine(0);
aceInstance.focus();
var makeBackup = function() {
var params = {
action: 'backup',
path: '<?= $path ?>'
};
}
$('#do-backup').on('click', function(evt) {
evt.preventDefault();
makeBackup();
});
//
// Shortcuts
//
shortcut.add("Ctrl+s",function() {
var inp = $('<input>').attr({'type': 'hidden', 'name': 'save'}).val('Save');
$('#edit-file-form').append(inp);
$('#edit-file-form').submit();
},{
'type': 'keydown',
'propagate': false,
'disable_in_input': false,
'target': document
});
shortcut.add("Ctrl+F2",function() {
makeBackup();
},{
'type': 'keydown',
'propagate': false,
'disable_in_input': false,
'target': document
});
</script>