1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +00:00
Pepperminty-Wiki/modules/page-debug-info.php

86 lines
3.5 KiB
PHP
Raw Permalink Normal View History

2016-01-23 15:25:36 +00:00
<?php
register_module([
"name" => "Debug Information",
2020-07-08 23:22:27 +00:00
"version" => "0.4",
2016-01-23 15:25:36 +00:00
"author" => "Starbeamrainbowlabs",
"description" => "Adds a debug action for administrator use only that collects a load of useful information to make reporting bugs easier.",
"id" => "page-debug-info",
"code" => function() {
global $settings, $env;
2016-06-13 10:55:40 +00:00
/**
* @api {get} ?action=debug Get a debug dump
* @apiName Debug
* @apiGroup Utility
* @apiPermission Moderator
*
* @apiUse UserNotModeratorError
2019-09-11 19:21:21 +00:00
*
* @apiParam {string} secret Optional. If you're not logged in as a moderator or better, then specifying the secret works as a substitute.
2016-06-13 10:55:40 +00:00
*/
2016-01-23 15:25:36 +00:00
/*
* ██████ ███████ ██████ ██ ██ ██████
* ██ ██ ██ ██ ██ ██ ██ ██
* ██ ██ █████ ██████ ██ ██ ██ ███
* ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██████ ███████ ██████ ██████ ██████
*/
add_action("debug", function() {
global $settings, $env, $paths, $version, $commit;
2016-01-23 15:25:36 +00:00
header("content-type: text/plain");
2020-07-08 23:15:54 +00:00
if(!$env->is_admin && (!isset($_GET["secret"]) && $_GET["secret"] !== $settings->secret)) {
2016-01-23 15:25:36 +00:00
exit("You must be logged in as an moderator in order to generate debugging information.");
}
$title = "$settings->sitename debug report";
echo("$title\n");
echo(str_repeat("=", strlen($title)) . "\n");
echo("Powered by Pepperminty Wiki version $version+" . substr($commit, 0, 7) . ".\n");
2016-01-23 15:25:36 +00:00
echo("This report may contain personal information.\n\n");
echo("Environment: ");
2020-07-08 23:37:02 +00:00
echo(debug_mask_secrets(var_export($env, true)));
2016-01-23 15:25:36 +00:00
echo("\nPaths: ");
2020-07-08 23:37:02 +00:00
echo(var_export($paths, true));
2016-01-23 15:25:36 +00:00
echo("\nServer information:\n");
echo("uname -a: " . php_uname() . "\n");
echo("Path: " . getenv("PATH") . "\n");
echo("Temporary directory: " . sys_get_temp_dir() . "\n");
echo("Server: " . $_SERVER["SERVER_SOFTWARE"] . "\n");
echo("Web root: " . $_SERVER["DOCUMENT_ROOT"] . "\n");
echo("Web server user: " . exec("whoami") . "\n");
echo("PHP version: " . phpversion() . "\n");
echo("index.php location: " . __FILE__ . "\n");
echo("index.php file permissions: " . substr(sprintf('%o', fileperms("./index.php")), -4) . "\n");
echo("Current folder permissions: " . substr(sprintf('%o', fileperms(".")), -4) . "\n");
echo("Storage directory permissions: " . substr(sprintf('%o', fileperms($env->storage_prefix)), -4) . "\n");
echo("Loaded extensions: " . implode(", ", get_loaded_extensions()) . "\n");
echo("Settings:\n-----\n");
2020-07-08 23:37:02 +00:00
echo(debug_mask_secrets(var_export($settings, true)));
2016-01-23 15:25:36 +00:00
echo("\n-----\n");
exit();
});
if($env->is_admin) {
add_help_section("950-debug-information", "Gathering debug information", "<p>As a moderator, $settings->sitename gives you the ability to generate a report on $settings->sitename's installation of Pepperminty Wiki for debugging purposes.</p>
2016-01-23 15:25:36 +00:00
<p>To generate such a report, visit the <code>debug</code> action or <a href='?action=debug'>click here</a>.</p>");
}
}
]);
2020-07-08 23:37:02 +00:00
/**
* Masks secrets in debug output.
* @param string $text The text to mask.
* @return string The masked text.
*/
function debug_mask_secrets($text) {
$lines = explode("\n", $text);
foreach ($lines as &$line) {
if(preg_match("/'(secret|sitesecret|email(?:Address)?|password)'/i", $line)) $line = "********* secret *********";
}
return implode("\n", $lines);
}
2016-01-23 15:25:36 +00:00
?>