display GeoIP information for hosts blocked by Guardian

Message ID 20171202193940.0fa7006d.peter.mueller@link38.eu
State Dropped
Headers
Series display GeoIP information for hosts blocked by Guardian |

Commit Message

Peter Müller Dec. 3, 2017, 5:39 a.m. UTC
  Display GeoIP flag for blocked hosts at guardian.cgi in the WebUI.

This makes spotting blocked local IPs (grey flag with question mark)
easier. Enumerating the rDNS entry, unfortunately, takes way too
long.

Signed-off-by: Peter Müller <peter.mueller@link38.eu>
---
 html/cgi-bin/guardian.cgi | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
  

Patch

diff --git a/html/cgi-bin/guardian.cgi b/html/cgi-bin/guardian.cgi
index e15501ef5..3bfa1b522 100644
--- a/html/cgi-bin/guardian.cgi
+++ b/html/cgi-bin/guardian.cgi
@@ -30,6 +30,7 @@  use Guardian::Socket;
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
+require "${General::swroot}/geoip-functions.pl";
 
 #workaround to suppress a warning when a variable is used only once
 my @dummy = (
@@ -791,7 +792,10 @@  sub showBlockedBox() {
 	print <<END;
 	<table width='60%'>
 		<tr>
-			<td colspan='2' class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'guardian blocked hosts'}</b></td>
+			<td class='base' bgcolor='$color{'color20'}'><b>$Lang::tr{'ip address'}</b></td>
+			<td class='base' align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'country'}</b></td>
+			<td class='base' bgcolor='$color{'color20'}'></td>
+			<td class='base' align='center' bgcolor='$color{'color20'}'><b>$Lang::tr{'unblock'}</b></td>
 		</tr>
 END
 
@@ -814,9 +818,17 @@  END
 				$col="bgcolor='$color{'color20'}'";
 			}
 
+			# enumerate GeoIP information for blocked host...
+			my $ccode = &GeoIP::lookup($blocked_host);
+			my $flag_icon = &GeoIP::get_flag_icon($ccode);
+
 			print <<END;
 			<tr>
-				<td width='80%' class='base' $col><a href='/cgi-bin/ipinfo.cgi?ip=$blocked_host'>$blocked_host</a></td>
+				<td width='20%' class='base' $col><a href='/cgi-bin/ipinfo.cgi?ip=$blocked_host'>$blocked_host</a></td>
+				<td width='20%' class='base' align='center' $col>
+						<a href='/cgi-bin/country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a>
+				</td>
+				<td width='30%' class='base' $col></td>
 				<td width='20%' align='center' $col>
 					<form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
 						<input type='image' name='$Lang::tr{'unblock'}' src='/images/delete.gif' title='$Lang::tr{'unblock'}' alt='$Lang::tr{'unblock'}'>
@@ -834,7 +846,7 @@  END
 
 		# Print notice that currently no hosts are blocked.
 		print "<tr>\n";
-		print "<td class='base' colspan='2'>$Lang::tr{'guardian no entries'}</td>\n";
+		print "<td class='base' colspan='4'>$Lang::tr{'guardian no entries'}</td>\n";
 		print "</tr>\n";
 	}