Skip to content

Commit

Permalink
Limit Adminer to the PW installation's DB only. Make it possible to u…
Browse files Browse the repository at this point in the history
…ninstall ProcessTracyAdminer and not have it automatically reinstalled. Minor Tracy core updates.
  • Loading branch information
adrianbj committed Nov 14, 2018
1 parent 5314edf commit 93420f0
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 110 deletions.
5 changes: 3 additions & 2 deletions ProcessTracyAdminer.module
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ProcessTracyAdminer extends Process {
error_reporting(0);
ini_set('display_errors', 0);

$_GET['db'] = $this->wire('config')->dbName;

function adminer_object() {

require_once './panels/Adminer/plugins/plugin.php';
Expand All @@ -39,8 +41,7 @@ class ProcessTracyAdminer extends Process {

$plugins = [
new AdminerFrames,
new AdminerDatabaseHide(["mysql", "information_schema", "performance_schema"]),
new AdminerProcessWireLogin(wire('config')->dbHost . $port, wire('config')->dbUser, wire('config')->dbPass, wire('config')->dbName),
new AdminerProcessWireLogin(wire('config')->dbHost . $port, wire('config')->dbName, wire('config')->dbUser, wire('config')->dbPass, wire('config')->dbName),
new AdminerTablesFilter(),
new AdminerSimpleMenu(),
new AdminerCollations(),
Expand Down
8 changes: 1 addition & 7 deletions TracyDebugger.module
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {
'summary' => __('Tracy debugger from Nette with several PW specific custom tools.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/topic/12208-tracy-debugger/',
'version' => '4.14.4',
'version' => '4.14.5',
'autoload' => 9999, // 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 @@ -3440,10 +3440,4 @@ class TracyDebugger extends WireData implements Module, ConfigurableModule {

}

public function ___upgrade($fromVersion, $toVersion) {
if(!$this->wire('modules')->isInstalled('ProcessTracyAdminer')) {
$this->wire('modules')->install('ProcessTracyAdminer');
}
}

}
7 changes: 6 additions & 1 deletion panels/Adminer/plugins/AdminerProcessWireLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

class AdminerProcessWireLogin {

public function __construct($server = false, $name = false, $pass = false) {
public function __construct($server = false, $db = false, $name = false, $pass = false) {
$this->server = $server;
$this->db = $db;
$this->name = $name;
$this->pass = $pass;
}
Expand All @@ -19,5 +20,9 @@ function login() {
return true;
}

function databases($flush = true) {
return [$this->db];
}

}

29 changes: 0 additions & 29 deletions panels/Adminer/plugins/database-hide.php

This file was deleted.

15 changes: 12 additions & 3 deletions panels/AdminerPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ public function getPanel() {
$adminerUrl = $this->wire('pages')->get("process=$adminerModuleId")->url;

$out = '
<h1>' . $this->icon . ' Adminer</h1><span class="tracy-icons"><span class="resizeIcons"><a href="#" title="Maximize / Restore" onclick="tracyResizePanel(\'AdminerPanel\')">+</a></span></span>
<div class="tracy-inner" style="padding: 0 !important">
<iframe src="'.$adminerUrl.'?db='.$this->wire('config')->dbName.'" style="width:100%; height:calc(100% - 5px); border: none; padding:0; margin:0;"></iframe>';
<h1>' . $this->icon . ' Adminer</h1><span class="tracy-icons"><span class="resizeIcons"><a href="#" title="Maximize / Restore" onclick="tracyResizePanel(\'AdminerPanel\')">+</a></span></span>';

if($this->wire('modules')->isInstalled("ProcessTracyAdminer")) {
$out .= '
<div class="tracy-inner" style="padding: 0 !important">
<iframe src="'.$adminerUrl.'" style="width:100%; height:calc(100% - 5px); border: none; padding:0; margin:0;"></iframe>';
}
else {
$out .= '
<div class="tracy-inner">
<p>This panel is not available because the ProcessTracyAdminer module has not been installed.</p>';
}

$out .= '<div style="padding-left:5px">'.\TracyDebugger::generatePanelFooter('adminer', \Tracy\Debugger::timer('adminer'), strlen($out), 'adminerPanel').'</div>';
$out .= '
Expand Down
2 changes: 1 addition & 1 deletion tracy-master/examples/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

?>
<!DOCTYPE html><html class=arrow><link rel="stylesheet" href="assets/style.css">
<base href="/test">

<h1>Tracy: AJAX demo</h1>

<p>
Expand Down
152 changes: 90 additions & 62 deletions tracy-master/src/Bridges/Nette/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,71 +22,99 @@ class Bridge
public static function initialize()
{
$blueScreen = Tracy\Debugger::getBlueScreen();
$blueScreen->addPanel([self::class, 'renderLatteError']);
$blueScreen->addAction([self::class, 'renderLatteUnknownMacro']);
$blueScreen->addAction([self::class, 'renderMemberAccessException']);
$blueScreen->addPanel([self::class, 'renderNeonError']);
}


public static function renderLatteError($e)
{
if (!$e instanceof Latte\CompileException) {
return null;
}
return [
'tab' => 'Template',
'panel' => (preg_match('#\n|\?#', $e->sourceName)
? ''
: '<p>'
. (@is_file($e->sourceName) // @ - may trigger error
? '<b>File:</b> ' . Helpers::editorLink($e->sourceName, $e->sourceLine)
: '<b>' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '</b>')
. '</p>')
. '<pre class=code><div>'
. BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
. '</div></pre>',
];
}


public static function renderLatteUnknownMacro($e)
{
if (
$e instanceof Latte\CompileException
&& @is_file($e->sourceName) // @ - may trigger error
&& (preg_match('#Unknown macro (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m)
|| preg_match('#Unknown attribute (n:\w+), did you mean (n:\w+)\?#A', $e->getMessage(), $m))
) {
return [
'link' => Helpers::editorUri($e->sourceName, $e->sourceLine, 'fix', $m[1], $m[2]),
'label' => 'fix it',
];
}
return null;
}


public static function renderMemberAccessException($e)
{
if (!$e instanceof Nette\MemberAccessException && !$e instanceof \LogicException) {
return null;
}
$loc = $e instanceof Nette\MemberAccessException ? $e->getTrace()[1] : $e->getTrace()[0];
if (preg_match('#Cannot (?:read|write to) an undeclared property .+::\$(\w+), did you mean \$(\w+)\?#A', $e->getMessage(), $m)) {
return [
'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', '->' . $m[1], '->' . $m[2]),
'label' => 'fix it',
];
} elseif (preg_match('#Call to undefined (static )?method .+::(\w+)\(\), did you mean (\w+)\(\)?#A', $e->getMessage(), $m)) {
$operator = $m[1] ? '::' : '->';
return [
'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', $operator . $m[2] . '(', $operator . $m[3] . '('),
'label' => 'fix it',
];
}
return null;
}

$blueScreen->addPanel(function ($e) {
if ($e instanceof Latte\CompileException) {
return [
'tab' => 'Template',
'panel' => (preg_match('#\n|\?#', $e->sourceName)
? ''
: '<p>'
. (@is_file($e->sourceName) // @ - may trigger error
? '<b>File:</b> ' . Helpers::editorLink($e->sourceName, $e->sourceLine)
: '<b>' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '</b>')
. '</p>')
. '<pre class=code><div>'
. BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
. '</div></pre>',
];
}
});

$blueScreen->addAction(function ($e) {
if (
$e instanceof Latte\CompileException
&& @is_file($e->sourceName) // @ - may trigger error
&& (preg_match('#Unknown macro (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m)
|| preg_match('#Unknown attribute (n:\w+), did you mean (n:\w+)\?#A', $e->getMessage(), $m))
) {
return [
'link' => Helpers::editorUri($e->sourceName, $e->sourceLine, 'fix', $m[1], $m[2]),
'label' => 'fix it',
];
}
});
public static function renderNeonError($e)
{
if (
$e instanceof Nette\Neon\Exception
&& preg_match('#line (\d+)#', $e->getMessage(), $m)
&& ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode'))
) {
return [
'tab' => 'NEON',
'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load'))
? '<p><b>File:</b> ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '</p>'
. self::highlightNeon(file_get_contents($trace2['args'][0]), $m[1])
: self::highlightNeon($trace['args'][0], (int) $m[1]),
];
}
return null;
}

$blueScreen->addAction(function ($e) {
if ($e instanceof Nette\MemberAccessException || $e instanceof \LogicException) {
$loc = $e instanceof Nette\MemberAccessException ? $e->getTrace()[1] : $e->getTrace()[0];
if (preg_match('#Cannot (?:read|write to) an undeclared property .+::\$(\w+), did you mean \$(\w+)\?#A', $e->getMessage(), $m)) { // @ - may trigger error
return [
'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', '->' . $m[1], '->' . $m[2]),
'label' => 'fix it',
];
} elseif (preg_match('#Call to undefined (static )?method .+::(\w+)\(\), did you mean (\w+)\(\)?#A', $e->getMessage(), $m)) { // @ - may trigger error
$operator = $m[1] ? '::' : '->';
return [
'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', $operator . $m[2] . '(', $operator . $m[3] . '('),
'label' => 'fix it',
];
}
}
});

$blueScreen->addPanel(function ($e) {
if (
$e instanceof Nette\Neon\Exception
&& preg_match('#line (\d+)#', $e->getMessage(), $m)
&& ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode'))
) {
return [
'tab' => 'NEON',
'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load'))
? '<p><b>File:</b> ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '</p>'
. BlueScreen::highlightFile($trace2['args'][0], $m[1])
: BlueScreen::highlightPhp($trace['args'][0], $m[1]),
];
}
});
private static function highlightNeon($code, $line)
{
$code = htmlspecialchars($code, ENT_IGNORE, 'UTF-8');
$code = str_replace(' ', "<span class='tracy-dump-whitespace'>·</span>", $code);
$code = str_replace("\t", "<span class='tracy-dump-whitespace'>→ </span>", $code);
return '<pre class=code><div>'
. BlueScreen::highlightLine($code, $line)
. '</div></pre>';
}
}
10 changes: 6 additions & 4 deletions tracy-master/src/Bridges/Nette/TracyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)

if ($this->debugMode) {
foreach ((array) $this->config['bar'] as $item) {
if (is_string($item) && substr($item, 0, 1) === '@') {
$item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]);
} elseif (is_string($item)) {
$item = new Nette\DI\Statement($item);
}
$initialize->addBody($builder->formatPhp(
'$this->getService(?)->addPanel(?);',
$class::filterArguments([
$this->prefix('bar'),
is_string($item) ? new Nette\DI\Statement($item) : $item,
])
$class::filterArguments([$this->prefix('bar'), $item])
));
}

Expand Down
2 changes: 1 addition & 1 deletion tracy-master/src/Tracy/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class Debugger
{
const VERSION = '2.5.3';
const VERSION = '2.5.4';

/** server modes for Debugger::enable() */
const
Expand Down
4 changes: 4 additions & 0 deletions tracy-master/src/Tracy/assets/BlueScreen/bluescreen.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ html.tracy-js #tracy-bs .tracy-toggle.tracy-collapsed {
color: #090;
}

#tracy-bs .tracy-dump-whitespace {
color: #0003;
}

#tracy-bs .tracy-dump-null,
#tracy-bs .tracy-dump-bool {
color: #850;
Expand Down

0 comments on commit 93420f0

Please sign in to comment.