[v2] add GeoIP and rDNS information to used nameservers

Message ID 20171115224900.2422e927.peter.mueller@link38.eu
State Accepted
Headers
Series [v2] add GeoIP and rDNS information to used nameservers |

Commit Message

Peter Müller Nov. 16, 2017, 8:49 a.m. UTC
  Add GeoIP and rDNS information to DNS nameserver list at netexternal.cgi

Use newly implemented GeoIP function in /var/ipfire/geoip-functions.pl

Signed-off-by: Peter Müller <peter.mueller@link38.eu>
---
 html/cgi-bin/netexternal.cgi | 27 ++++++++++++++++++++++++++-
 langs/de/cgi-bin/de.pl       |  1 +
 langs/en/cgi-bin/en.pl       |  1 +
 3 files changed, 28 insertions(+), 1 deletion(-)
  

Comments

Michael Tremer Nov. 16, 2017, 11:52 p.m. UTC | #1
Hi,

On Wed, 2017-11-15 at 22:49 +0100, Peter Müller wrote:
> Add GeoIP and rDNS information to DNS nameserver list at netexternal.cgi
> 
> Use newly implemented GeoIP function in /var/ipfire/geoip-functions.pl
> 
> Signed-off-by: Peter Müller <peter.mueller@link38.eu>
> ---
>  html/cgi-bin/netexternal.cgi | 27 ++++++++++++++++++++++++++-
>  langs/de/cgi-bin/de.pl       |  1 +
>  langs/en/cgi-bin/en.pl       |  1 +
>  3 files changed, 28 insertions(+), 1 deletion(-)
> 
> diff --git a/html/cgi-bin/netexternal.cgi b/html/cgi-bin/netexternal.cgi
> index 299612d4c..4393393e0 100644
> --- a/html/cgi-bin/netexternal.cgi
> +++ b/html/cgi-bin/netexternal.cgi
> @@ -25,9 +25,12 @@ use strict;
>  #use warnings;
>  #use CGI::Carp 'fatalsToBrowser';
>  
> +use IO::Socket;
> +

For what is this module being loaded?

>  require '/var/ipfire/general-functions.pl';
>  require "${General::swroot}/lang.pl";
>  require "${General::swroot}/header.pl";
> +require "${General::swroot}/geoip-functions.pl";
>  require "${General::swroot}/graphs.pl";
>  
>  my %color = ();
> @@ -99,6 +102,12 @@ if ( $querry[0] ne~ ""){
>  						<strong>$Lang::tr{'nameserver
> '}</strong>
>  					</th>
>  					<th align="center">
> +						<strong>$Lang::tr{'country'}<
> /strong>
> +					</th>
> +					<th align="center">
> +						<strong>$Lang::tr{'rdns'}</st
> rong>
> +					</th>
> +					<th align="center">
>  						<strong>$Lang::tr{'status'}</
> strong>
>  					</th>
>  				</tr>
> @@ -139,9 +148,25 @@ END
>  
>  		my $table_colour = ($id++ % 2) ? $color{'color22'} :
> $color{'color20'};
>  
> +		# collect more information about name server (rDNS, GeoIP
> country code)
> +		my $ccode = &GeoIP::lookup($nameserver);
> +		my $flag_icon = &GeoIP::get_flag_icon($ccode);
> +
> +		my $iaddr = inet_aton($nameserver);
> +		my $rdns = gethostbyaddr($iaddr, AF_INET);
> +		if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
> +
>  		print <<END;
>  			<tr bgcolor="$table_colour">
> -				<td>$nameserver</td>
> +				<td>
> +					$nameserver
> +				</td>
> +				<td align="center">
> +					<a href='country.cgi#$ccode'><img
> src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
> +				</td>
> +				<td align="center">
> +					$rdns
> +				</td>
>  				<td bgcolor="$bgcolour" align="center">
>  					<font
> color="$colour"><strong>$message</strong></font>
>  				</td>
> diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
> index 6dff5d781..ae87464d2 100644
> --- a/langs/de/cgi-bin/de.pl
> +++ b/langs/de/cgi-bin/de.pl
> @@ -1962,6 +1962,7 @@
>  'read bytes' => 'Gelesene Bytes',
>  'read list' => 'Liste der Leseberechtigten',
>  'real address' => 'Reale Addresse',
> +'rdns' => 'rDNS',
>  'reboot' => 'Neustart',
>  'reboot ask' => 'Neustart?',
>  'reboot question' => 'Extra Abfrage bei neustart und herunterfahren
> einschalten',
> diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl
> index 4efff6e65..3af17d5dc 100644
> --- a/langs/en/cgi-bin/en.pl
> +++ b/langs/en/cgi-bin/en.pl
> @@ -1997,6 +1997,7 @@
>  'quick playlist' => 'Quick Playlist',
>  'ram' => 'RAM',
>  'random number generator daemon' => 'Random Number Generator Daemon',
> +'rdns' => 'rDNS',
>  'read bytes' => 'Read Bytes',
>  'read list' => 'list with readonly hosts',
>  'real address' => 'Real Address',
  
Peter Müller Nov. 17, 2017, 3:23 a.m. UTC | #2
Hello Michael,

> Hi,
> 
> On Wed, 2017-11-15 at 22:49 +0100, Peter Müller wrote:
> > Add GeoIP and rDNS information to DNS nameserver list at netexternal.cgi
> > 
> > Use newly implemented GeoIP function in /var/ipfire/geoip-functions.pl
> > 
> > Signed-off-by: Peter Müller <peter.mueller@link38.eu>
> > ---
> >  html/cgi-bin/netexternal.cgi | 27 ++++++++++++++++++++++++++-
> >  langs/de/cgi-bin/de.pl       |  1 +
> >  langs/en/cgi-bin/en.pl       |  1 +
> >  3 files changed, 28 insertions(+), 1 deletion(-)
> > 
> > diff --git a/html/cgi-bin/netexternal.cgi b/html/cgi-bin/netexternal.cgi
> > index 299612d4c..4393393e0 100644
> > --- a/html/cgi-bin/netexternal.cgi
> > +++ b/html/cgi-bin/netexternal.cgi
> > @@ -25,9 +25,12 @@ use strict;
> >  #use warnings;
> >  #use CGI::Carp 'fatalsToBrowser';
> >  
> > +use IO::Socket;
> > +  
> 
> For what is this module being loaded?
It is necessary to perform the DNS query. Without it, Perl returns
an error.

Best regards,
Peter Müller
> 
> >  require '/var/ipfire/general-functions.pl';
> >  require "${General::swroot}/lang.pl";
> >  require "${General::swroot}/header.pl";
> > +require "${General::swroot}/geoip-functions.pl";
> >  require "${General::swroot}/graphs.pl";
> >  
> >  my %color = ();
> > @@ -99,6 +102,12 @@ if ( $querry[0] ne~ ""){
> >  						<strong>$Lang::tr{'nameserver
> > '}</strong>
> >  					</th>
> >  					<th align="center">
> > +						<strong>$Lang::tr{'country'}<  
> > /strong>  
> > +					</th>
> > +					<th align="center">
> > +						<strong>$Lang::tr{'rdns'}</st  
> > rong>  
> > +					</th>
> > +					<th align="center">
> >  						<strong>$Lang::tr{'status'}</  
> > strong>  
> >  					</th>
> >  				</tr>
> > @@ -139,9 +148,25 @@ END
> >  
> >  		my $table_colour = ($id++ % 2) ? $color{'color22'} :
> > $color{'color20'};
> >  
> > +		# collect more information about name server (rDNS, GeoIP
> > country code)
> > +		my $ccode = &GeoIP::lookup($nameserver);
> > +		my $flag_icon = &GeoIP::get_flag_icon($ccode);
> > +
> > +		my $iaddr = inet_aton($nameserver);
> > +		my $rdns = gethostbyaddr($iaddr, AF_INET);
> > +		if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
> > +
> >  		print <<END;
> >  			<tr bgcolor="$table_colour">
> > -				<td>$nameserver</td>
> > +				<td>
> > +					$nameserver
> > +				</td>
> > +				<td align="center">
> > +					<a href='country.cgi#$ccode'><img
> > src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
> > +				</td>
> > +				<td align="center">
> > +					$rdns
> > +				</td>
> >  				<td bgcolor="$bgcolour" align="center">
> >  					<font  
> > color="$colour"><strong>$message</strong></font>  
> >  				</td>
> > diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
> > index 6dff5d781..ae87464d2 100644
> > --- a/langs/de/cgi-bin/de.pl
> > +++ b/langs/de/cgi-bin/de.pl
> > @@ -1962,6 +1962,7 @@
> >  'read bytes' => 'Gelesene Bytes',
> >  'read list' => 'Liste der Leseberechtigten',
> >  'real address' => 'Reale Addresse',
> > +'rdns' => 'rDNS',
> >  'reboot' => 'Neustart',
> >  'reboot ask' => 'Neustart?',
> >  'reboot question' => 'Extra Abfrage bei neustart und herunterfahren
> > einschalten',
> > diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl
> > index 4efff6e65..3af17d5dc 100644
> > --- a/langs/en/cgi-bin/en.pl
> > +++ b/langs/en/cgi-bin/en.pl
> > @@ -1997,6 +1997,7 @@
> >  'quick playlist' => 'Quick Playlist',
> >  'ram' => 'RAM',
> >  'random number generator daemon' => 'Random Number Generator Daemon',
> > +'rdns' => 'rDNS',
> >  'read bytes' => 'Read Bytes',
> >  'read list' => 'list with readonly hosts',
> >  'real address' => 'Real Address',
  
Michael Tremer Nov. 21, 2017, 3:03 a.m. UTC | #3
On Thu, 2017-11-16 at 17:23 +0100, Peter Müller wrote:
> Hello Michael,
> 
> > Hi,
> > 
> > On Wed, 2017-11-15 at 22:49 +0100, Peter Müller wrote:
> > > Add GeoIP and rDNS information to DNS nameserver list at netexternal.cgi
> > > 
> > > Use newly implemented GeoIP function in /var/ipfire/geoip-functions.pl
> > > 
> > > Signed-off-by: Peter Müller <peter.mueller@link38.eu>
> > > ---
> > >  html/cgi-bin/netexternal.cgi | 27 ++++++++++++++++++++++++++-
> > >  langs/de/cgi-bin/de.pl       |  1 +
> > >  langs/en/cgi-bin/en.pl       |  1 +
> > >  3 files changed, 28 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/html/cgi-bin/netexternal.cgi b/html/cgi-bin/netexternal.cgi
> > > index 299612d4c..4393393e0 100644
> > > --- a/html/cgi-bin/netexternal.cgi
> > > +++ b/html/cgi-bin/netexternal.cgi
> > > @@ -25,9 +25,12 @@ use strict;
> > >  #use warnings;
> > >  #use CGI::Carp 'fatalsToBrowser';
> > >  
> > > +use IO::Socket;
> > > +  
> > 
> > For what is this module being loaded?
> 
> It is necessary to perform the DNS query. Without it, Perl returns
> an error.

Oh, so inet_aton() is from that package. Would it not be better to call that by
it's full name (IO::Socket::inet_aton)?

-Michael

> 
> Best regards,
> Peter Müller
> > 
> > >  require '/var/ipfire/general-functions.pl';
> > >  require "${General::swroot}/lang.pl";
> > >  require "${General::swroot}/header.pl";
> > > +require "${General::swroot}/geoip-functions.pl";
> > >  require "${General::swroot}/graphs.pl";
> > >  
> > >  my %color = ();
> > > @@ -99,6 +102,12 @@ if ( $querry[0] ne~ ""){
> > >  						<strong>$Lang::tr{'namese
> > > rver
> > > '}</strong>
> > >  					</th>
> > >  					<th align="center">
> > > +						<strong>$Lang::tr{'countr
> > > y'}<  
> > > /strong>  
> > > +					</th>
> > > +					<th align="center">
> > > +						<strong>$Lang::tr{'rdns'}
> > > </st  
> > > rong>  
> > > +					</th>
> > > +					<th align="center">
> > >  						<strong>$Lang::tr{'status
> > > '}</  
> > > strong>  
> > >  					</th>
> > >  				</tr>
> > > @@ -139,9 +148,25 @@ END
> > >  
> > >  		my $table_colour = ($id++ % 2) ? $color{'color22'} :
> > > $color{'color20'};
> > >  
> > > +		# collect more information about name server (rDNS, GeoIP
> > > country code)
> > > +		my $ccode = &GeoIP::lookup($nameserver);
> > > +		my $flag_icon = &GeoIP::get_flag_icon($ccode);
> > > +
> > > +		my $iaddr = inet_aton($nameserver);
> > > +		my $rdns = gethostbyaddr($iaddr, AF_INET);
> > > +		if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
> > > +
> > >  		print <<END;
> > >  			<tr bgcolor="$table_colour">
> > > -				<td>$nameserver</td>
> > > +				<td>
> > > +					$nameserver
> > > +				</td>
> > > +				<td align="center">
> > > +					<a href='country.cgi#$ccode'><img
> > > src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
> > > +				</td>
> > > +				<td align="center">
> > > +					$rdns
> > > +				</td>
> > >  				<td bgcolor="$bgcolour" align="center">
> > >  					<font  
> > > color="$colour"><strong>$message</strong></font>  
> > >  				</td>
> > > diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
> > > index 6dff5d781..ae87464d2 100644
> > > --- a/langs/de/cgi-bin/de.pl
> > > +++ b/langs/de/cgi-bin/de.pl
> > > @@ -1962,6 +1962,7 @@
> > >  'read bytes' => 'Gelesene Bytes',
> > >  'read list' => 'Liste der Leseberechtigten',
> > >  'real address' => 'Reale Addresse',
> > > +'rdns' => 'rDNS',
> > >  'reboot' => 'Neustart',
> > >  'reboot ask' => 'Neustart?',
> > >  'reboot question' => 'Extra Abfrage bei neustart und herunterfahren
> > > einschalten',
> > > diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl
> > > index 4efff6e65..3af17d5dc 100644
> > > --- a/langs/en/cgi-bin/en.pl
> > > +++ b/langs/en/cgi-bin/en.pl
> > > @@ -1997,6 +1997,7 @@
> > >  'quick playlist' => 'Quick Playlist',
> > >  'ram' => 'RAM',
> > >  'random number generator daemon' => 'Random Number Generator Daemon',
> > > +'rdns' => 'rDNS',
> > >  'read bytes' => 'Read Bytes',
> > >  'read list' => 'list with readonly hosts',
> > >  'real address' => 'Real Address',  
> 
>
  
Peter Müller Nov. 21, 2017, 5:15 a.m. UTC | #4
Hello Michael,

> On Thu, 2017-11-16 at 17:23 +0100, Peter Müller wrote:
> > Hello Michael,
> >   
> > > Hi,
> > > 
> > > On Wed, 2017-11-15 at 22:49 +0100, Peter Müller wrote:  
> > > > Add GeoIP and rDNS information to DNS nameserver list at netexternal.cgi
> > > > 
> > > > Use newly implemented GeoIP function in /var/ipfire/geoip-functions.pl
> > > > 
> > > > Signed-off-by: Peter Müller <peter.mueller@link38.eu>
> > > > ---
> > > >  html/cgi-bin/netexternal.cgi | 27 ++++++++++++++++++++++++++-
> > > >  langs/de/cgi-bin/de.pl       |  1 +
> > > >  langs/en/cgi-bin/en.pl       |  1 +
> > > >  3 files changed, 28 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/html/cgi-bin/netexternal.cgi b/html/cgi-bin/netexternal.cgi
> > > > index 299612d4c..4393393e0 100644
> > > > --- a/html/cgi-bin/netexternal.cgi
> > > > +++ b/html/cgi-bin/netexternal.cgi
> > > > @@ -25,9 +25,12 @@ use strict;
> > > >  #use warnings;
> > > >  #use CGI::Carp 'fatalsToBrowser';
> > > >  
> > > > +use IO::Socket;
> > > > +    
> > > 
> > > For what is this module being loaded?  
> > 
> > It is necessary to perform the DNS query. Without it, Perl returns
> > an error.  
> 
> Oh, so inet_aton() is from that package. Would it not be better to call that by
> it's full name (IO::Socket::inet_aton)?
> 
> -Michael
Probably, but since PTR lookups are performed this way in other CGIs
such as ipinfo.cgi, I wanted to stay consistent here.

All other patches of the GeoIP bundle are not affected by this.

Best regards,
Peter Müller
> 
> > 
> > Best regards,
> > Peter Müller  
> > >   
> > > >  require '/var/ipfire/general-functions.pl';
> > > >  require "${General::swroot}/lang.pl";
> > > >  require "${General::swroot}/header.pl";
> > > > +require "${General::swroot}/geoip-functions.pl";
> > > >  require "${General::swroot}/graphs.pl";
> > > >  
> > > >  my %color = ();
> > > > @@ -99,6 +102,12 @@ if ( $querry[0] ne~ ""){
> > > >  						<strong>$Lang::tr{'namese
> > > > rver
> > > > '}</strong>
> > > >  					</th>
> > > >  					<th align="center">
> > > > +						<strong>$Lang::tr{'countr
> > > > y'}<    
> > > > /strong>    
> > > > +					</th>
> > > > +					<th align="center">
> > > > +						<strong>$Lang::tr{'rdns'}
> > > > </st    
> > > > rong>    
> > > > +					</th>
> > > > +					<th align="center">
> > > >  						<strong>$Lang::tr{'status
> > > > '}</    
> > > > strong>    
> > > >  					</th>
> > > >  				</tr>
> > > > @@ -139,9 +148,25 @@ END
> > > >  
> > > >  		my $table_colour = ($id++ % 2) ? $color{'color22'} :
> > > > $color{'color20'};
> > > >  
> > > > +		# collect more information about name server (rDNS, GeoIP
> > > > country code)
> > > > +		my $ccode = &GeoIP::lookup($nameserver);
> > > > +		my $flag_icon = &GeoIP::get_flag_icon($ccode);
> > > > +
> > > > +		my $iaddr = inet_aton($nameserver);
> > > > +		my $rdns = gethostbyaddr($iaddr, AF_INET);
> > > > +		if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
> > > > +
> > > >  		print <<END;
> > > >  			<tr bgcolor="$table_colour">
> > > > -				<td>$nameserver</td>
> > > > +				<td>
> > > > +					$nameserver
> > > > +				</td>
> > > > +				<td align="center">
> > > > +					<a href='country.cgi#$ccode'><img
> > > > src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
> > > > +				</td>
> > > > +				<td align="center">
> > > > +					$rdns
> > > > +				</td>
> > > >  				<td bgcolor="$bgcolour" align="center">
> > > >  					<font    
> > > > color="$colour"><strong>$message</strong></font>    
> > > >  				</td>
> > > > diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
> > > > index 6dff5d781..ae87464d2 100644
> > > > --- a/langs/de/cgi-bin/de.pl
> > > > +++ b/langs/de/cgi-bin/de.pl
> > > > @@ -1962,6 +1962,7 @@
> > > >  'read bytes' => 'Gelesene Bytes',
> > > >  'read list' => 'Liste der Leseberechtigten',
> > > >  'real address' => 'Reale Addresse',
> > > > +'rdns' => 'rDNS',
> > > >  'reboot' => 'Neustart',
> > > >  'reboot ask' => 'Neustart?',
> > > >  'reboot question' => 'Extra Abfrage bei neustart und herunterfahren
> > > > einschalten',
> > > > diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl
> > > > index 4efff6e65..3af17d5dc 100644
> > > > --- a/langs/en/cgi-bin/en.pl
> > > > +++ b/langs/en/cgi-bin/en.pl
> > > > @@ -1997,6 +1997,7 @@
> > > >  'quick playlist' => 'Quick Playlist',
> > > >  'ram' => 'RAM',
> > > >  'random number generator daemon' => 'Random Number Generator Daemon',
> > > > +'rdns' => 'rDNS',
> > > >  'read bytes' => 'Read Bytes',
> > > >  'read list' => 'list with readonly hosts',
> > > >  'real address' => 'Real Address',    
> > 
> >
  

Patch

diff --git a/html/cgi-bin/netexternal.cgi b/html/cgi-bin/netexternal.cgi
index 299612d4c..4393393e0 100644
--- a/html/cgi-bin/netexternal.cgi
+++ b/html/cgi-bin/netexternal.cgi
@@ -25,9 +25,12 @@  use strict;
 #use warnings;
 #use CGI::Carp 'fatalsToBrowser';
 
+use IO::Socket;
+
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
+require "${General::swroot}/geoip-functions.pl";
 require "${General::swroot}/graphs.pl";
 
 my %color = ();
@@ -99,6 +102,12 @@  if ( $querry[0] ne~ ""){
 						<strong>$Lang::tr{'nameserver'}</strong>
 					</th>
 					<th align="center">
+						<strong>$Lang::tr{'country'}</strong>
+					</th>
+					<th align="center">
+						<strong>$Lang::tr{'rdns'}</strong>
+					</th>
+					<th align="center">
 						<strong>$Lang::tr{'status'}</strong>
 					</th>
 				</tr>
@@ -139,9 +148,25 @@  END
 
 		my $table_colour = ($id++ % 2) ? $color{'color22'} : $color{'color20'};
 
+		# collect more information about name server (rDNS, GeoIP country code)
+		my $ccode = &GeoIP::lookup($nameserver);
+		my $flag_icon = &GeoIP::get_flag_icon($ccode);
+
+		my $iaddr = inet_aton($nameserver);
+		my $rdns = gethostbyaddr($iaddr, AF_INET);
+		if (!$rdns) { $rdns = $Lang::tr{'lookup failed'}; }
+
 		print <<END;
 			<tr bgcolor="$table_colour">
-				<td>$nameserver</td>
+				<td>
+					$nameserver
+				</td>
+				<td align="center">
+					<a href='country.cgi#$ccode'><img src="$flag_icon" border="0" alt="$ccode" title="$ccode" /></a>
+				</td>
+				<td align="center">
+					$rdns
+				</td>
 				<td bgcolor="$bgcolour" align="center">
 					<font color="$colour"><strong>$message</strong></font>
 				</td>
diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl
index 6dff5d781..ae87464d2 100644
--- a/langs/de/cgi-bin/de.pl
+++ b/langs/de/cgi-bin/de.pl
@@ -1962,6 +1962,7 @@ 
 'read bytes' => 'Gelesene Bytes',
 'read list' => 'Liste der Leseberechtigten',
 'real address' => 'Reale Addresse',
+'rdns' => 'rDNS',
 'reboot' => 'Neustart',
 'reboot ask' => 'Neustart?',
 'reboot question' => 'Extra Abfrage bei neustart und herunterfahren einschalten',
diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl
index 4efff6e65..3af17d5dc 100644
--- a/langs/en/cgi-bin/en.pl
+++ b/langs/en/cgi-bin/en.pl
@@ -1997,6 +1997,7 @@ 
 'quick playlist' => 'Quick Playlist',
 'ram' => 'RAM',
 'random number generator daemon' => 'Random Number Generator Daemon',
+'rdns' => 'rDNS',
 'read bytes' => 'Read Bytes',
 'read list' => 'list with readonly hosts',
 'real address' => 'Real Address',