1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 05:22:59 +00:00

Added semiautomtic update and other things

This commit is contained in:
Starbeamrainbowlabs 2015-03-14 18:38:32 +00:00
parent 32846bd6ea
commit 0e88b7cbeb
4 changed files with 190 additions and 48 deletions

View file

@ -43,6 +43,10 @@ If you prefer, you can clone this repository or use the "Download Zip" button to
3. Open both files for editing 3. Open both files for editing
4. Copy your settings over the new settings (making sure that you don't delete any new settings - it will be obvious if you do this if you have error reporting enabled) 4. Copy your settings over the new settings (making sure that you don't delete any new settings - it will be obvious if you do this if you have error reporting enabled)
### Breaking Changes
From time to time breaking changes will be made. By this I mean additions and / or deletions to the settings that can be found at the top of your wiki's `index.php`. They will be listed here so you can manually update your settings if required.
* (no breaking changes have been made yet)
### Building ### Building
Pepperminty Wiki uses a simple PHP based build script. If you want to run this script yourself (for whatever reason), follow these instructions: Pepperminty Wiki uses a simple PHP based build script. If you want to run this script yourself (for whatever reason), follow these instructions:

View file

@ -6,6 +6,7 @@ $start_time = time(true);
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/////////////// Do not edit below this line unless you know what you are doing! /////////////// /////////////// Do not edit below this line unless you know what you are doing! ///////////////
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
$version = "0.4-dev";
session_start(); session_start();
///////// Login System ///////// ///////// Login System /////////
//clear expired sessions //clear expired sessions
@ -648,7 +649,13 @@ switch($_GET["action"])
<tr><td><code> <tr><td><code>
--- ---
</code></td><td><hr /></td></tr> </code></td><td><hr /></td></tr>
</table>"; <tr><tds><code> - One
- Two
- Three</code></td><td><ul><li>One</li><li>Two</li><li>Three</li></ul></td></tr>
</table>
<h2>Administrator Actions</h2>
<p>By default, the <code>delete</code> and <code>move</code> actions are shown on the nav bar. These can be used by administrators to delete or move pages.</p>
<p>The other thing admininistrators can do is update the wiki (provided they know the site's secret). This page can be found here: <a href='?action=update'>Update $sitename</a>.</p>";
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
@ -757,6 +764,67 @@ switch($_GET["action"])
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
/*
* _ _
* _ _ _ __ __| |__ _| |_ ___
* | || | '_ \/ _` / _` | _/ -_)
* \_,_| .__/\__,_\__,_|\__\___|
* |_| %update%
*/
case "update":
if(!$isadmin)
{
http_response_code(401);
exit(renderpage("Update - Error", "<p>You must be an administrator to do that.</p>"));
}
if(!isset($_GET["do"]) or $_GET["do"] !== "true")
{
exit(renderpage("Update $sitename", "<p>This page allows you to update $sitename.</p>
<p>Currently, $sitename is using $version of Pepperminty Wiki.</p>
<p>This script will automatically download and install the latest version of Pepperminty Wiki from the url of your choice (see settings), regardless of whether an update is acutally needed (version checking isn't implemented yet).</p>
<p>To update $sitename, fill out the form below and click click the update button.</p>
<form method='get' action=''>
<input type='hidden' name='action' value='update' />
<input type='hidden' name='do' value='true' />
<label for='secret'>$sitename's secret code</label>
<input type='text' name='secret' value='' />
<input type='submit' value='Update' />
</form>"));
}
if(!isset($_GET["secret"]) or $_GET["secret"] !== $sitesecret)
{
exit(renderpage("Update $sitename - Error", "<p>You forgot to enter $sitename's secret code or entered it incorrectly. $sitename's secret can be found in the settings portion of <code>index.php</code>.</p>"));
}
$settings_separator = "/////////////// Do not edit below this line unless you know what you are doing! ///////////////";
$log = "Beginning update...\n";
$log .= "I am <code>" . __FILE__ . "</code>.\n";
$oldcode = file_get_contents(__FILE__);
$log .= "Fetching new code...";
$newcode = file_get_contents($updateurl);
$log .= "done.\n";
$log .= "Rewriting <code>" . __FILE__ . "</code>...";
$settings = substr($oldcode, 0, strpos($oldcode, $settings_separator));
$code = substr($newcode, strpos($newcode, $settings_separator));
$result = $settings . $code;
$log .= "done.\n";
$log .= "Saving...";
file_put_contents(__FILE__, $result);
$log .= "done.\n";
$log .= "Update complete. I am now running on the latest version of $sitename.";
$log .= "The version number that I have updated to can be found on the credits or help ages."
exit(renderpage("Update - Success", "<ul><li>" . implode("</li><li>", explode("\n", $log)) . "</li></ul>"));
break;
/* /*
* _ _ * _ _
* | |__ __ _ ___| |__ * | |__ __ _ ___| |__

View file

@ -20,10 +20,11 @@ $sitename = "Pepperminty Wiki";
// the url from which to fetch updates. Defaults to the master (development) branch If there is sufficient demand, a separate stable branch will be created. // the url from which to fetch updates. Defaults to the master (development) branch If there is sufficient demand, a separate stable branch will be created.
//currently not implemented (yet). //currently not implemented (yet).
// MAKE SURE THAT THIS POINTS TO A HTTP URL, OTHERWISE SOMEONE COULD INJECT A VIRUS INTO YOUR WIKI
$updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php"; $updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php";
// the secret key used to perform 'dangerous' actions, like updating the wiki, and deleting pages. It is strongly advised that you change this! // the secret key used to perform 'dangerous' actions, like updating the wiki, and deleting pages. It is strongly advised that you change this!
//note that neither of these features have been added yet. // note that (semi)automatic updating of your wiki has not been added yet.
$sitesecret = "ed420502615bac9037f8f12abd4c9f02"; $sitesecret = "ed420502615bac9037f8f12abd4c9f02";
// whether people can edit the site // whether people can edit the site
@ -51,7 +52,7 @@ $admins = [ "admin" ];
// The string that is prepended before an admin's name on the nav bar. defaults to a diamond shape (&#9670;). // The string that is prepended before an admin's name on the nav bar. defaults to a diamond shape (&#9670;).
$admindisplaychar = "&#9670;"; $admindisplaychar = "&#9670;";
//contact details for the site administrator. Since user can only be added by editing this file, people will need a contact address to use to ask for an account. Displayed at the bottom of the page, and will be appropriatly obfusticateed to deter spammers. // contact details for the site administrator. Since user can only be added by editing this file, people will need a contact address to use to ask for an account. Displayed at the bottom of the page, and will be appropriatly obfusticated to deter spammers.
$admindetails = [ $admindetails = [
"name" => "Administrator", "name" => "Administrator",
"email" => "admin@localhost" "email" => "admin@localhost"
@ -107,13 +108,16 @@ Actions:
save - save edits to page save - save edits to page
page - page name page - page name
list - list pages list - list pages
category - the category to list [optional] category - the category to list [optional] [unimplemented]
login - login to the site login - login to the site
logout - logout logout - logout
checklogin - check login credentials and set cookie checklogin - check login credentials and set cookie
hash - hash a string with sha256 hash - hash a string with sha256
string - string to hash string - string to hash
help - get help help - get help
update - update the wiki
do - set to `true` to actually update the wiki
secret - set to the value of the site's secret
credits - view the credits credits - view the credits
delete - delete a page delete - delete a page
page - page name page - page name
@ -124,6 +128,7 @@ Actions:
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
/////////////// Do not edit below this line unless you know what you are doing! /////////////// /////////////// Do not edit below this line unless you know what you are doing! ///////////////
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
$version = "0.4-dev";
session_start(); session_start();
///////// Login System ///////// ///////// Login System /////////
//clear expired sessions //clear expired sessions
@ -766,7 +771,13 @@ switch($_GET["action"])
<tr><td><code> <tr><td><code>
--- ---
</code></td><td><hr /></td></tr> </code></td><td><hr /></td></tr>
</table>"; <tr><tds><code> - One
- Two
- Three</code></td><td><ul><li>One</li><li>Two</li><li>Three</li></ul></td></tr>
</table>
<h2>Administrator Actions</h2>
<p>By default, the <code>delete</code> and <code>move</code> actions are shown on the nav bar. These can be used by administrators to delete or move pages.</p>
<p>The other thing admininistrators can do is update the wiki (provided they know the site's secret). This page can be found here: <a href='?action=update'>Update $sitename</a>.</p>";
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
@ -875,6 +886,61 @@ switch($_GET["action"])
exit(renderpage($title, $content)); exit(renderpage($title, $content));
break; break;
/*
* _ _
* _ _ _ __ __| |__ _| |_ ___
* | || | '_ \/ _` / _` | _/ -_)
* \_,_| .__/\__,_\__,_|\__\___|
* |_| %update%
*/
case "update":
if(!$isadmin)
{
http_response_code(401);
exit(renderpage("Update - Error", "<p>You must be an administrator to do that.</p>"));
}
if(!isset($_GET["do"]) or $_GET["do"] !== "true")
{
exit(renderpage("Update $sitename", "<p>This page allows you to update $sitename.</p>
<p>Currently, $sitename is using $version of Pepperminty Wiki.</p>
<p>This script will automatically download and install the latest version of Pepperminty Wiki from the url of your choice (see settings), regardless of whether an update is acutally needed (version checking isn't implemented yet).</p>
<p>To update $sitename, fill out the form below and click click the update button.</p>
<form method='get' action=''>
<input type='hidden' name='action' value='update' />
<input type='hidden' name='do' value='true' />
<label for='secret'>$sitename's secret code</label>
<input type='text' name='secret' value='' />
<input type='submit' value='Update' />
</form>"));
}
if(!isset($_GET["secret"]) or $_GET["secret"] !== $sitesecret)
{
exit(renderpage("Update $sitename - Error", "<p>You forgot to enter $sitename's secret code or entered it incorrectly. $sitename's secret can be found in the settings portion of <code>index.php</code>.</p>"));
}
$settings_separator = "/////////////// Do not edit below this line unless you know what you are doing! ///////////////";
$log = "Beginning update...\n";
$log .= "I am <code>" . __FILE__ . "</code>.\n";
$oldcode = file_get_contents(__FILE__);
$log .= "Fetching new code...";
$newcode = file_get_contents($updateurl);
$log .= "done.\n";
$log .= "Rewriting <code>" . __FILE__ . "</code>...";
$settings = substr($oldcode, 0, strpos($oldcode, $settings_separator));
$code = substr($newcode, strpos($newcode, $settings_separator));
$result = $settings . $code;
$log .= "done.\n";
header("content-type: text/php");
echo("$log\n\n");
exit($result);
break;
/* /*
* _ _ * _ _
* | |__ __ _ ___| |__ * | |__ __ _ ___| |__

View file

@ -17,10 +17,11 @@ $sitename = "Pepperminty Wiki";
// the url from which to fetch updates. Defaults to the master (development) branch If there is sufficient demand, a separate stable branch will be created. // the url from which to fetch updates. Defaults to the master (development) branch If there is sufficient demand, a separate stable branch will be created.
//currently not implemented (yet). //currently not implemented (yet).
// MAKE SURE THAT THIS POINTS TO A HTTP URL, OTHERWISE SOMEONE COULD INJECT A VIRUS INTO YOUR WIKI
$updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php"; $updateurl = "https://raw.githubusercontent.com/sbrl/pepperminty-wiki/master/index.php";
// the secret key used to perform 'dangerous' actions, like updating the wiki, and deleting pages. It is strongly advised that you change this! // the secret key used to perform 'dangerous' actions, like updating the wiki, and deleting pages. It is strongly advised that you change this!
//note that neither of these features have been added yet. // note that (semi)automatic updating of your wiki has not been added yet.
$sitesecret = "ed420502615bac9037f8f12abd4c9f02"; $sitesecret = "ed420502615bac9037f8f12abd4c9f02";
// whether people can edit the site // whether people can edit the site
@ -48,7 +49,7 @@ $admins = [ "admin" ];
// The string that is prepended before an admin's name on the nav bar. defaults to a diamond shape (&#9670;). // The string that is prepended before an admin's name on the nav bar. defaults to a diamond shape (&#9670;).
$admindisplaychar = "&#9670;"; $admindisplaychar = "&#9670;";
//contact details for the site administrator. Since user can only be added by editing this file, people will need a contact address to use to ask for an account. Displayed at the bottom of the page, and will be appropriatly obfusticateed to deter spammers. // contact details for the site administrator. Since user can only be added by editing this file, people will need a contact address to use to ask for an account. Displayed at the bottom of the page, and will be appropriatly obfusticated to deter spammers.
$admindetails = [ $admindetails = [
"name" => "Administrator", "name" => "Administrator",
"email" => "admin@localhost" "email" => "admin@localhost"
@ -104,13 +105,16 @@ Actions:
save - save edits to page save - save edits to page
page - page name page - page name
list - list pages list - list pages
category - the category to list [optional] category - the category to list [optional] [unimplemented]
login - login to the site login - login to the site
logout - logout logout - logout
checklogin - check login credentials and set cookie checklogin - check login credentials and set cookie
hash - hash a string with sha256 hash - hash a string with sha256
string - string to hash string - string to hash
help - get help help - get help
update - update the wiki
do - set to `true` to actually update the wiki
secret - set to the value of the site's secret
credits - view the credits credits - view the credits
delete - delete a page delete - delete a page
page - page name page - page name