diff --git a/core/01-settings.fragment.php b/core/01-settings.fragment.php index d5027d0..3c9ce22 100644 --- a/core/01-settings.fragment.php +++ b/core/01-settings.fragment.php @@ -29,8 +29,7 @@ if(file_exists("$settingsFilename.compromised")) { $guiConfig = json_decode($guiConfig); $settings = new stdClass(); -if(!file_exists($settingsFilename)) -{ +if(!file_exists($settingsFilename)) { // Copy the default settings over to the main settings array foreach ($guiConfig as $key => $value) $settings->$key = $value->default; @@ -41,18 +40,15 @@ if(!file_exists($settingsFilename)) else $settings = json_decode(file_get_contents("peppermint.json")); -if($settings === null) -{ +if($settings === null) { header("content-type: text/plain"); exit("Error: Failed to decode the settings file! Does it contain a syntax error?"); } // Fill in any missing properties $settingsUpgraded = false; -foreach($guiConfig as $key => $propertyData) -{ - if(!isset($settings->$key)) - { +foreach($guiConfig as $key => $propertyData) { + if(!isset($settings->$key)) { $settings->$key = $propertyData->default; $settingsUpgraded = true; } diff --git a/modules/feature-firstrun.php b/modules/feature-firstrun.php new file mode 100644 index 0000000..837acc0 --- /dev/null +++ b/modules/feature-firstrun.php @@ -0,0 +1,113 @@ + "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", "
Oops! Looks like $settings->sitename is already setup and ready to go! Go to the " . htmlentities($settings->defaultpage)." to get started!
")); + } + + // 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 = "Welcome to Pepperminty Wiki.
+Fill out the below form to get your wiki up and running!
+"; + }); + + + 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", "Oops! Looks like $settings->sitename is already setup and ready to go! Go to the " . htmlentities($settings->defaultpage)." to get started!
")); + } + + // $_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", "Oops! Looks like you forgot to enter a username. Try going back in your browser and filling one in.
")); + } + if(empty($_POST["password"]) || empty($_POST["password-again"])) { + http_response_code(422); + exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "Oops! Looks like you forgot to enter a password. Try going back in your browser and filling one in.
")); + } + if(empty($_POST["wiki-name"])) { + http_response_code(422); + exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "Oops! Looks like you forgot to enter a name for your wiki. Try going back in your browser and filling one in.
")); + } + if(empty($_POST["data-dir"])) { + http_response_code(422); + exit(page_renderer::render_main("Missing information - Error - Pepperminty Wiki", "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 .
(i.e. the current directory).