|
|
@ -1,5 +1,5 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
use function _\find;
|
|
|
|
class SetUp
|
|
|
|
class SetUp
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public static function status()
|
|
|
|
public static function status()
|
|
|
@ -91,7 +91,104 @@ class SetUp
|
|
|
|
return $result;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function restore()
|
|
|
|
public static function restore($request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
|
|
|
"type" => "requestLame",
|
|
|
|
|
|
|
|
"message" => "Still working on it.",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
$body = $request->getParsedBody();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$backup = $request->getUploadedFiles();
|
|
|
|
|
|
|
|
$file = $backup["backup-upload"];
|
|
|
|
|
|
|
|
$name = $file->getClientFileName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//park it so it can be read
|
|
|
|
|
|
|
|
$file->moveTo("../content" . "/" . $name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//open it and get files to verify user
|
|
|
|
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
|
|
|
|
if ($zip->open("../content" . "/" . $name) === true) {
|
|
|
|
|
|
|
|
$folks = json_decode($zip->getFromName("settings/folks.json"), true);
|
|
|
|
|
|
|
|
$found = find($folks, ["handle" => $body["restore_member_handle"]]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if member is found in back up, check pass
|
|
|
|
|
|
|
|
if ($found) {
|
|
|
|
|
|
|
|
if (password_verify($body["restore_member_pass"], $found["password"])) {
|
|
|
|
|
|
|
|
//backup verified, restore site
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//set new secret key for older folks configs
|
|
|
|
|
|
|
|
$newFolks = [];
|
|
|
|
|
|
|
|
if (!isset($found["secret"])) {
|
|
|
|
|
|
|
|
$found["secret"] = StringTools::randomString(12);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($newFolks, $found);
|
|
|
|
|
|
|
|
//dump files in folder
|
|
|
|
|
|
|
|
$zip->extractTo("../content");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//move to appropriate spots
|
|
|
|
|
|
|
|
rename(
|
|
|
|
|
|
|
|
"../content/settings/settings.json",
|
|
|
|
|
|
|
|
"../config/settings.json"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//rename("../content/settings/folks.json", "../config/folks.json");
|
|
|
|
|
|
|
|
DocTools::writeSettings("../config/folks.json", $newFolks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rename("../content/settings/tags.json", "../config/tags.json");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rename(
|
|
|
|
|
|
|
|
"../content/public/assets/images/blog",
|
|
|
|
|
|
|
|
"../public/assets/images/blog"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rename("../content/content/pages/", "../content/pages");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//legacy check for old file structure
|
|
|
|
|
|
|
|
if (is_file("../content/pages/index.md")) {
|
|
|
|
|
|
|
|
if (!is_dir("../content/pages/start")) {
|
|
|
|
|
|
|
|
//Directory does not exist, so lets create it.
|
|
|
|
|
|
|
|
mkdir("../content/pages/start", 0755, true);
|
|
|
|
|
|
|
|
//move start page to appropriate spot
|
|
|
|
|
|
|
|
rename(
|
|
|
|
|
|
|
|
"../content/pages/index.md",
|
|
|
|
|
|
|
|
"../content/pages/start/index.md"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//chill
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//clean up
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DocTools::deleteFolder("../content/settings");
|
|
|
|
|
|
|
|
DocTools::deleteFolder("../content/public");
|
|
|
|
|
|
|
|
DocTools::deleteFolder("../content/content");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "AUTH VERIFIED";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
|
|
|
"type" => "requestLame",
|
|
|
|
|
|
|
|
"message" => "Check that password, champ.",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
|
|
|
"type" => "requestLame",
|
|
|
|
|
|
|
|
"message" => "No member found by that name, hoss",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$zip->close();
|
|
|
|
|
|
|
|
$zipPath = "../content/" . $name;
|
|
|
|
|
|
|
|
//trash zip when done
|
|
|
|
|
|
|
|
unlink($zipPath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
|
|
|
"type" => "requestLame",
|
|
|
|
|
|
|
|
"message" => "Could not open backup. RATS!",
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|