make sysinfo part of core, and use YAML for easier parsing

This commit is contained in:
Shish 2020-03-26 16:45:48 +00:00
parent 06e5b02874
commit ecbf4f52a0
3 changed files with 84 additions and 94 deletions

View file

@ -9,6 +9,7 @@ class ETInfo extends ExtensionInfo
public $url = self::SHIMMIE_URL; public $url = self::SHIMMIE_URL;
public $authors = self::SHISH_AUTHOR; public $authors = self::SHISH_AUTHOR;
public $license = self::LICENSE_GPLV2; public $license = self::LICENSE_GPLV2;
public $core = true;
public $description = "Show various bits of system information"; public $description = "Show various bits of system information";
public $documentation = public $documentation =
"Knowing the information that this extension shows can be very useful for debugging. There's also an option to send "Knowing the information that this extension shows can be very useful for debugging. There's also an option to send

View file

@ -10,7 +10,7 @@ class ET extends Extension
global $user; global $user;
if ($event->page_matches("system_info")) { if ($event->page_matches("system_info")) {
if ($user->can(Permissions::VIEW_SYSINTO)) { if ($user->can(Permissions::VIEW_SYSINTO)) {
$this->theme->display_info_page($this->get_info()); $this->theme->display_info_page($this->to_yaml($this->get_info()));
} }
} }
} }
@ -29,7 +29,7 @@ class ET extends Extension
{ {
global $user; global $user;
if ($user->can(Permissions::VIEW_SYSINTO)) { if ($user->can(Permissions::VIEW_SYSINTO)) {
$event->add_link("System Info", make_link("system_info")); $event->add_link("System Info", make_link("system_info"), 99);
} }
} }
@ -40,9 +40,7 @@ class ET extends Extension
print "\t\tList a bunch of info\n\n"; print "\t\tList a bunch of info\n\n";
} }
if ($event->cmd == "info") { if ($event->cmd == "info") {
foreach ($this->get_info() as $k => $v) { print($this->to_yaml($this->get_info()));
print("$k = $v\n");
}
} }
} }
@ -53,51 +51,66 @@ class ET extends Extension
{ {
global $config, $database; global $config, $database;
$info = []; $core_exts = ExtensionInfo::get_core_extensions();
$info['site_title'] = $config->get_string(SetupConfig::TITLE); $extra_exts = [];
$info['site_theme'] = $config->get_string(SetupConfig::THEME); foreach (ExtensionInfo::get_all() as $info) {
$info['site_url'] = "http://" . $_SERVER["HTTP_HOST"] . get_base_href(); if ($info->is_enabled() && !in_array($info->key, $core_exts)) {
$extra_exts[] = $info->key;
$info['sys_shimmie'] = VERSION; }
$info['sys_schema'] = $config->get_int("db_version");
$info['sys_php'] = phpversion();
$info['sys_db'] = $database->get_driver_name();
$info['sys_os'] = php_uname();
$info['sys_disk'] = to_shorthand_int((int)disk_total_space("./") - (int)disk_free_space("./")) . " / " .
to_shorthand_int((int)disk_total_space("./"));
$info['sys_server'] = isset($_SERVER["SERVER_SOFTWARE"]) ? $_SERVER["SERVER_SOFTWARE"] : 'unknown';
$info[MediaConfig::FFMPEG_PATH] = $config->get_string(MediaConfig::FFMPEG_PATH);
$info[MediaConfig::CONVERT_PATH] = $config->get_string(MediaConfig::CONVERT_PATH);
$info[MediaConfig::MEM_LIMIT] = $config->get_int(MediaConfig::MEM_LIMIT);
$info[ImageConfig::THUMB_ENGINE] = $config->get_string(ImageConfig::THUMB_ENGINE);
$info[ImageConfig::THUMB_QUALITY] = $config->get_int(ImageConfig::THUMB_QUALITY);
$info[ImageConfig::THUMB_WIDTH] = $config->get_int(ImageConfig::THUMB_WIDTH);
$info[ImageConfig::THUMB_HEIGHT] = $config->get_int(ImageConfig::THUMB_HEIGHT);
$info[ImageConfig::THUMB_SCALING] = $config->get_int(ImageConfig::THUMB_SCALING);
$info[ImageConfig::THUMB_TYPE] = $config->get_string(ImageConfig::THUMB_TYPE);
$info['stat_images'] = $database->get_one("SELECT COUNT(*) FROM images");
$info['stat_comments'] = $database->get_one("SELECT COUNT(*) FROM comments");
$info['stat_users'] = $database->get_one("SELECT COUNT(*) FROM users");
$info['stat_tags'] = $database->get_one("SELECT COUNT(*) FROM tags");
$info['stat_image_tags'] = $database->get_one("SELECT COUNT(*) FROM image_tags");
$els = [];
foreach (getSubclassesOf("Extension") as $class) {
$els[] = $class;
} }
$info['sys_extensions'] = join(', ', $els);
$info['handled_extensions'] = join(', ', DataHandlerExtension::get_all_supported_exts()); $info = [
"about" => [
//$cfs = array(); 'title' => $config->get_string(SetupConfig::TITLE),
//foreach($database->get_all("SELECT name, value FROM config") as $pair) { 'theme' => $config->get_string(SetupConfig::THEME),
// $cfs[] = $pair['name']."=".$pair['value']; 'url' => "http://" . $_SERVER["HTTP_HOST"] . get_base_href(),
//} ],
//$info[''] = "Config: ".join(", ", $cfs); "versions" => [
'shimmie' => VERSION,
'schema' => $config->get_int("db_version"),
'php' => phpversion(),
'db' => $database->get_driver_name(),
'os' => php_uname(),
'server' => isset($_SERVER["SERVER_SOFTWARE"]) ? $_SERVER["SERVER_SOFTWARE"] : 'unknown',
],
"extensions" => [
"core" => $core_exts,
"extra" => $extra_exts,
"handled_extensions" => DataHandlerExtension::get_all_supported_exts(),
],
"stats" => [
'images' => (int)$database->get_one("SELECT COUNT(*) FROM images"),
'comments' => (int)$database->get_one("SELECT COUNT(*) FROM comments"),
'users' => (int)$database->get_one("SELECT COUNT(*) FROM users"),
],
"media" => [
"memory_limit" => to_shorthand_int($config->get_int(MediaConfig::MEM_LIMIT)),
"disk_use" => to_shorthand_int((int)disk_total_space("./") - (int)disk_free_space("./")),
"disk_total" => to_shorthand_int((int)disk_total_space("./")),
],
"thumbnails" => [
"engine" => $config->get_string(ImageConfig::THUMB_ENGINE),
"quality" => $config->get_int(ImageConfig::THUMB_QUALITY),
"width" => $config->get_int(ImageConfig::THUMB_WIDTH),
"height" => $config->get_int(ImageConfig::THUMB_HEIGHT),
"scaling" => $config->get_int(ImageConfig::THUMB_SCALING),
"type" => $config->get_string(ImageConfig::THUMB_TYPE),
],
];
return $info; return $info;
} }
private function to_yaml($info)
{
$data = "";
foreach ($info as $title => $section) {
$data .= "$title:\n";
foreach ($section as $k => $v) {
$data .= " $k: " . json_encode($v, JSON_UNESCAPED_SLASHES) . "\n";
}
$data .= "\n";
}
return $data;
}
} }

View file

@ -1,5 +1,10 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use function MicroHTML\FORM;
use function MicroHTML\INPUT;
use function MicroHTML\P;
use function MicroHTML\TEXTAREA;
class ETTheme extends Themelet class ETTheme extends Themelet
{ {
/* /*
@ -7,61 +12,32 @@ class ETTheme extends Themelet
* *
* $info = an array of ($name => $value) * $info = an array of ($name => $value)
*/ */
public function display_info_page($info) public function display_info_page($yaml)
{ {
global $page; global $page;
$page->set_title("System Info"); $page->set_title("System Info");
$page->set_heading("System Info"); $page->set_heading("System Info");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block("Information:", $this->build_data_form($info))); $page->add_block(new Block("Information:", $this->build_data_form($yaml)));
} }
protected function build_data_form($info) protected function build_data_form($yaml)
{ {
$data = <<<EOD return (string)FORM(
Optional: ["action"=>"https://shimmie.shishnet.org/register.php", "method"=>"POST"],
Site title: {$info['site_title']} INPUT(["type"=>"hidden", "name"=>"registration_api", "value"=>"2"]),
Theme: {$info['site_theme']} P(
Genre: [describe your site here] "Your stats are useful so that I know which combinations of ".
URL: {$info['site_url']} "web servers / databases / etc I need to support :)"
),
System stats: P(TEXTAREA(
Shimmie: {$info['sys_shimmie']} ["name"=>'data', "style"=>"width: 100%; height: 20em;"],
Schema: {$info['sys_schema']} $yaml
PHP: {$info['sys_php']} )),
OS: {$info['sys_os']} P(INPUT(
Database: {$info['sys_db']} ["type"=>'submit', "value"=>'Click to send to Shish', "style"=>"width: 100%; padding: 1em;"]
Server: {$info['sys_server']} )),
Disk use: {$info['sys_disk']} );
Media System:
Memory Limit: {$info[MediaConfig::MEM_LIMIT]}
Thumbnail Generation:
Engine: {$info[ImageConfig::THUMB_ENGINE]}
Type: {$info[ImageConfig::THUMB_TYPE]}
Quality: {$info[ImageConfig::THUMB_QUALITY]}
Width: {$info[ImageConfig::THUMB_WIDTH]}
Height: {$info[ImageConfig::THUMB_HEIGHT]}
Scaling: {$info[ImageConfig::THUMB_SCALING]}
Shimmie stats:
Images: {$info['stat_images']}
Comments: {$info['stat_comments']}
Users: {$info['stat_users']}
Tags: {$info['stat_tags']}
Applications: {$info['stat_image_tags']}
Extensions: {$info['sys_extensions']}
EOD;
return <<<EOD
<form action='https://shimmie.shishnet.org/register.php' method='POST'>
<input type='hidden' name='registration_api' value='1'>
<textarea name='data' rows='20' cols='80'>$data</textarea>
<br><input type='submit' value='Click to send to Shish'>
<br>Your stats are useful so that I know which combinations
of web servers / databases / etc I need to support.
</form>
EOD;
} }
} }