fix(actions): creating a backup in FM_ROOT_PATH (#418)

This commit is contained in:
Dvash 2020-08-26 01:25:13 +03:00 committed by GitHub
parent 44bedb9be0
commit 211568ff4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 11 deletions

View File

@ -452,17 +452,27 @@ if (isset($_POST['ajax']) && !FM_READONLY) {
}
// backup files
if (isset($_POST['type']) && $_POST['type'] == "backup") {
$file = $_POST['file'];
$dir = fm_clean_path($_POST['path']);
$path = FM_ROOT_PATH.'/'.$dir;
if($dir) {
$date = date("dMy-His");
$newFile = $file . '-' . $date . '.bak';
copy($path . '/' . $file, $path . '/' . $newFile) or die("Unable to backup");
echo "Backup $newFile Created";
} else {
echo "Error! Not allowed";
if (isset($_POST['type']) && $_POST['type'] == "backup" && !empty($_POST['file'])) {
$fileName = $_POST['file'];
$fullPath = FM_ROOT_PATH . '/';
if (!empty($_POST['path'])) {
$relativeDirPath = fm_clean_path($_POST['path']);
$fullPath .= "{$relativeDirPath}/";
}
$date = date("dMy-His");
$newFileName = "{$fileName}-{$date}.bak";
$fullyQualifiedFileName = $fullPath . $fileName;
try {
if (!file_exists($fullyQualifiedFileName)) {
throw new Exception("File {$fileName} not found");
}
if (copy($fullyQualifiedFileName, $fullPath . $newFileName)) {
echo "Backup {$newFileName} created";
} else {
throw new Exception("Could not copy file {$fileName}");
}
} catch (Exception $e) {
echo $e->getMessage();
}
}