#!/usr/local/bin/perl # Show server or domain information use strict; use warnings; no warnings 'redefine'; no warnings 'uninitialized'; # The language table of the system status module is read once below no warnings 'once'; # The page is the start page, which the browser opens without a Referer # when the address was typed, as / redirects to it in the single page # layout. A request with a Referer from another site is still refused. our $trust_unknown_referers = 2; require "gray-theme/gray-theme-lib.pl"; require "gray-theme/theme.pl"; &ReadParse(); &load_theme_library(); our ($current_theme, %gconfig, %in); our %text = &load_language($current_theme); # Get system info to show my $sects = get_right_frame_sections(); my @info = &list_combined_system_info($sects, \%in); # Redirect if needed my ($redir) = grep { $_->{'type'} eq 'redirect' } @info; if ($redir) { &redirect($redir->{'url'}); return; } # The body class selects the right frame styles. In the single page layout # this page shows the menu, even though it uses the popup header. our $gray_theme_body_class = 'right-frame'; our $gray_theme_menu_page = 1; &popup_header($text{'left_home'}); # Links from modules become the page actions, with an icon where the # link is a known one my @links = grep { $_->{'type'} eq 'link' } @info; @info = grep { $_->{'type'} ne 'link' } @info; unshift(@links, { 'link' => 'edit_right.cgi', 'desc' => $text{'right_edit'} }); my @actions; foreach my $l (@links) { my $lnk = $l->{'link'}; $lnk = &get_webprefix().$lnk if (&get_webprefix() && $lnk =~ /^\//); my $icon = $lnk =~ /edit_right\.cgi/ ? 'gear' : $lnk =~ /recollect\.cgi/ ? 'refresh' : $lnk =~ /licen[cs]e/ ? 'shield' : $lnk =~ /doc/ ? 'book' : undef; my $target = !$l->{'target'} ? undef : $l->{'target'} eq 'new' ? '_blank' : $l->{'target'} eq 'window' ? '_top' : undef; push(@actions, &ui_tag('a', ($icon ? &ui_svg_icon($icon, { 'size' => 15 }) : ""). &ui_tag('span', $l->{'desc'}), { 'class' => 'ui_link page-action', 'href' => $lnk, 'target' => $target })); } # The system status block supplies the tiles at the top and the line # under the title. Its rows are found by their labels, in the language # of that module. my ($sysinfo) = grep { $_->{'type'} eq 'table' && $_->{'module'} eq 'system-status' && $_->{'id'} eq 'sysinfo' } @info; my @tiles; my @subtitle; if ($sysinfo) { # The tiles take their rows out of the block; the two subtitle rows # are only copied and stay in it my $rows = $sysinfo->{'table'}; my $row = sub { my ($key) = @_; my $label = $system_status::text{$key}; return undef if (!$label); my ($r) = grep { $_->{'desc'} eq $label } @$rows; return $r; }; my $drop = sub { my ($r) = @_; @$rows = grep { $_ ne $r } @$rows if ($r); }; # Operating system and time under the title foreach my $key ('right_os', 'right_time') { my $r = $row->($key); push(@subtitle, $r->{'value'}) if ($r); } # CPU load, shown as the one minute average my $cpu = $row->('right_cpu'); if ($cpu && $cpu->{'value'} =~ /^\s*([\d.]+)\s*(.*)$/) { push(@tiles, &tile($1, $cpu->{'desc'}, $2)); $drop->($cpu); } # Memory and disk, with their bars foreach my $key ('right_real', 'right_disk') { my $r = $row->($key); next if (!$r); my ($value, $rest) = $r->{'value'} =~ /^\s*([\d.]+\s*\S+)\s*(.*)$/ ? ($1, $2) : ($r->{'value'}, ""); $rest =~ s/^\s*used,?\s*//; push(@tiles, &tile($value, $r->{'desc'}, $rest, $r->{'chart'})); $drop->($r); } # Running processes, with the uptime under them my $procs = $row->('right_procs'); if ($procs) { my $up = $row->('right_uptime'); push(@tiles, &tile($procs->{'value'}, $procs->{'desc'}, $up ? $up->{'desc'}." ".$up->{'value'} : "")); $drop->($procs); $drop->($up); } } # The page area, with its title, subtitle and actions print &ui_page_assets({ 'nojs' => 1 }); print &ui_page_start({ 'title' => $text{'left_home'}, 'desc_html' => @subtitle ? join(" · ", @subtitle) : undef, 'actions' => \@actions, 'class' => 'page' }); print &ui_switch_theme_javascript(); # Show notifications first @info = sort { ($b->{'type'} eq 'warning') <=> ($a->{'type'} eq 'warning') } @info; my @notices = grep { $_->{'type'} eq 'warning' } @info; my @blocks = grep { $_->{'type'} ne 'warning' } @info; foreach my $info (@notices) { # A notice, optionally under a heading my $w; if (ref($info->{'warning'}) eq 'HASH') { # Alert HTML supplied by the module $w = $info->{'warning'}->{'alert'}; } else { # Plain text, wrapped in a notice of the given level $w = &ui_alert_box($info->{'warning'}, $info->{'level'} || 'warn'); } if ($info->{'desc'}) { # Inside a card with the block's heading print §ion_start($info, 1); print $w; print §ion_end(); } else { # On its own print $w; } } # The tiles, four across, fewer on a narrow frame if (@tiles) { print &ui_grid(\@tiles, { 'cols' => 4, 'class' => 'tiles' }); } foreach my $info (@blocks) { # A collapsible section my $open = defined($info->{'open'}) ? $info->{'open'} : 1; print §ion_start($info, $open); if ($info->{'header'}) { # Introductory text above the block's content print "
| \n";
print " |