Skip to content

Commit

Permalink
add extra info to /system_info to help debugging #1221
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Sep 30, 2024
1 parent 9d23fca commit 985faa6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
50 changes: 41 additions & 9 deletions ext/et/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public function onPageRequest(PageRequestEvent $event): void
{
global $user;
if ($event->page_matches("system_info", permission: Permissions::VIEW_SYSINFO)) {
$this->theme->display_info_page($this->to_yaml($this->get_info()));
$this->theme->display_info_page(
$this->to_yaml($this->get_site_info()),
$this->to_yaml($this->get_system_info()),
);
}
}

Expand All @@ -44,17 +47,15 @@ public function onCliGen(CliGenEvent $event): void
$event->app->register('info')
->setDescription('List a bunch of info')
->setCode(function (InputInterface $input, OutputInterface $output): int {
print($this->to_yaml($this->get_info()));
print($this->to_yaml($this->get_site_info()));
return Command::SUCCESS;
});
}

/**
* Collect the information and return it in a keyed array.
*
* @return array<string, mixed>
*/
private function get_info(): array
private function get_site_info(): array
{
global $config, $database;

Expand Down Expand Up @@ -139,18 +140,49 @@ private function get_info(): array
return $info;
}

/**
* @return array<string, mixed>
*/
private function get_system_info(): array
{
global $config, $database;

$info = [
"server" => $_SERVER,
"env" => $_ENV,
"get" => $_GET,
"cookie" => $_COOKIE,
// These don't apply to "GET /system_info"
// "post" => $_POST,
// "files" => $_FILES,
// "session" => $_SESSION,
// "request" => $_REQUEST,
"php" => [
"extensions" => get_loaded_extensions(),
],
"php_ini" => ini_get_all(),
];
return $info;
}

/**
* @param array<string, mixed> $info
*/
private function to_yaml(array $info): string
{
$data = "";
foreach ($info as $title => $section) {
$data .= "$title:\n";
foreach ($section as $k => $v) {
$data .= " $k: " . \Safe\json_encode($v, JSON_UNESCAPED_SLASHES) . "\n";
if (!empty($section)) {
$data .= "$title:\n";
foreach ($section as $k => $v) {
try {
$data .= " $k: " . \Safe\json_encode($v, JSON_UNESCAPED_SLASHES) . "\n";
} catch (\Exception $e) {
$data .= " $k: \"(encode error)\"\n";
}
}
$data .= "\n";
}
$data .= "\n";
}
return $data;
}
Expand Down
8 changes: 6 additions & 2 deletions ext/et/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ class ETTheme extends Themelet
/*
* Create a page showing info
*/
public function display_info_page(string $yaml): void
public function display_info_page(string $yaml, string $extra): void
{
global $page;

$page->set_title("System Info");
$page->add_block(new NavBlock());
$page->add_block(new Block("Information:", $this->build_data_form($yaml)));
$page->add_block(new Block("Site Information", $this->build_data_form($yaml)));
$page->add_block(new Block("System Information", TEXTAREA(
["name" => 'data', "style" => "width: 100%; height: 20em;"],
$extra
)));
}

protected function build_data_form(string $yaml): \MicroHTML\HTMLElement
Expand Down

0 comments on commit 985faa6

Please sign in to comment.