Fix to use hash for mapping since select names

This commit is contained in:
Ilia Ross
2024-05-29 15:35:41 +03:00
parent 6f37dc94bf
commit a420c7142f
2 changed files with 24 additions and 19 deletions

View File

@@ -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])

View File

@@ -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&nbsp; " .
&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 {