From 9800c257de64774cc8e09e2a75f4de6a1dcb6ac2 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 19 Aug 2024 22:18:38 +0100 Subject: [PATCH] settings: fill in secret if it doesn't exist but peppermint.json does --- Changelog.md | 5 +++-- core/01-settings.fragment.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3d03f40..eac5d34 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,8 +7,9 @@ This is the next release of Pepperminty Wiki, that hasn't been released yet. - **Fixed:** Fixed link to the interwiki links documentation on the help page if interwiki links have not yet been setup. - **Fixed:** Fixed typos in system text -- **Fixed:** Fixed handling of [`firstrun_complete`](https://starbeamrainbowlabs.com/labs/peppermint/peppermint-config-info.php#config_firstrun_complete) setting if `peppermint.json` is prefilled with a `firstrun_complete` directive but the Wiki hasn't been initialised for the first time yet - useful for installations inside Docker -- **Changed:** Correctly check for `pdo_sqlite3` instead of `sqlite3` in `feature-firstrun` +- **Fixed:** Fixed handling of [`firstrun_complete`](https://starbeamrainbowlabs.com/labs/peppermint/peppermint-config-info.php#config_firstrun_complete) setting if `peppermint.json` is prefilled with a `firstrun_complete` directive but the Wiki hasn't been initialised for the first time yet - useful for installations inside Docker +- **Fixed:** Fill in `secret` with a secrely random value inside `peppermint.json` if it doesn't exist.... even if `peppermint.json` already exists. Also useful for Docker users. +- **Changed:** Correctly check for `pdo_sqlite3` instead of `sqlite3` in `feature-firstrun` - **Changed:** Catch and deal with more unpacking issues on first run (thanks, @daveschroeter in [#249](https://github.com/sbrl/Pepperminty-Wiki/issues/249)) diff --git a/core/01-settings.fragment.php b/core/01-settings.fragment.php index 5147661..bd1b4e9 100644 --- a/core/01-settings.fragment.php +++ b/core/01-settings.fragment.php @@ -37,8 +37,6 @@ if(!file_exists($settingsFilename)) { // Copy the default settings over to the main settings array foreach ($guiConfig as $key => $value) $settings->$key = $value->default; - // Generate a random secret - $settings->secret = bin2hex(random_bytes(16)); if(file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT)) === false) { http_response_code(503); header("content-type: text/plain"); @@ -65,6 +63,9 @@ foreach($guiConfig as $key => $propertyData) { $did_upgrade_firstrun_key = true; } } +// Generate a random secret if it doesn't already exist +if(!property_exists($settings, "secret")) + $settings->secret = bin2hex(random_bytes(16)); if($settings_upgraded) file_put_contents("peppermint.json", json_encode($settings, JSON_PRETTY_PRINT));