+ elseif (isset($_POST) && !empty($_POST))
+ {
+ ?><br><div class="container"><?php
+ $opts = (object)$_POST;
+ /* pre-load the appropriate auth plugin */
+ $auth_method = (isset($opts->auth_method)) ? $opts->auth_method : NULL;
+ $auth_method_name = NULL;
+ switch($auth_method)
+ {
+ case "sql_db":
+ $auth_method_name = "SQLDB";
+ break;
+ case "file_db":
+ $auth_method_name = "FileDB";
+ break;
+ }
+ if ($auth_method)
+ $am = new Plugin($auth_method);
+ else
+ {
+ Message::Fail("Invalid parameters");
+ return;
+ }
+ if ($am->error)
+ {
+ Message::Fail("Couldn't load plugin \"$auth_method\": $am->error");
+ return;
+ }
+
+ $config["base_url"] = BASE_URL;
+ $config["plugins"] = Array("$auth_method");
+ if ($auth_method == "sql_db")
+ {
+ $config["mysql"] = [
+ "host" => $opts->sql_host,
+ "database" => $opts->sql_db,
+ "username" => $opts->sql_user,
+ "password" => $opts->sql_password,
+ "table_prefix" => $opts->sql_table_prefix,
+ ];
+ }
+
+ generate_secrets();
+
+ /* First, write only the config file */
+ write_config_file();
+
+ if ($auth_method == "sql_db")
+ {
+ sql_db::delete_tables();
+ if (!sql_db::create_tables())
+ Message::Fail("Could not create SQL tables");
+ } else if ($auth_method == "file_db")
+ {
+ file_db::delete_db();
+ }
+
+ $user = [
+ "user_name" => $opts->account_user,
+ "user_pass" => $opts->account_password,
+ "fname" => $opts->account_fname,
+ "lname" => $opts->account_lname,
+ "user_bio" => $opts->account_bio,
+ "email" => $opts->account_email
+ ];
+
+ create_new_user($user);
+ $lkup = new PanelUser($opts->account_user);
+ if (!$lkup->id)
+ {
+ Message::Fail("Could not create user");
+ return;
+ }
+ $lkup->add_meta('role', 'Super-Admin');
+
+ /* Enable lookups on HIBP by default */
+ $config['hibp'] = true;
+
+ /* Now, write all the config (config.php + settings in DB) */
+ write_config();
+ ?>
+ <br>
+ The configuration file has been written. Now, log in to the panel to proceed with the rest of the installation.<br><br>
+ <a class="text-center btn btn-primary" href="<?php echo BASE_URL; ?>">Let's go!</a></div>
+ <?php
+ return;
+ }