Skip to content

Commit

Permalink
Add "Keys to Hide" config option.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbj committed Dec 31, 2024
1 parent 975ba75 commit 99143dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion TracyDebugger.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function getModuleInfo() {
'summary' => __('Tracy debugger from Nette with many PW specific custom tools.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/forum/58-tracy-debugger/',
'version' => '4.26.46',
'version' => '4.26.47',
'autoload' => 100000, // in PW 3.0.114+ higher numbers are loaded first - we want Tracy first
'singular' => true,
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',
Expand Down Expand Up @@ -216,6 +216,7 @@ static public function getDefaultData() {
"forceScream" => null,
"outputMode" => 'detect',
"showLocation" => array('Tracy\Dumper::LOCATION_SOURCE', 'Tracy\Dumper::LOCATION_LINK', 'Tracy\Dumper::LOCATION_CLASS'),
"keysToHide" => 'dbPass, dbName, dbUser, user, username, pass, password, pwd, pw, auth, token, secret',
"logSeverity" => array(),
"excludedPwLogFiles" => array('session', 'modules', 'file-compiler'),
"excludedTracyLogFiles" => array(),
Expand Down Expand Up @@ -950,6 +951,9 @@ public function init() {
Debugger::$showLocation = array_reduce($locations, function($a, $b) { return $a | $b; }, 0);


Debugger::$keysToHide = array_map('trim', explode(',', $this->data['keysToHide']));


// START ENABLING TRACY
// now that required classes above have been loaded, we can now exit if user is not allowed
if(!static::$allowedTracyUser) return;
Expand Down Expand Up @@ -3458,6 +3462,14 @@ public function getModuleConfigInputfields(array $data) {
$f->attr('checked', $data['debugInfo'] == '1' ? 'checked' : '');
$fieldset->add($f);

$f = $this->wire('modules')->get("InputfieldText");
$f->attr('name', 'keysToHide');
$f->label = __('Keys to hide', __FILE__);
$f->description = __('Keys to redact in dumps and bluescreens.', __FILE__);
$f->notes = __('Enter keys separated by commas.'."\nDefault: ".self::getDefaultData()['keysToHide'], __FILE__);
if($data['keysToHide']) $f->attr('value', $data['keysToHide']);
$fieldset->add($f);

$f = $this->wire('modules')->get("InputfieldInteger");
$f->attr('name', 'maxDepth');
$f->label = __('Maximum nesting depth', __FILE__);
Expand Down
5 changes: 5 additions & 0 deletions includes/TD.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static function barDump($var, $title = NULL, $options = []) {
$options[Dumper::TRUNCATE] = isset($options['maxLength']) ? $options['maxLength'] : \TracyDebugger::getDataValue('maxLength');
if(defined('\Tracy\Dumper::ITEMS')) $options[Dumper::ITEMS] = isset($options['maxItems']) ? $options['maxItems'] : \TracyDebugger::getDataValue('maxItems');
$options[Dumper::LOCATION] = Debugger::$showLocation;
$options[Dumper::KEYS_TO_HIDE] = Debugger::$keysToHide;
if(version_compare(Debugger::VERSION, '2.6.0', '>=')) $options[Dumper::LAZY] = true;
static::dumpToBar($var, $title, $options);
}
Expand All @@ -100,6 +101,7 @@ public static function barDumpBig($var, $title = NULL, $options = []) {
$options[Dumper::TRUNCATE] = 9999;
if(defined('\Tracy\Dumper::ITEMS')) $options[Dumper::ITEMS] = 250;
$options[Dumper::LOCATION] = Debugger::$showLocation;
$options[Dumper::KEYS_TO_HIDE] = Debugger::$keysToHide;
if(version_compare(Debugger::VERSION, '2.6.0', '>=')) $options[Dumper::LAZY] = true;
static::dumpToBar($var, $title, $options);
}
Expand Down Expand Up @@ -138,6 +140,7 @@ public static function dump($var, $title = NULL, $options = []) {
$options[Dumper::ITEMS] = isset($options['maxItems']) ? $options['maxItems'] : \TracyDebugger::getDataValue('maxItems');
}
$options[Dumper::LOCATION] = \TracyDebugger::$fromConsole ? false : Debugger::$showLocation;
$options[Dumper::KEYS_TO_HIDE] = Debugger::$keysToHide;
if(version_compare(Debugger::VERSION, '2.6.0', '>=')) $options[Dumper::LAZY] = false;
echo '
<div class="tracy-inner" style="height:auto !important">
Expand Down Expand Up @@ -181,6 +184,7 @@ public static function dumpBig($var, $title = NULL, $options = []) {
$options[Dumper::TRUNCATE] = 9999;
if(defined('\Tracy\Dumper::ITEMS')) $options[Dumper::ITEMS] = 250;
$options[Dumper::LOCATION] = \TracyDebugger::$fromConsole ? false : Debugger::$showLocation;
$options[Dumper::KEYS_TO_HIDE] = Debugger::$keysToHide;
if(version_compare(Debugger::VERSION, '2.6.0', '>=')) $options[Dumper::LAZY] = false;
echo '
<div class="tracy-inner" style="height:auto !important">
Expand All @@ -205,6 +209,7 @@ private static function dumpToBar($var, $title = NULL, $options = [], $echo = fa
if((self::tracyUnavailable() && \TracyDebugger::getDataValue('recordGuestDumps')) || (isset(\TracyDebugger::$showPanels) && in_array('dumpsRecorder', \TracyDebugger::$showPanels))) {
$dumpsFile = wire('config')->paths->cache . 'TracyDebugger/dumps.json';
$dumpsRecorderItems = file_exists($dumpsFile) ? json_decode(file_get_contents($dumpsFile), true) : array();
if(!$dumpsRecorderItems) $dumpsRecorderItems = array();
array_push($dumpsRecorderItems, $dumpItem);
wire('files')->filePutContents($dumpsFile, json_encode($dumpsRecorderItems));
}
Expand Down

0 comments on commit 99143dc

Please sign in to comment.