From patchwork Sun Jan 21 04:24:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 1623 Return-Path: Received: from mail01.ipfire.org (unknown [172.28.1.200]) by web02.ipfire.org (Postfix) with ESMTP id 742D560329 for ; Sat, 20 Jan 2018 18:24:44 +0100 (CET) Received: from mail01.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 947C24559; Sat, 20 Jan 2018 18:24:43 +0100 (CET) Received: from mx.link38.eu (mx.link38.eu [IPv6:2a03:4000:17:39a::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx.link38.eu", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 0423E4557 for ; Sat, 20 Jan 2018 18:24:39 +0100 (CET) X-Virus-Scanned: ClamAV at mx.link38.eu Received: from mx-fra.brokers.link38.eu (mx-fra.brokers.link38.eu [10.141.75.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx.link38.eu (Postfix) with ESMTPS id 93F0340127 for ; Sat, 20 Jan 2018 18:24:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx-fra.brokers.link38.eu (Postfix) with ESMTPSA id 0486A9F3A8 for ; Sat, 20 Jan 2018 18:24:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=link38.eu; s=201711; t=1516469072; x=1579541072; bh=EuGalPVKkFaOngp/KFBON7NpXeJoERHNoeF4jq51ZrE=; h=Date:From:To:Subject:Message-ID:Content-Type:From:To:Subject:Date: Cc; b=ckm72ptC4HJJU7OGonLkJdmREkYJq3jyoTYHTGBmoyPzMBYYQ9tAB0GaZP7rGCiDc rj722mqfc6V6X/0QDERBIuoiAskv6fHn6d1rLd/KbxZHPJBs7WxfwFKu8IqbVpRRRi ROl7JH9aPslmnDkGJDJt6BVzZMCId+JAqL6/PJc/NISuJ8Djt62VFLB8wd9D3mlB80 6FPDUrIJPqkiU3FUck8GfTQEKxOl2RgpHNioA2pTp+EalFMaMo0AtiS/y59y9Is8Yv fUs3D9cgCJ5mOZEm/J8BQ/32X4s3n0KGQo8Y/BwJYsLJ7Qwwgf/XDyjG7ZrQzL2lam qvXtnWtNxsnaw== Date: Sat, 20 Jan 2018 18:24:31 +0100 From: Peter =?utf-8?q?M=C3=BCller?= To: "development@lists.ipfire.org" Subject: [PATCH 1/2] display active logins at remote.cgi Message-ID: <20180120182431.239a7317.peter.mueller@link38.eu> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" 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 --- 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'; +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 +; + } + } +}