From patchwork Sat Sep 9 05:11:41 2017 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: 1417 Return-Path: Received: from mail01.ipfire.org (unknown [172.28.1.200]) by web02.ipfire.org (Postfix) with ESMTP id C060560FFE for ; Fri, 8 Sep 2017 21:11:54 +0200 (CEST) Received: from mail01.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 9EBA82817; Fri, 8 Sep 2017 21:11:53 +0200 (CEST) Received: from mx.link38.eu (mx.link38.eu [188.68.43.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPS id 91B8227D6 for ; Fri, 8 Sep 2017 21:11:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new 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 07AE4410C5 for ; Fri, 8 Sep 2017 21:11:43 +0200 (CEST) Received: from [127.0.0.1] (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 D5C5D9F129 for ; Fri, 8 Sep 2017 21:11:42 +0200 (CEST) Date: Fri, 8 Sep 2017 21:11:41 +0200 From: Peter =?utf-8?q?M=C3=BCller?= To: "development@lists.ipfire.org" Subject: [PATCH] show GeoIP information in WebUI connection list Message-ID: <20170908211141.35e974b8.peter.mueller@link38.eu> Organization: Link38 MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.20 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" Show country flag for source and destination IP addresses at the connection list ("connections.cgi"). This might be useful for debugging geoip based firewall rules and to identify possible harmful connections (i.e. to offshore locations or other countries rarely used). This is another "nice to have" patch (trying to gain experience by adding some simple features I always missed) but could come in handy sometimes. Signed-off-by: Peter Müller diff --git a/html/cgi-bin/connections.cgi b/html/cgi-bin/connections.cgi index 96f09012b..b3348f04a 100644 --- a/html/cgi-bin/connections.cgi +++ b/html/cgi-bin/connections.cgi @@ -23,12 +23,14 @@ use strict; use Net::IPv4Addr qw( :all ); use Switch; +use Geo::IP::PurePerl; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/geoip-functions.pl"; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; @@ -379,6 +382,7 @@ print < +   @@ -386,6 +390,7 @@ print < +   @@ -409,10 +414,16 @@ print < $Lang::tr{'source ip and port'} + + $Lang::tr{'country'} + $Lang::tr{'dest ip and port'} + $Lang::tr{'country'} + + $Lang::tr{'download'} /
$Lang::tr{'upload'} @@ -551,6 +562,12 @@ foreach my $line (@conntrack) { $sip_extra .= ""; } + my $gi1 = Geo::IP::PurePerl->new(); + my $ccode1 = $gi1->country_code_by_name($sip_ret); + my $fcode1 = lc($ccode1); + my $flag_icon1 = &GeoIP::get_flag_icon($fcode1); + + my $dip_extra; if ($dip_ret && $dip ne $dip_ret) { $dip_extra = "> "; @@ -559,6 +576,10 @@ foreach my $line (@conntrack) { $dip_extra .= ""; } + my $gi2 = Geo::IP::PurePerl->new(); + my $ccode2 = $gi2->country_code_by_name($dip_ret); + my $fcode2 = lc($ccode2); + my $flag_icon2 = &GeoIP::get_flag_icon($fcode2); my $sport_extra; if ($sport ne $sport_ret) { @@ -601,6 +622,9 @@ foreach my $line (@conntrack) { $sport_extra + + + $dip @@ -613,6 +637,9 @@ foreach my $line (@conntrack) { $dport_extra + + + $bytes_in / $bytes_out @@ -683,3 +710,4 @@ sub ipcolour($) { } 1; +