mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-14 10:37:39 -07:00
Integrated new api interface.
This commit is contained in:
parent
4a9bfc94ad
commit
4306a4fb4f
116 changed files with 10371 additions and 0 deletions
51
web/api/v1/edit/file/index.php
Normal file
51
web/api/v1/edit/file/index.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?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'];
|
||||
}
|
||||
|
||||
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 (VESTA_CMD . "v-copy-fs-file {$user} {$fn} ".escapeshellarg($path), $output, $return_var);
|
||||
$error = check_return_code($return_var, $output);
|
||||
if ($return_var != 0) {
|
||||
$error = 'Error while saving file';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
unlink($fn);
|
||||
}
|
||||
}
|
||||
|
||||
exec (VESTA_CMD . "v-open-fs-file {$user} ".escapeshellarg($path), $content, $return_var);
|
||||
if ($return_var != 0) {
|
||||
$error = 'Error while opening file'; // todo: handle this more styled
|
||||
exit;
|
||||
}
|
||||
$content = implode("\n", $content)."\n";
|
||||
} else {
|
||||
$content = '';
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'error' => $error,
|
||||
'content' => $content
|
||||
);
|
||||
|
||||
echo json_encode($result);
|
Loading…
Add table
Add a link
Reference in a new issue