From: Peter Müller Date: Sat, 20 Jan 2018 17:24:31 +0000 (+0100) Subject: display active logins at remote.cgi X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9159bd4bbe8bf51d7d604daa7c60651a979da90e;p=people%2Fmfischer%2Fipfire-2.x.git display active logins at remote.cgi Display active user logins (both local and remote) at the remote.cgi page in the WebUI. This might be useful for debugging broken SSH sessions or simply checking that nobody is currently logged in. :-) Signed-off-by: Peter Müller Signed-off-by: Michael Tremer --- diff --git a/html/cgi-bin/remote.cgi b/html/cgi-bin/remote.cgi index 10a3e87cc0..5acce4e997 100644 --- a/html/cgi-bin/remote.cgi +++ b/html/cgi-bin/remote.cgi @@ -25,15 +25,23 @@ use strict; #use warnings; #use CGI::Carp 'fatalsToBrowser'; +use IO::Socket; + require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/geoip-functions.pl"; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; +my %color = (); +my %mainsettings = (); my %remotesettings=(); my %checked=(); my $errormessage=''; my $counter = 0; +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); + &Header::showhttpheaders(); $remotesettings{'ENABLE_SSH'} = 'off'; @@ -187,6 +195,38 @@ print "\n"; &Header::closebox(); +&Header::openbox('100%', 'center', $Lang::tr{'ssh active sesstions'}); + +print < + + + + $Lang::tr{'ssh username'} + + + $Lang::tr{'ssh login time'} + + + $Lang::tr{'ip address'} + + + $Lang::tr{'country'} + + + $Lang::tr{'rdns'} + + + + +END + +&printactivelogins(); + +print "\n\n"; + +&Header::closebox(); + &Header::closebigbox(); &Header::closepage(); @@ -205,3 +245,54 @@ sub viewkey print "$key ($name)$fingerprint$keysize\n"; } } + +sub printactivelogins() +{ + # print active SSH logins (grep outpout of "who -s") + my $command = "who -s"; + my @output = `$command`; + chomp(@output); + + my $id = 0; + + if ( scalar(@output) == 0 ) + { + # no logins appeared + my $table_colour = ($id++ % 2) ? $color{'color22'} : $color{'color20'}; + print "$Lang::tr{'ssh no active logins'}\n"; + } else { + # list active logins... + + foreach my $line (@output) + { + my @arry = split(/\ +/, $line); + + my $username = @arry[0]; + my $logintime = join(' ', @arry[2..4]); + my $remoteip = @arry[5]; + $remoteip =~ s/[()]//g; + + # display more information about that IP adress... + my $ccode = &GeoIP::lookup($remoteip); + my $flag_icon = &GeoIP::get_flag_icon($ccode); + + # get rDNS... + my $iaddr = inet_aton($remoteip); + my $rdns = gethostbyaddr($iaddr, AF_INET); + if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }; + + my $table_colour = ($id++ % 2) ? $color{'color22'} : $color{'color20'}; + + print < + $username + $logintime + $remoteip + $ccode + $rdns + +END +; + } + } +}