-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
314 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ See instructions to run Wallos below. | |
- intl | ||
- openssl | ||
- sqlite3 | ||
- zip | ||
|
||
#### Docker | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate('session_expired', $i18n) | ||
])); | ||
} | ||
|
||
function addFolderToZip($dir, $zipArchive, $zipdir = ''){ | ||
if (is_dir($dir)) { | ||
if ($dh = opendir($dir)) { | ||
//Add the directory | ||
if(!empty($zipdir)) $zipArchive->addEmptyDir($zipdir); | ||
while (($file = readdir($dh)) !== false) { | ||
// Skip '.' and '..' | ||
if ($file == "." || $file == "..") { | ||
continue; | ||
} | ||
//If it's a folder, run the function again! | ||
if(is_dir($dir . $file)){ | ||
$newdir = $dir . $file . '/'; | ||
addFolderToZip($newdir, $zipArchive, $zipdir . $file . '/'); | ||
}else{ | ||
//Add the files | ||
$zipArchive->addFile($dir . $file, $zipdir . $file); | ||
} | ||
} | ||
} | ||
} else { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => "Directory does not exist: $dir" | ||
])); | ||
} | ||
} | ||
|
||
$zip = new ZipArchive(); | ||
$zipname = "../../.tmp/backup.zip"; | ||
|
||
if ($zip->open($zipname, ZipArchive::CREATE)!==TRUE) { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate('cannot_open_zip', $i18n) | ||
])); | ||
} | ||
|
||
addFolderToZip('../../db/', $zip); | ||
addFolderToZip('../../images/uploads/', $zip); | ||
|
||
$numberOfFilesAdded = $zip->numFiles; | ||
|
||
if ($zip->close() === false) { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => "Failed to finalize the zip file" | ||
])); | ||
} else { | ||
die(json_encode([ | ||
"success" => true, | ||
"message" => "Zip file created successfully", | ||
"numFiles" => $numberOfFilesAdded | ||
])); | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate('session_expired', $i18n) | ||
])); | ||
} | ||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
if (isset($_FILES['file'])) { | ||
$file = $_FILES['file']; | ||
$fileTmpName = $file['tmp_name']; | ||
$fileError = $file['error']; | ||
|
||
if ($fileError === 0) { | ||
// Handle the uploaded file here | ||
// The uploaded file will be stored as restore.zip | ||
$fileDestination = '../../.tmp/restore.zip'; | ||
move_uploaded_file($fileTmpName, $fileDestination); | ||
|
||
// Unzip the uploaded file | ||
$zip = new ZipArchive(); | ||
if ($zip->open($fileDestination) === true) { | ||
$zip->extractTo('../../.tmp/restore/'); | ||
$zip->close(); | ||
} | ||
|
||
// Check if wallos.db file exists in the restore folder | ||
if (file_exists('../../.tmp/restore/wallos.db')) { | ||
// Replace the wallos.db file in the db directory with the wallos.db file in the restore directory | ||
if (file_exists('../../db/wallos.db')) { | ||
unlink('../../db/wallos.db'); | ||
} | ||
rename('../../.tmp/restore/wallos.db', '../../db/wallos.db'); | ||
|
||
// Check if restore/logos/ directory exists | ||
if (file_exists('../../.tmp/restore/logos/')) { | ||
// Delete the files and folders in the uploaded logos directory | ||
$dir = '../../images/uploads/logos/'; | ||
|
||
// Create recursive directory iterator | ||
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); | ||
|
||
// Create recursive iterator iterator in Child First Order | ||
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST); | ||
|
||
// For each item in the recursive iterator | ||
foreach ( $ri as $file ) { | ||
// If the item is a directory | ||
if ( $file->isDir() ) { | ||
// Remove the directory | ||
rmdir($file->getPathname()); | ||
} else { | ||
// If the item is a file | ||
// Remove the file | ||
unlink($file->getPathname()); | ||
} | ||
} | ||
|
||
// Copy the contents of restore/logos/ directory to the ../../images/uploads/logos/ directory | ||
$dir = new RecursiveDirectoryIterator('../../.tmp/restore/logos/'); | ||
$ite = new RecursiveIteratorIterator($dir); | ||
$allowedExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp']; | ||
|
||
foreach ($ite as $filePath) { | ||
if (in_array(pathinfo($filePath, PATHINFO_EXTENSION), $allowedExtensions)) { | ||
$destination = str_replace('../../.tmp/restore/', '../../images/uploads/', $filePath); | ||
$destinationDir = pathinfo($destination, PATHINFO_DIRNAME); | ||
|
||
if (!is_dir($destinationDir)) { | ||
mkdir($destinationDir, 0755, true); | ||
} | ||
|
||
copy($filePath, $destination); | ||
} | ||
} | ||
} | ||
|
||
echo json_encode([ | ||
"success" => true, | ||
"message" => "File uploaded and wallos.db exists" | ||
]); | ||
} else { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => "wallos.db does not exist in the backup file" | ||
])); | ||
} | ||
|
||
|
||
} else { | ||
echo json_encode([ | ||
"success" => false, | ||
"message" => "Failed to upload file" | ||
]); | ||
} | ||
} else { | ||
echo json_encode([ | ||
"success" => false, | ||
"message" => "No file uploaded" | ||
]); | ||
} | ||
} else { | ||
echo json_encode([ | ||
"success" => false, | ||
"message" => "Invalid request method" | ||
]); | ||
} | ||
?> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,11 @@ | |
<div class="progress success"></div> | ||
</div> | ||
|
||
<?php | ||
if (isset($db)) { | ||
$db->close(); | ||
} | ||
?> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.