2014-12-26 11:14:29 +00:00
< ? php
2020-09-23 22:22:39 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at https :// mozilla . org / MPL / 2.0 /. */
2014-12-26 11:06:37 +00:00
/*
* Pepperminty Wiki
* ================
2016-04-03 17:11:34 +00:00
* Inspired by Minty Wiki by am2064
2014-12-26 11:06:37 +00:00
* Link : https :// github . com / am2064 / Minty - Wiki
2016-05-29 19:34:34 +00:00
*
2014-12-26 11:06:37 +00:00
* Credits :
2014-12-26 18:14:38 +00:00
* Code by @ Starbeamrainbowlabs
2016-03-12 18:55:47 +00:00
* Parsedown - by erusev and others on github from http :// parsedown . org /
2016-04-03 17:01:12 +00:00
* Mathematical Expression rendering
* Code : @ con - f - use < https :// github . com / con - f - use >
* Rendering : MathJax ( https :// www . mathjax . org / )
2015-01-05 18:53:44 +00:00
* Bug reports :
2015-07-14 15:11:59 +00:00
* #2 - Incorrect closing tag - nibreh <https://github.com/nibreh/>
* #8 - Rogue <datalist /> tag - nibreh <https://github.com/nibreh/>
2014-12-26 11:06:37 +00:00
*/
2016-06-22 08:13:32 +00:00
$guiConfig = <<< 'GUICONFIG'
2016-06-12 20:06:27 +00:00
{ guiconfig }
GUICONFIG ;
2016-06-22 08:13:32 +00:00
2016-12-11 19:03:06 +00:00
$settingsFilename = " peppermint.json " ;
2017-11-04 21:33:21 +00:00
if ( file_exists ( " $settingsFilename .compromised " )) {
http_response_code ( 500 );
header ( " content-type: text/plain " );
2019-12-22 14:32:46 +00:00
exit ( " Error: $settingsFilename .compromised exists on disk, so it's likely you need to block access to 'peppermint.json' from the internet. If you've done this already, please delete $settingsFilename .compromised and reload this page. \n \n If you've done this check manually, please set the disable_peppermint_access_check setting to false. \n \n This check was done as part of the first run wizard. " );
2017-11-04 21:33:21 +00:00
}
2016-06-12 20:06:27 +00:00
$guiConfig = json_decode ( $guiConfig );
2015-04-09 14:13:07 +00:00
$settings = new stdClass ();
2019-05-10 23:35:17 +00:00
if ( ! file_exists ( $settingsFilename )) {
2016-06-12 20:06:27 +00:00
// Copy the default settings over to the main settings array
foreach ( $guiConfig as $key => $value )
2016-06-13 05:41:50 +00:00
$settings -> $key = $value -> default ;
2016-06-12 20:06:27 +00:00
// Generate a random secret
2018-05-11 11:45:34 +00:00
$settings -> secret = bin2hex ( random_bytes ( 16 ));
2019-09-11 19:21:21 +00:00
if ( file_put_contents ( " peppermint.json " , json_encode ( $settings , JSON_PRETTY_PRINT )) === false ) {
http_response_code ( 503 );
2020-02-04 01:23:44 +00:00
header ( " content-type: text/plain " );
2019-09-11 19:21:21 +00:00
exit ( " Oops! It looks like $settings->sitename wasn't able to write peppermint.json to disk. \n This file contains all of $settings->sitename 's settings, so it's really important! \n Have you checked that PHP has write access to the directory that index.php is located in (and all it's contents and subdirectories)? Try \n \n sudo chown USERNAME:USERNAME -R path/to/directory \n \n and \n \n sudo chmod -R 0644 path/to/directory; \n sudo chmod -R +X path/too/directory \n \n ....where USERNAME is the username that the PHP process is running under. " );
}
2016-06-12 20:06:27 +00:00
}
else
$settings = json_decode ( file_get_contents ( " peppermint.json " ));
2019-05-10 23:35:17 +00:00
if ( $settings === null ) {
2016-09-19 09:28:32 +00:00
header ( " content-type: text/plain " );
exit ( " Error: Failed to decode the settings file! Does it contain a syntax error? " );
}
2016-12-06 19:17:11 +00:00
// Fill in any missing properties
2019-05-11 14:39:55 +00:00
$settings_upgraded = false ;
2019-05-10 23:35:17 +00:00
foreach ( $guiConfig as $key => $propertyData ) {
2019-05-11 21:52:08 +00:00
if ( ! property_exists ( $settings , $key )) {
2020-07-28 18:42:41 +00:00
error_log ( " [PeppermintyWiki/ $settings->sitename /settings] Upgrading $key " );
2016-12-06 19:17:11 +00:00
$settings -> $key = $propertyData -> default ;
2019-05-11 14:39:55 +00:00
$settings_upgraded = true ;
2016-12-06 19:17:11 +00:00
}
}
2019-05-11 14:39:55 +00:00
if ( $settings_upgraded )
2016-12-06 19:17:11 +00:00
file_put_contents ( " peppermint.json " , json_encode ( $settings , JSON_PRETTY_PRINT ));
2019-05-11 14:39:55 +00:00
// If the first-run wizard hasn't been completed but we've filled in 1 or more new settings, then we must be a pre-existing wiki upgrading from a previous version. We can guarantee this because of the new firstrun_complete setting
if ( ! $settings -> firstrun_complete && $settings_upgraded ) {
$settings -> firstrun_complete = true ;
file_put_contents ( " peppermint.json " , json_encode ( $settings , JSON_PRETTY_PRINT ));
}
2016-12-06 19:17:11 +00:00
// Insert the default CSS if requested
2016-12-11 18:52:53 +00:00
$defaultCSS = <<< THEMECSS
2016-06-22 08:13:32 +00:00
{ default - css }
THEMECSS ;
2018-05-10 23:18:21 +00:00
// This will automatically save to peppermint.json if an automatic takes place
// for another reason (such as password rehashing or user data updates), but it
// doesn't really matter because the site name isn't going to change all that
// often, and even if it does it shouldn't matter :P
if ( $settings -> sessionprefix == " auto " )
$settings -> sessionprefix = " pepperminty-wiki- " . preg_replace ( '/[^a-z0-9\-_]/' , " - " , strtolower ( $settings -> sitename ));
2019-05-11 14:39:55 +00:00
2014-12-26 11:14:29 +00:00
?>