From mboxrd@z Thu Jan  1 00:00:00 1970
From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH 5/5] Adjust CGI files to work with latest location-function.pl
 changes.
Date: Sat, 07 Nov 2020 19:47:24 +0100
Message-ID: <20201107184724.3590-5-stefan.schantl@ipfire.org>
In-Reply-To: <20201107184724.3590-1-stefan.schantl@ipfire.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============4238581357007984245=="
List-Id: <development.lists.ipfire.org>

--===============4238581357007984245==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Fixes #12515.

Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
 html/cgi-bin/connections.cgi                     | 7 ++-----
 html/cgi-bin/country.cgi                         | 5 +----
 html/cgi-bin/dns.cgi                             | 5 +----
 html/cgi-bin/ipinfo.cgi                          | 5 ++---
 html/cgi-bin/logs.cgi/firewalllog.dat            | 6 ++----
 html/cgi-bin/logs.cgi/firewalllogcountry.dat     | 5 +----
 html/cgi-bin/logs.cgi/firewalllogip.dat          | 6 ++----
 html/cgi-bin/logs.cgi/showrequestfromcountry.dat | 7 ++-----
 html/cgi-bin/ovpnmain.cgi                        | 5 +----
 html/cgi-bin/remote.cgi                          | 6 +-----
 html/cgi-bin/tor.cgi                             | 7 ++-----
 11 files changed, 17 insertions(+), 47 deletions(-)

diff --git a/html/cgi-bin/connections.cgi b/html/cgi-bin/connections.cgi
index 6c55bd7a0..8613b9d9b 100644
--- a/html/cgi-bin/connections.cgi
+++ b/html/cgi-bin/connections.cgi
@@ -86,9 +86,6 @@ if ( $debug ){
 my @dummy =3D ( ${Header::table1colour} );
 undef (@dummy);
=20
-# Init libloc database connection.
-my $libloc_db_handle =3D &Location::Functions::init();
-
 # check sorting arguments
 if ( $cgiin{'sort_field'} ~~ [ '1','2','3','4','5','6','7','8','9' ] ) {
 	$SORT_FIELD =3D $cgiin{'sort_field'};
@@ -554,9 +551,9 @@ foreach my $line (@conntrack) {
 	my $bytes_out =3D format_bytes($bytes[1]);
=20
 	# enumerate location information
-	my $srcccode =3D &Location::Functions::lookup_country_code($libloc_db_handl=
e, $sip_ret);
+	my $srcccode =3D &Location::Functions::lookup_country_code($sip_ret);
 	my $src_flag_icon =3D &Location::Functions::get_flag_icon($srcccode);
-	my $dstccode =3D &Location::Functions::lookup_country_code($libloc_db_handl=
e, $dip_ret);
+	my $dstccode =3D &Location::Functions::lookup_country_code($dip_ret);
 	my $dst_flag_icon =3D &Location::Functions::get_flag_icon($dstccode);
=20
 	# Format TTL
diff --git a/html/cgi-bin/country.cgi b/html/cgi-bin/country.cgi
index b519d89b3..b1c72bb22 100644
--- a/html/cgi-bin/country.cgi
+++ b/html/cgi-bin/country.cgi
@@ -52,11 +52,8 @@ print<<END;
 	</tr>
 END
=20
-# Init libloc database connection.
-my $db_handle =3D &Location::Functions::init();
-
 # Get a list of all supported country codes.
-my @countries =3D &Location::database_countries($db_handle);
+my @countries =3D &Location::database_countries();
=20
 # Loop through whole country list.
 foreach my $country (@countries) {
diff --git a/html/cgi-bin/dns.cgi b/html/cgi-bin/dns.cgi
index 13dd9d6a0..762e77ff1 100755
--- a/html/cgi-bin/dns.cgi
+++ b/html/cgi-bin/dns.cgi
@@ -269,9 +269,6 @@ my %dns_servers =3D ();
 # Read-in config file.
 &General::readhasharray("$servers_file", \%dns_servers);
=20
-# Libloc database handle
-my $libloc_db_handle =3D &Location::Functions::init();
-
 &Header::openpage($Lang::tr{'dns title'}, 1, '');
=20
 &Header::openbigbox('100%', 'left', '', $errormessage);
@@ -598,7 +595,7 @@ END
 				}
=20
 				# collect more information about name server (rDNS, country code)
-				my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_handl=
e, $nameserver);
+				my $ccode =3D &Location::Functions::lookup_country_code($nameserver);
 				my $flag_icon =3D &Location::Functions::get_flag_icon($ccode);
=20
 				my $rdns;
diff --git a/html/cgi-bin/ipinfo.cgi b/html/cgi-bin/ipinfo.cgi
index d8cb6c6b7..ecc7c436c 100644
--- a/html/cgi-bin/ipinfo.cgi
+++ b/html/cgi-bin/ipinfo.cgi
@@ -62,12 +62,11 @@ if (&General::validip($addr)) {
 	if (!$hostname) { $hostname =3D $Lang::tr{'lookup failed'}; }
=20
 	# enumerate location information for IP address...
-	my $db_handle =3D &Location::Functions::init();
-	my $ccode =3D &Location::Functions::lookup_country_code($db_handle, $addr);
+	my $ccode =3D &Location::Functions::lookup_country_code($addr);
 	my @network_flags =3D &Location::Functions::address_has_flags($addr);
=20
 	# Try to get the continent of the country code.
-	my $continent =3D &Location::get_continent_code($db_handle, $ccode);
+	my $continent =3D &Location::Functions::get_continent_code($ccode);
=20
 	# Check if a whois server for the continent is known.
 	if($whois_servers_by_continent{$continent}) {
diff --git a/html/cgi-bin/logs.cgi/firewalllog.dat b/html/cgi-bin/logs.cgi/fi=
rewalllog.dat
index 2b690e35b..361bf0432 100644
--- a/html/cgi-bin/logs.cgi/firewalllog.dat
+++ b/html/cgi-bin/logs.cgi/firewalllog.dat
@@ -24,9 +24,6 @@ require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
=20
-# Libloc database handle.
-my $libloc_db_handle =3D &Location::Functions::init();
-
 my %color =3D ();
 my %mainsettings =3D ();
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
@@ -354,7 +351,8 @@ foreach $_ (@log)
 	$srcport=3D$1 if $packet =3D~ /SPT=3D(\d+)/;
 	$dstport=3D$1 if $packet =3D~ /DPT=3D(\d+)/;
=20
-	my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_handle, =
$srcaddr);
+	# Get the country code.
+	my $ccode =3D &Location::Functions::lookup_country_code($srcaddr);
=20
 	my $servi =3D uc(getservbyport($srcport, lc($proto)));
 	if ($servi ne '' && $srcport < 1024) {
diff --git a/html/cgi-bin/logs.cgi/firewalllogcountry.dat b/html/cgi-bin/logs=
.cgi/firewalllogcountry.dat
index 701abab2c..e3901b945 100644
--- a/html/cgi-bin/logs.cgi/firewalllogcountry.dat
+++ b/html/cgi-bin/logs.cgi/firewalllogcountry.dat
@@ -22,9 +22,6 @@ require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
=20
-# Libloc database handle.
-my $libloc_db_handle =3D &Location::Functions::init();
-
 use POSIX();
=20
 my %cgiparams=3D();
@@ -311,7 +308,7 @@ foreach $_ (@log)
 		# Traffic from red
 		if($srcaddr ne '') {
 			# srcaddr is set
-			my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_handle=
, $srcaddr);
+			my $ccode =3D &Location::Functions::lookup_country_code($srcaddr);
 			if ($ccode eq '') {
 				$ccode =3D 'unknown';
 			}
diff --git a/html/cgi-bin/logs.cgi/firewalllogip.dat b/html/cgi-bin/logs.cgi/=
firewalllogip.dat
index 670d72a52..6de4081af 100644
--- a/html/cgi-bin/logs.cgi/firewalllogip.dat
+++ b/html/cgi-bin/logs.cgi/firewalllogip.dat
@@ -22,9 +22,6 @@ require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
=20
-# Libloc database handle.
-my $libloc_db_handle =3D &Location::Functions::init();
-
 use POSIX();
=20
 my %cgiparams=3D();
@@ -438,7 +435,8 @@ for($s=3D0;$s<$lines;$s++)
 	$col=3D"bgcolor=3D'$color{\"color$colorIndex\"}'";
 	print "<tr>";
=20
-	my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_handle, =
$key[$s]);
+	# Get country code.
+	my $ccode =3D &Location::Functions::lookup_country_code($key[$s]);
  =20
 	$color++;
 	print "<td align=3D'center' $col><form method=3D'post' action=3D'showreques=
tfromip.dat'><input type=3D'hidden' name=3D'MONTH' value=3D'$cgiparams{'MONTH=
'}'> <input type=3D'hidden' name=3D'DAY' value=3D'$cgiparams{'DAY'}'> <input =
type=3D'hidden' name=3D'ip' value=3D'$key[$s]'> <input type=3D'submit' value=
=3D'$Lang::tr{'details'}'></form></td>";
diff --git a/html/cgi-bin/logs.cgi/showrequestfromcountry.dat b/html/cgi-bin/=
logs.cgi/showrequestfromcountry.dat
index 4d80e77a4..2a246ec60 100644
--- a/html/cgi-bin/logs.cgi/showrequestfromcountry.dat
+++ b/html/cgi-bin/logs.cgi/showrequestfromcountry.dat
@@ -19,9 +19,6 @@ require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
=20
-# Libloc database handle.
-my $libloc_db_handle =3D &Location::Functions::init();
-
 use POSIX();
=20
 #workaround to suppress a warning when a variable is used only once
@@ -181,7 +178,7 @@ if (!$skip)
 			}
 			elsif($srcaddr ne '') {
 				# or srcaddr matches country code
-				my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_handl=
e, $srcaddr);
+				my $ccode =3D &Location::Functions::lookup_country_code($srcaddr);
 				if($ccode eq uc($country)){
 					$log[$lines] =3D $_;
 					$lines++;
@@ -352,7 +349,7 @@ foreach $_ (@slice)
 	if($iface eq $country || $srcaddr ne '') {
 		my $ccode=3D'';
 		if($iface ne $country) {
-			$ccode =3D &Location::Functions::lookup_country_code($libloc_db_handle, $=
srcaddr);
+			$ccode =3D &Location::Functions::lookup_country_code($srcaddr);
 		}
 		if($iface eq $country || $ccode eq uc($country)) {
 			my $chain =3D '';
diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi
index e7bc505e7..8626a94ca 100644
--- a/html/cgi-bin/ovpnmain.cgi
+++ b/html/cgi-bin/ovpnmain.cgi
@@ -3002,9 +3002,6 @@ END
 	&Header::openbigbox('100%', 'LEFT', '', '');
     &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'});
=20
-    # Libloc database handle.
-    my $libloc_db_handle =3D &Location::Functions::init();
-
 #
 #	<td><b>$Lang::tr{'protocol'}</b></td>
 # protocol temp removed=20
@@ -3055,7 +3052,7 @@ END
 		    $users[$uid]{'Proto'} =3D $proto;
=20
 		    # get country code for "RealAddress"...
-		    my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_han=
dle, (split ':', $users[$uid]{'RealAddress'})[0]);
+		    my $ccode =3D &Location::Functions::lookup_country_code((split ':', $u=
sers[$uid]{'RealAddress'})[0]);
 		    my $flag_icon =3D &Location::Functions::get_flag_icon($ccode);
 		    $users[$uid]{'Country'} =3D "<a href=3D'country.cgi#$ccode'><img src=
=3D'$flag_icon' border=3D'0' align=3D'absmiddle' alt=3D'$ccode' title=3D'$cco=
de' /></a>";
 		    $uid++;
diff --git a/html/cgi-bin/remote.cgi b/html/cgi-bin/remote.cgi
index 9c742669b..a27e10de9 100644
--- a/html/cgi-bin/remote.cgi
+++ b/html/cgi-bin/remote.cgi
@@ -277,10 +277,6 @@ sub printactivelogins()
 		print "<tr bgcolor=3D'$table_colour'><td colspan=3D'5'>$Lang::tr{'ssh no a=
ctive logins'}</td></tr>\n";
 	} else {
 		# list active logins...
-
-		# Libloc database handle.
-		my $libloc_db_handle =3D &Location::Functions::init();
-
 		foreach my $line (@output)
 		{
 			my @arry =3D split(/\ +/, $line);
@@ -291,7 +287,7 @@ sub printactivelogins()
 			$remoteip =3D~ s/[()]//g;
=20
 			# display more information about that IP adress...
-			my $ccode =3D &Location::Functions::lookup_country_code($libloc_db_handle=
, $remoteip);
+			my $ccode =3D &Location::Functions::lookup_country_code($remoteip);
 			my $flag_icon =3D &Location::Functions::get_flag_icon($ccode);
=20
 			# get rDNS...
diff --git a/html/cgi-bin/tor.cgi b/html/cgi-bin/tor.cgi
index 14bfcfe90..983bb30c9 100644
--- a/html/cgi-bin/tor.cgi
+++ b/html/cgi-bin/tor.cgi
@@ -30,9 +30,6 @@ require "${General::swroot}/location-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
=20
-# Init libloc database connection.
-my $db_handle =3D &Location::Functions::init();
-
 #workaround to suppress a warning when a variable is used only once
 my @dummy =3D ( ${Header::colouryellow} );
 undef (@dummy);
@@ -322,7 +319,7 @@ END
 					<select name=3D'TOR_EXIT_COUNTRY'>
 						<option value=3D''>- $Lang::tr{'tor exit country any'} -</option>
 END
-		my @country_codes =3D &Location::database_countries($db_handle);
+		my @country_codes =3D &Location::Functions::get_locations("no_special_loca=
tions");
 		foreach my $country_code (@country_codes) {
 			# Convert country code into upper case format.
 			$country_code =3D uc($country_code);
@@ -912,7 +909,7 @@ sub TorNodeDescription() {
 			$node->{'address'} =3D $3;
 			$node->{'port'}    =3D $4;
=20
-			my $country_code =3D &Location::Functions::lookup_country_code($db_handle=
, $node->{'address'});
+			my $country_code =3D &Location::Functions::lookup_country_code($node->{'a=
ddress'});
 			$node->{'country_code'} =3D $country_code;
=20
 		# Flags
--=20
2.20.1


--===============4238581357007984245==--