From a420c7142faf66313dcf4e2686cf3969a3bdb820 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 29 May 2024 15:35:41 +0300 Subject: [PATCH] Fix to use hash for mapping since select names --- logviewer/logviewer-lib.pl | 24 ++++++++++++++---------- logviewer/view_log.cgi | 19 ++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/logviewer/logviewer-lib.pl b/logviewer/logviewer-lib.pl index 4bd810c14..89df9dda8 100755 --- a/logviewer/logviewer-lib.pl +++ b/logviewer/logviewer-lib.pl @@ -28,18 +28,22 @@ return 0; } # get_journal_since -# Returns a list of journalctl commands to get logs since various times, -# which should correspond with language strings journal_since0, -# journal_since1, journal_since2, etc. +# Returns a list of journalctl since commands sub get_journal_since { -return - ("", "-f", - "-b", "-S '7 days ago'", - "-S '24 hours ago'", "-S '8 hours ago'", - "-S '1 hour ago'", "-S '30 minutes ago'", - "-S '10 minutes ago'", "-S '3 minutes ago'", - "-S '1 minute ago'"); +return [ + { "" => $text{'journal_since0'} }, + { "-f" => $text{'journal_since1'} }, + { "-b" => $text{'journal_since2'} }, + { "-S '7 days ago'" => $text{'journal_since3'} }, + { "-S '24 hours ago'" => $text{'journal_since4'} }, + { "-S '8 hours ago'" => $text{'journal_since5'} }, + { "-S '1 hour ago'" => $text{'journal_since6'} }, + { "-S '30 minutes ago'" => $text{'journal_since7'} }, + { "-S '10 minutes ago'" => $text{'journal_since8'} }, + { "-S '3 minutes ago'" => $text{'journal_since9'} }, + { "-S '1 minute ago'" => $text{'journal_since10'} }, + ]; } # get_systemctl_cmds([force-select]) diff --git a/logviewer/view_log.cgi b/logviewer/view_log.cgi index 523ff3703..d62280286 100755 --- a/logviewer/view_log.cgi +++ b/logviewer/view_log.cgi @@ -21,7 +21,7 @@ if ($in{'idx'} =~ /^\//) { delete($in{'idx'}); delete($in{'oidx'}); } -my @journal_since = &get_journal_since(); +my $journal_since = &get_journal_since(); if ($in{'idx'} ne '') { # From systemctl commands if ($in{'idx'} =~ /^journal-/) { @@ -41,7 +41,9 @@ if ($in{'idx'} ne '') { $log->{'cmd'} .= " -r"; } # If since is set and allowed, add it to the command - if ($in{'since'} && grep { $_ eq $in{'since'} } @journal_since) { + if ($in{'since'} && + grep { $_ eq $in{'since'} } + map { keys %$_ } @$journal_since) { $log->{'cmd'} .= " $in{'since'}"; } &can_edit_log($log) && $access{'syslog'} || @@ -385,16 +387,15 @@ if (@logfiles && $found) { [ @logfiles ], undef, undef, undef, undef, "onChange='form.submit()' style='max-width: 240px'"); if ($in{'idx'} =~ /^journal-/) { - my $selots; - for (my $i = 0; $i < @journal_since; $i++) { - push(@$selots, [ $journal_since[$i], - $text{'journal_since'.$i} ]); - } my $since_label = $follow ? $text{'journal_sincefollow'} : $text{'journal_since'}; $sel .= "$since_label  " . - &ui_select("since", $in{'since'}, $selots, undef, - undef, undef, undef, "onChange='form.submit()'"); + &ui_select("since", $in{'since'}, + [ map { my ($key) = keys %$_; + [ $key, $_->{$key} ] } + @$journal_since ], + undef, undef, undef, undef, + "onChange='form.submit()'"); } } else {