From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter =?utf-8?q?M=C3=BCller?= To: development@lists.ipfire.org Subject: [PATCH 1/2] display active logins at remote.cgi Date: Sat, 20 Jan 2018 18:24:31 +0100 Message-ID: <20180120182431.239a7317.peter.mueller@link38.eu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4373242572867538135==" List-Id: --===============4373242572867538135== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=BCller --- html/cgi-bin/remote.cgi | 91 +++++++++++++++++++++++++++++++++++++++++++++++= ++ 1 file changed, 91 insertions(+) diff --git a/html/cgi-bin/remote.cgi b/html/cgi-bin/remote.cgi index 10a3e87cc..5acce4e99 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'; =20 +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"; =20 +my %color =3D (); +my %mainsettings =3D (); my %remotesettings=3D(); my %checked=3D(); my $errormessage=3D''; my $counter =3D 0; =20 +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/i= nclude/colors.txt", \%color); + &Header::showhttpheaders(); =20 $remotesettings{'ENABLE_SSH'} =3D 'off'; @@ -187,6 +195,38 @@ print "\n"; =20 &Header::closebox(); =20 +&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(); =20 &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 =3D "who -s"; + my @output =3D `$command`; + chomp(@output); + + my $id =3D 0; + + if ( scalar(@output) =3D=3D 0 ) + { + # no logins appeared + my $table_colour =3D ($id++ % 2) ? $color{'color22'} : $color{'color20'}; + print "$Lang::tr{'ssh no a= ctive logins'}\n"; + } else { + # list active logins... + + foreach my $line (@output) + { + my @arry =3D split(/\ +/, $line); + + my $username =3D @arry[0]; + my $logintime =3D join(' ', @arry[2..4]); + my $remoteip =3D @arry[5]; + $remoteip =3D~ s/[()]//g; + + # display more information about that IP adress... + my $ccode =3D &GeoIP::lookup($remoteip); + my $flag_icon =3D &GeoIP::get_flag_icon($ccode); + + # get rDNS... + my $iaddr =3D inet_aton($remoteip); + my $rdns =3D gethostbyaddr($iaddr, AF_INET); + if (!$rdns) { $rdns =3D $Lang::tr{'lookup failed'}; }; + + my $table_colour =3D ($id++ % 2) ? $color{'color22'} : $color{'color20'}; + + print < + $username + $logintime + $remoteip + 3D'$ccode' + $rdns + +END +; + } + } +} --=20 2.13.6 --===============4373242572867538135==--