mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Work more on the first-run installer, but it's not finished yet
This commit is contained in:
parent
e37541d606
commit
1dc0438a18
1 changed files with 54 additions and 13 deletions
|
@ -12,8 +12,10 @@ register_module([
|
||||||
return true; // Stop this module from actually being executed - it's not ready yet!
|
return true; // Stop this module from actually being executed - it's not ready yet!
|
||||||
|
|
||||||
// TODO: Figure out how to detect pre-existing wikis here
|
// TODO: Figure out how to detect pre-existing wikis here
|
||||||
// Perhaps this could be a setting instead? We'd need to update the settings logic a bit
|
|
||||||
$firstrun_complete = file_exists("._peppermint_installed");
|
if(!$firstrun_complete && count(glob("._peppermint_secret_*")) == 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} ?action=firstrun Display the firstrun page
|
* @api {get} ?action=firstrun Display the firstrun page
|
||||||
|
@ -30,14 +32,20 @@ register_module([
|
||||||
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
* ██ ██ ██ ██ ███████ ██ ██ ██ ██████ ██ ████
|
* ██ ██ ██ ██ ███████ ██ ██ ██ ██████ ██ ████
|
||||||
*/
|
*/
|
||||||
add_action("firstrun", function() use($firstrun_complete) {
|
add_action("firstrun", function() {
|
||||||
global $settings;
|
global $settings;
|
||||||
|
|
||||||
if($firstrun_complete) {
|
if($settings->firstrun_complete) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
exit(page_renderer::render_main("Setup complete - Error - $settings->sitename", "<p>Oops! Looks like $settings->sitename is already setup and ready to go! Go to the <a href='?action=$settings->defaultaction&page=".rawurlencode($settings->defaultpage)."'>" . htmlentities($settings->defaultpage)."</a> to get started!</p>"));
|
exit(page_renderer::render_main("Setup complete - Error - $settings->sitename", "<p>Oops! Looks like $settings->sitename is already setup and ready to go! Go to the <a href='?action=$settings->defaultaction&page=".rawurlencode($settings->defaultpage)."'>" . htmlentities($settings->defaultpage)."</a> to get started!</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!module_exists("page-login")) {
|
||||||
|
http_response_code(503);
|
||||||
|
exit(page_renderer::render_main("Build error - Pepperminty Wiki", "<p>The <code>page-login</code> wasn't included in this build of Pepperminty Wiki, so the first-run installation wizard will not work correctly.</p>
|
||||||
|
<p>You can still complete the setup manually, however! Once done, set <code>firstrun_complete</code> in peppermint.json to <code>true</code>.</p>"));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check the environment here first
|
// TODO: Check the environment here first
|
||||||
// - Make sure peppermint.json isn't accessible
|
// - Make sure peppermint.json isn't accessible
|
||||||
// - Check for required modules?
|
// - Check for required modules?
|
||||||
|
@ -54,6 +62,9 @@ register_module([
|
||||||
<label for='username'>Username:</label>
|
<label for='username'>Username:</label>
|
||||||
<input type='text' id='username' name='username' placeholder='e.g. bob, admin' required />
|
<input type='text' id='username' name='username' placeholder='e.g. bob, admin' required />
|
||||||
<br />
|
<br />
|
||||||
|
<label for='username'>Email address:</label>
|
||||||
|
<input type='text' id='email-address' name='email-address' required />
|
||||||
|
<br />
|
||||||
<p><em>Longer is better! Aim for at least 14 characters.</em></p>
|
<p><em>Longer is better! Aim for at least 14 characters.</em></p>
|
||||||
<label for='username'>Password:</label>
|
<label for='username'>Password:</label>
|
||||||
<input type='text' id='password' name='password' required />
|
<input type='text' id='password' name='password' required />
|
||||||
|
@ -74,41 +85,71 @@ register_module([
|
||||||
|
|
||||||
<input type='submit' value='Create Wiki!' />
|
<input type='submit' value='Create Wiki!' />
|
||||||
</form>";
|
</form>";
|
||||||
|
|
||||||
|
exit(page_renderer::render_main("Welcome! - Pepperminty Wiki", $result));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
add_action("firstrun-complete", function() {
|
add_action("firstrun-complete", function() {
|
||||||
global $version, $commit;
|
global $version, $commit, $settings;
|
||||||
|
|
||||||
if($firstrun_complete) {
|
if($settings->firstrun_complete) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
exit(page_renderer::render_main("Setup complete - Error - $settings->sitename", "<p>Oops! Looks like $settings->sitename is already setup and ready to go! Go to the <a href='?action=$settings->defaultaction&page=".rawurlencode($settings->defaultpage)."'>" . htmlentities($settings->defaultpage)."</a> to get started!</p>"));
|
exit(page_renderer::render_main("Setup complete - Error - $settings->sitename", "<p>Oops! Looks like $settings->sitename is already setup and ready to go! Go to the <a href='?action=$settings->defaultaction&page=".rawurlencode($settings->defaultpage)."'>" . htmlentities($settings->defaultpage)."</a> to get started!</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// $_POST: username, password, password-again, wiki-name, data-dir
|
// $_POST: username, email-address, password, password-again, wiki-name, data-dir
|
||||||
|
|
||||||
if(empty($_POST["username"])) {
|
if(empty($_POST["username"])) {
|
||||||
http_response_code(422);
|
http_response_code(400);
|
||||||
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a username. Try going back in your browser and filling one in.</p>"));
|
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a username. Try going back in your browser and filling one in.</p>"));
|
||||||
}
|
}
|
||||||
|
if(empty($_POST["email-address"])) {
|
||||||
|
http_response_code(400);
|
||||||
|
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter an email address. Try going back in your browser and filling one in.</p>"));
|
||||||
|
}
|
||||||
|
if(!filter_var($_POST["email-address"], FILTER_VALIDATE_EMAIL)) {
|
||||||
|
http_response_code(400);
|
||||||
|
exit(page_renderer::render_main("Invalid email address - Error - Pepperminty Wiki", "<p>Oops! Looks like that email address isn't valid. Try going back in your browser and correcting it.</p>"));
|
||||||
|
}
|
||||||
if(empty($_POST["password"]) || empty($_POST["password-again"])) {
|
if(empty($_POST["password"]) || empty($_POST["password-again"])) {
|
||||||
http_response_code(422);
|
http_response_code(400);
|
||||||
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a password. Try going back in your browser and filling one in.</p>"));
|
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a password. Try going back in your browser and filling one in.</p>"));
|
||||||
}
|
}
|
||||||
if(empty($_POST["wiki-name"])) {
|
if($_POST["password"] !== $_POST["password-again"]) {
|
||||||
http_response_code(422);
|
http_response_code(422);
|
||||||
|
exit(page_renderer::render_main("Password mismatch - Error - Pepperminty Wiki", "<p>Oops! Looks like the passwords you entered aren't the same. Try going back in your browser and entering it again.</p>"));
|
||||||
|
}
|
||||||
|
if(empty($_POST["wiki-name"])) {
|
||||||
|
http_response_code(400);
|
||||||
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a name for your wiki. Try going back in your browser and filling one in.</p>"));
|
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a name for your wiki. Try going back in your browser and filling one in.</p>"));
|
||||||
}
|
}
|
||||||
if(empty($_POST["data-dir"])) {
|
if(empty($_POST["data-dir"])) {
|
||||||
http_response_code(422);
|
http_response_code(400);
|
||||||
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a directory on the server to store the wiki's data in. Try going back in your browser and filling one in. Relative paths are ok - the default is <code>.</code> (i.e. the current directory).</p>"));
|
exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "<p>Oops! Looks like you forgot to enter a directory on the server to store the wiki's data in. Try going back in your browser and filling one in. Relative paths are ok - the default is <code>.</code> (i.e. the current directory).</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate the user data object & replace the pre-generated users
|
||||||
|
$user_data = new stdClass();
|
||||||
|
$user_data->password = hash_password($_POST["password"]);
|
||||||
|
$user_data->emailAddress = $_POST["email-address"];
|
||||||
|
$settings->users = new stdClass();
|
||||||
|
$settings->users->{$_POST["username"]} = $user_data;
|
||||||
|
|
||||||
|
// Apply the settings
|
||||||
|
$settings->firstrun_complete = true;
|
||||||
|
$settings->sitename = $_POST["wiki-name"];
|
||||||
|
$settings->data_storage_dir = $_POST["data-dir"];
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
if(!save_settings()) {
|
||||||
|
http_response_code(500);
|
||||||
|
exit(page_renderer::render_main("Server Error - Pepperminty Wiki", "<p>Oops! Pepperminty Wiki was unable to save your settings back to disk. This can happen if Pepperminty Wiki does not have write permissions on it's own directory and the files contained within (except <code>index.php</code> of course).</p>
|
||||||
|
<p>Try contacting your server owner and ask them to correct it. If you are the server owner, you may need to run <code>sudo chown -R WEBSERVER_USERNAME:WEBSERVER_USERNAME PATH/TO/WIKI/DIRECTORY</code>, replacing the bits in UPPERCASE.</p>"));
|
||||||
|
}
|
||||||
|
|
||||||
file_put_contents("._peppermint_installed", "Install complete at " . date("c") . "with Pepperminty Wiki v$version-$commit");
|
http_response_code(201);
|
||||||
|
exit(page_renderer::render_main("Setup complete! - Pepperminty Wiki", "<p>Congratulations! You've completed the Pepperminty Wiki setup.</p>
|
||||||
|
<p><a href='?action=$settings->defaultaction'>Click here</a> to start using $settings->sitename, your new wiki!</p>"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue