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

View file

@ -452,17 +452,27 @@ if (isset($_POST['ajax']) && !FM_READONLY) {
} }
// backup files // backup files
if (isset($_POST['type']) && $_POST['type'] == "backup") { if (isset($_POST['type']) && $_POST['type'] == "backup" && !empty($_POST['file'])) {
$file = $_POST['file']; $fileName = $_POST['file'];
$dir = fm_clean_path($_POST['path']); $fullPath = FM_ROOT_PATH . '/';
$path = FM_ROOT_PATH.'/'.$dir; if (!empty($_POST['path'])) {
if($dir) { $relativeDirPath = fm_clean_path($_POST['path']);
$date = date("dMy-His"); $fullPath .= "{$relativeDirPath}/";
$newFile = $file . '-' . $date . '.bak'; }
copy($path . '/' . $file, $path . '/' . $newFile) or die("Unable to backup"); $date = date("dMy-His");
echo "Backup $newFile Created"; $newFileName = "{$fileName}-{$date}.bak";
} else { $fullyQualifiedFileName = $fullPath . $fileName;
echo "Error! Not allowed"; 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();
} }
} }