From 985faa6e45c5e339a30935a78a64c6cd4ff110e0 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Sep 2024 20:12:23 +0100 Subject: [PATCH] add extra info to /system_info to help debugging #1221 --- ext/et/main.php | 50 +++++++++++++++++++++++++++++++++++++++--------- ext/et/theme.php | 8 ++++++-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/ext/et/main.php b/ext/et/main.php index 94e75266a..a52a72c90 100644 --- a/ext/et/main.php +++ b/ext/et/main.php @@ -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()), + ); } } @@ -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 */ - private function get_info(): array + private function get_site_info(): array { global $config, $database; @@ -139,6 +140,31 @@ private function get_info(): array return $info; } + /** + * @return array + */ + 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 $info */ @@ -146,11 +172,17 @@ 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; } diff --git a/ext/et/theme.php b/ext/et/theme.php index d1c1743de..50031d3b0 100644 --- a/ext/et/theme.php +++ b/ext/et/theme.php @@ -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