Compare commits

...

3 Commits

Author SHA1 Message Date
Ilia Ross
4006b0454e Fix to escape and not to truncate username 2024-06-18 23:51:19 +03:00
Ilia Ross
5d4ab58baa Fix the regex for last command on FreeBSD 2024-06-18 23:50:12 +03:00
Jamie Cameron
e6c7a60fe6 Merge pull request #2200 from webmin/dev/fix-last-command-regexes
Fix the regex to correctly match the output of the `last` command on contemporary systems
2024-06-18 13:38:21 -07:00

View File

@@ -21,7 +21,8 @@ return 0;
sub open_last_command
{
local ($fh, $user) = @_;
open($fh, "last $user |");
local $quser = quotemeta($user);
open($fh, "(last -w $quser || last $quser) |");
}
# read_last_line(handle)
@@ -34,7 +35,9 @@ while(1) {
chop($line = <$fh>);
if (!$line) { return (); }
if ($line =~ /^(reboot|shutdown)/) { next; }
if ($line =~ /^(\S+)\s+(\S+)\s+(\S+)?\s+(\S+\s+\S+\s+\d+\s+\d+:\d+)\s+\-\s+(\S+)\s+\((\d+:\d+)\)/) {
if ($line =~ /^(\S+)\s+(\S+)\s+(\S+)?\s+(\S+\s+\S+\s+\d+\s+\d+:\d+)\s+\-\s+(\S+)\s+\((.*?\d+:\d+.*?)\)/) {
# root pts/0 10.211.55.2 Tue Nov 22 21:06 - 23:16 (02:10:00)
# root pts/1 10.211.55.2 Wed Jun 29 13:13 - shutdown (7+00:01:20)
return ($1, $2, $3, $4, $5 eq "shutdown" ? "Shutdown" :
$5 eq "crash" ? "Crash" : $5, $6);
}