mirror of
https://github.com/webmin/webmin.git
synced 2026-02-03 14:13:29 +00:00
Fix to bring back support for limit in last command
https://forum.virtualmin.com/t/is-this-process-normal-or-should-i-worry/128835/10?u=ilia
This commit is contained in:
@@ -17,12 +17,13 @@ sub groupfiles_type
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# open_last_command(handle, user)
|
# open_last_command(handle, user, [max])
|
||||||
sub open_last_command
|
sub open_last_command
|
||||||
{
|
{
|
||||||
local ($fh, $user) = @_;
|
my ($fh, $user, $max) = @_;
|
||||||
local $quser = quotemeta($user);
|
my $quser = quotemeta($user);
|
||||||
open($fh, "(last -w $quser || last $quser) |");
|
$max = " -n $max" if ($max);
|
||||||
|
open($fh, "(last -w$max $quser || last$max $quser) |");
|
||||||
}
|
}
|
||||||
|
|
||||||
# read_last_line(handle)
|
# read_last_line(handle)
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ sub groupfiles_type
|
|||||||
return &password_file($config{'gshadow_file'}) ? 2 : 0;
|
return &password_file($config{'gshadow_file'}) ? 2 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# open_last_command(handle, user)
|
# open_last_command(handle, user, [max])
|
||||||
sub open_last_command
|
sub open_last_command
|
||||||
{
|
{
|
||||||
local ($fh, $user) = @_;
|
my ($fh, $user, $max) = @_;
|
||||||
local $quser = quotemeta($user);
|
my $quser = quotemeta($user);
|
||||||
open($fh, "(last -F -w $quser || last -w $quser) |");
|
$max = " -n $max" if ($max);
|
||||||
|
open($fh, "(last -F -w$max $quser || last -w$max $quser) |");
|
||||||
}
|
}
|
||||||
|
|
||||||
# read_last_line(handle)
|
# read_last_line(handle)
|
||||||
|
|||||||
@@ -54,11 +54,12 @@ else {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# open_last_command(handle, user)
|
# open_last_command(handle, user, [max])
|
||||||
sub open_last_command
|
sub open_last_command
|
||||||
{
|
{
|
||||||
local ($fh, $user) = @_;
|
my ($fh, $user, $max) = @_;
|
||||||
open($fh, "last $user |");
|
$max = " -n $max" if ($max);
|
||||||
|
open($fh, "last$max $user |");
|
||||||
}
|
}
|
||||||
|
|
||||||
# read_last_line(handle)
|
# read_last_line(handle)
|
||||||
|
|||||||
@@ -2552,11 +2552,13 @@ Returns a list of array references, each containing the details of a login.
|
|||||||
=cut
|
=cut
|
||||||
sub list_last_logins
|
sub list_last_logins
|
||||||
{
|
{
|
||||||
local @rv;
|
my ($user, $max) = @_;
|
||||||
&open_last_command(LAST, $_[0]);
|
my @rv;
|
||||||
|
undef($max) if (defined($max) && $max <= 0); # sanity check
|
||||||
|
&open_last_command(LAST, $user, $max);
|
||||||
while(@last = &read_last_line(LAST)) {
|
while(@last = &read_last_line(LAST)) {
|
||||||
push(@rv, [ @last ]);
|
push(@rv, [ @last ]);
|
||||||
if ($_[1] && scalar(@rv) >= $_[1]) {
|
if ($max && scalar(@rv) >= $max) {
|
||||||
last; # reached max
|
last; # reached max
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user