mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 17:23:00 +00:00
Start work on a simpler first-run wizard, but it's not finished yet.
Hopefully this one will be more successful than the last attempt :P
This commit is contained in:
parent
50efd4bb49
commit
1d6409128d
2 changed files with 117 additions and 8 deletions
|
@ -29,8 +29,7 @@ if(file_exists("$settingsFilename.compromised")) {
|
||||||
|
|
||||||
$guiConfig = json_decode($guiConfig);
|
$guiConfig = json_decode($guiConfig);
|
||||||
$settings = new stdClass();
|
$settings = new stdClass();
|
||||||
if(!file_exists($settingsFilename))
|
if(!file_exists($settingsFilename)) {
|
||||||
{
|
|
||||||
// Copy the default settings over to the main settings array
|
// Copy the default settings over to the main settings array
|
||||||
foreach ($guiConfig as $key => $value)
|
foreach ($guiConfig as $key => $value)
|
||||||
$settings->$key = $value->default;
|
$settings->$key = $value->default;
|
||||||
|
@ -41,18 +40,15 @@ if(!file_exists($settingsFilename))
|
||||||
else
|
else
|
||||||
$settings = json_decode(file_get_contents("peppermint.json"));
|
$settings = json_decode(file_get_contents("peppermint.json"));
|
||||||
|
|
||||||
if($settings === null)
|
if($settings === null) {
|
||||||
{
|
|
||||||
header("content-type: text/plain");
|
header("content-type: text/plain");
|
||||||
exit("Error: Failed to decode the settings file! Does it contain a syntax error?");
|
exit("Error: Failed to decode the settings file! Does it contain a syntax error?");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in any missing properties
|
// Fill in any missing properties
|
||||||
$settingsUpgraded = false;
|
$settingsUpgraded = false;
|
||||||
foreach($guiConfig as $key => $propertyData)
|
foreach($guiConfig as $key => $propertyData) {
|
||||||
{
|
if(!isset($settings->$key)) {
|
||||||
if(!isset($settings->$key))
|
|
||||||
{
|
|
||||||
$settings->$key = $propertyData->default;
|
$settings->$key = $propertyData->default;
|
||||||
$settingsUpgraded = true;
|
$settingsUpgraded = true;
|
||||||
}
|
}
|
||||||
|
|
113
modules/feature-firstrun.php
Normal file
113
modules/feature-firstrun.php
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
register_module([
|
||||||
|
"name" => "First run wizard",
|
||||||
|
"version" => "0.1",
|
||||||
|
"author" => "Starbeamrainbowlabs",
|
||||||
|
"description" => "Displays a special page to aid in setting up a new wiki for the first time.",
|
||||||
|
"id" => "feature-firstrun",
|
||||||
|
"code" => function() {
|
||||||
|
|
||||||
|
return true; // Stop this module from actually being executed - it's not ready yet!
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} ?action=firstrun Display the firstrun page
|
||||||
|
* @apiName FirstRun
|
||||||
|
* @apiGroup Settings
|
||||||
|
* @apiPermission Anonymous
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ███████ ██ ██████ ███████ ████████ ██████ ██ ██ ███ ██
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
|
||||||
|
* █████ ██ ██████ ███████ ██ ██████ ██ ██ ██ ██ ██
|
||||||
|
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
* ██ ██ ██ ██ ███████ ██ ██ ██ ██████ ██ ████
|
||||||
|
*/
|
||||||
|
add_action("firstrun", function() use($firstrun_complete) {
|
||||||
|
global $settings;
|
||||||
|
|
||||||
|
if($firstrun_complete) {
|
||||||
|
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>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Check the environment here first
|
||||||
|
// - Make sure peppermint.json isn't accessible
|
||||||
|
// - Check for required modules?
|
||||||
|
|
||||||
|
// TODO: Add a button to skip the firstrun wizard & do your own manual setup
|
||||||
|
|
||||||
|
$result = "<h1>Welcome!</h1>
|
||||||
|
<p>Welcome to Pepperminty Wiki.</p>
|
||||||
|
<p>Fill out the below form to get your wiki up and running!</p>
|
||||||
|
<form method='post' action='?action=firstrun-complete'>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Admin account details</legend>
|
||||||
|
|
||||||
|
<label for='username'>Username:</label>
|
||||||
|
<input type='text' id='username' name='username' placeholder='e.g. bob, admin' required />
|
||||||
|
<br />
|
||||||
|
<p><em>Longer is better! Aim for at least 14 characters.</em></p>
|
||||||
|
<label for='username'>Password:</label>
|
||||||
|
<input type='text' id='password' name='password' required />
|
||||||
|
<br />
|
||||||
|
<label for='username'>Repeat Password:</label>
|
||||||
|
<input type='text' id='password-again' name='password-again' required />
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Wiki Details</legend>
|
||||||
|
|
||||||
|
<label for='wiki-name'>Wiki Name:</label>
|
||||||
|
<input type='text' id='wiki-name' name='wiki-name' placeholder=\"e.g. Bob's Rockets Compendium\" required />
|
||||||
|
<!-- FUTURE: Have a logo url box here? -->
|
||||||
|
<p><em>The location on the server's disk to store the wiki data. Relative paths are ok - the default is <code>.</code> (i.e. the current directory).</em></p>
|
||||||
|
<label for='data-dir'>Data Storage Directory:</label>
|
||||||
|
<input type='text' id='data-dir' name='data-dir' value='.' required />
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<input type='submit' value='Create Wiki!' />
|
||||||
|
</form>";
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
add_action("firstrun-complete", function() {
|
||||||
|
global $version, $commit;
|
||||||
|
|
||||||
|
if($firstrun_complete) {
|
||||||
|
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>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// $_POST: username, password, password-again, wiki-name, data-dir
|
||||||
|
|
||||||
|
if(empty($_POST["username"])) {
|
||||||
|
http_response_code(422);
|
||||||
|
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["password"]) || empty($_POST["password-again"])) {
|
||||||
|
http_response_code(422);
|
||||||
|
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"])) {
|
||||||
|
http_response_code(422);
|
||||||
|
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"])) {
|
||||||
|
http_response_code(422);
|
||||||
|
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>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
file_put_contents("._peppermint_installed", "Install complete at " . date("c") . "with Pepperminty Wiki v$version-$commit");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Reference in a new issue