From d069c490aef5781cbf3c2058b55ce30556121e75 Mon Sep 17 00:00:00 2001 From: shuki Date: Thu, 5 Mar 2026 03:40:45 +0200 Subject: [PATCH] Add Status column (Success/Warning/Error) to WHM logs list Scans each log file for [ERROR] and [WARN] markers and displays a color-coded badge in the logs table. Co-Authored-By: Claude Opus 4.6 --- whm/gniza-whm/logs.cgi | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/whm/gniza-whm/logs.cgi b/whm/gniza-whm/logs.cgi index 5dd5198..edf2d68 100755 --- a/whm/gniza-whm/logs.cgi +++ b/whm/gniza-whm/logs.cgi @@ -56,11 +56,13 @@ sub show_list { my $path = "$log_dir/$entry"; next unless -f $path; my @stat = stat($path); + my $status = _detect_log_status($path); push @files, { - name => $entry, - size => $stat[7] // 0, - mtime => $stat[9] // 0, - type => ($entry =~ /^cron-/) ? 'Cron' : 'Backup', + name => $entry, + size => $stat[7] // 0, + mtime => $stat[9] // 0, + type => ($entry =~ /^cron-/) ? 'Cron' : 'Backup', + status => $status, }; } closedir $dh; @@ -89,7 +91,7 @@ sub show_list { print qq{
\n}; print qq{\n}; - print qq{\n}; + print qq{\n}; print qq{\n}; for my $f (@page_files) { @@ -102,6 +104,10 @@ sub show_list { print qq{\n}; print qq{ \n}; print qq{ \n}; + my $status_badge = $f->{status} eq 'Error' ? 'badge-error' + : $f->{status} eq 'Warning' ? 'badge-warning' + : 'badge-success'; + print qq{ \n}; print qq{ \n}; print qq{ \n}; print qq{ \n}; @@ -315,6 +321,23 @@ sub _valid_log_filename { return 0; } +sub _detect_log_status { + my ($path) = @_; + return 'Success' unless -f $path; + my $has_warn = 0; + if (open my $fh, '<', $path) { + while (my $line = <$fh>) { + if ($line =~ /\[ERROR\]/) { + close $fh; + return 'Error'; + } + $has_warn = 1 if !$has_warn && $line =~ /\[WARN\]/; + } + close $fh; + } + return $has_warn ? 'Warning' : 'Success'; +} + sub _uri_escape { my $str = shift // ''; $str =~ s/([^A-Za-z0-9\-._~])/sprintf("%%%02X", ord($1))/ge;
FilenameTypeDateSize
FilenameTypeStatusDateSize
$esc_name$f->{type}$f->{status}$date$size