public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Bernhard Bitsch <Bernhard.Bitsch@gmx.de>
To: development@lists.ipfire.org
Subject: Aw: [PATCH 5/5] Adjust CGI files to work with latest location-function.pl changes.
Date: Tue, 10 Nov 2020 13:18:00 +0100	[thread overview]
Message-ID: <trinity-e53b1cbc-e7c2-4f4a-b8a6-274aa3dec119-1605010680766@3c-app-gmx-bap35> (raw)
In-Reply-To: <20201107184724.3590-5-stefan.schantl@ipfire.org>

[-- Attachment #1: Type: text/plain, Size: 10741 bytes --]

country.cgi should use Location::Functions::get_locations()

> Gesendet: Samstag, 07. November 2020 um 19:47 Uhr
> Von: "Stefan Schantl" <stefan.schantl(a)ipfire.org>
> An: development(a)lists.ipfire.org
> Betreff: [PATCH 5/5] Adjust CGI files to work with latest location-function.pl changes.
>
> Fixes #12515.
>
> Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
...
> 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
>
> -# Init libloc database connection.
> -my $db_handle = &Location::Functions::init();
> -
>  # Get a list of all supported country codes.
> -my @countries = &Location::database_countries($db_handle);
> +my @countries = &Location::database_countries();
>

+my @countries = Location::Funvtions:get_locations();

>  # 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 = ();
>  # Read-in config file.
>  &General::readhasharray("$servers_file", \%dns_servers);
>
> -# Libloc database handle
> -my $libloc_db_handle = &Location::Functions::init();
> -
>  &Header::openpage($Lang::tr{'dns title'}, 1, '');
>
>  &Header::openbigbox('100%', 'left', '', $errormessage);
> @@ -598,7 +595,7 @@ END
>  				}
>
>  				# collect more information about name server (rDNS, country code)
> -				my $ccode = &Location::Functions::lookup_country_code($libloc_db_handle, $nameserver);
> +				my $ccode = &Location::Functions::lookup_country_code($nameserver);
>  				my $flag_icon = &Location::Functions::get_flag_icon($ccode);
>
>  				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 = $Lang::tr{'lookup failed'}; }
>
>  	# enumerate location information for IP address...
> -	my $db_handle = &Location::Functions::init();
> -	my $ccode = &Location::Functions::lookup_country_code($db_handle, $addr);
> +	my $ccode = &Location::Functions::lookup_country_code($addr);
>  	my @network_flags = &Location::Functions::address_has_flags($addr);
>
>  	# Try to get the continent of the country code.
> -	my $continent = &Location::get_continent_code($db_handle, $ccode);
> +	my $continent = &Location::Functions::get_continent_code($ccode);
>
>  	# 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/firewalllog.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";
>
> -# Libloc database handle.
> -my $libloc_db_handle = &Location::Functions::init();
> -
>  my %color = ();
>  my %mainsettings = ();
>  &General::readhash("${General::swroot}/main/settings", \%mainsettings);
> @@ -354,7 +351,8 @@ foreach $_ (@log)
>  	$srcport=$1 if $packet =~ /SPT=(\d+)/;
>  	$dstport=$1 if $packet =~ /DPT=(\d+)/;
>
> -	my $ccode = &Location::Functions::lookup_country_code($libloc_db_handle, $srcaddr);
> +	# Get the country code.
> +	my $ccode = &Location::Functions::lookup_country_code($srcaddr);
>
>  	my $servi = 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";
>
> -# Libloc database handle.
> -my $libloc_db_handle = &Location::Functions::init();
> -
>  use POSIX();
>
>  my %cgiparams=();
> @@ -311,7 +308,7 @@ foreach $_ (@log)
>  		# Traffic from red
>  		if($srcaddr ne '') {
>  			# srcaddr is set
> -			my $ccode = &Location::Functions::lookup_country_code($libloc_db_handle, $srcaddr);
> +			my $ccode = &Location::Functions::lookup_country_code($srcaddr);
>  			if ($ccode eq '') {
>  				$ccode = '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";
>
> -# Libloc database handle.
> -my $libloc_db_handle = &Location::Functions::init();
> -
>  use POSIX();
>
>  my %cgiparams=();
> @@ -438,7 +435,8 @@ for($s=0;$s<$lines;$s++)
>  	$col="bgcolor='$color{\"color$colorIndex\"}'";
>  	print "<tr>";
>
> -	my $ccode = &Location::Functions::lookup_country_code($libloc_db_handle, $key[$s]);
> +	# Get country code.
> +	my $ccode = &Location::Functions::lookup_country_code($key[$s]);
>
>  	$color++;
>  	print "<td align='center' $col><form method='post' action='showrequestfromip.dat'><input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'> <input type='hidden' name='DAY' value='$cgiparams{'DAY'}'> <input type='hidden' name='ip' value='$key[$s]'> <input type='submit' value='$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";
>
> -# Libloc database handle.
> -my $libloc_db_handle = &Location::Functions::init();
> -
>  use POSIX();
>
>  #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 = &Location::Functions::lookup_country_code($libloc_db_handle, $srcaddr);
> +				my $ccode = &Location::Functions::lookup_country_code($srcaddr);
>  				if($ccode eq uc($country)){
>  					$log[$lines] = $_;
>  					$lines++;
> @@ -352,7 +349,7 @@ foreach $_ (@slice)
>  	if($iface eq $country || $srcaddr ne '') {
>  		my $ccode='';
>  		if($iface ne $country) {
> -			$ccode = &Location::Functions::lookup_country_code($libloc_db_handle, $srcaddr);
> +			$ccode = &Location::Functions::lookup_country_code($srcaddr);
>  		}
>  		if($iface eq $country || $ccode eq uc($country)) {
>  			my $chain = '';
> 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'});
>
> -    # Libloc database handle.
> -    my $libloc_db_handle = &Location::Functions::init();
> -
>  #
>  #	<td><b>$Lang::tr{'protocol'}</b></td>
>  # protocol temp removed
> @@ -3055,7 +3052,7 @@ END
>  		    $users[$uid]{'Proto'} = $proto;
>
>  		    # get country code for "RealAddress"...
> -		    my $ccode = &Location::Functions::lookup_country_code($libloc_db_handle, (split ':', $users[$uid]{'RealAddress'})[0]);
> +		    my $ccode = &Location::Functions::lookup_country_code((split ':', $users[$uid]{'RealAddress'})[0]);
>  		    my $flag_icon = &Location::Functions::get_flag_icon($ccode);
>  		    $users[$uid]{'Country'} = "<a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></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='$table_colour'><td colspan='5'>$Lang::tr{'ssh no active logins'}</td></tr>\n";
>  	} else {
>  		# list active logins...
> -
> -		# Libloc database handle.
> -		my $libloc_db_handle = &Location::Functions::init();
> -
>  		foreach my $line (@output)
>  		{
>  			my @arry = split(/\ +/, $line);
> @@ -291,7 +287,7 @@ sub printactivelogins()
>  			$remoteip =~ s/[()]//g;
>
>  			# display more information about that IP adress...
> -			my $ccode = &Location::Functions::lookup_country_code($libloc_db_handle, $remoteip);
> +			my $ccode = &Location::Functions::lookup_country_code($remoteip);
>  			my $flag_icon = &Location::Functions::get_flag_icon($ccode);
>
>  			# 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";
>
> -# Init libloc database connection.
> -my $db_handle = &Location::Functions::init();
> -
>  #workaround to suppress a warning when a variable is used only once
>  my @dummy = ( ${Header::colouryellow} );
>  undef (@dummy);
> @@ -322,7 +319,7 @@ END
>  					<select name='TOR_EXIT_COUNTRY'>
>  						<option value=''>- $Lang::tr{'tor exit country any'} -</option>
>  END
> -		my @country_codes = &Location::database_countries($db_handle);
> +		my @country_codes = &Location::Functions::get_locations("no_special_locations");
>  		foreach my $country_code (@country_codes) {
>  			# Convert country code into upper case format.
>  			$country_code = uc($country_code);
> @@ -912,7 +909,7 @@ sub TorNodeDescription() {
>  			$node->{'address'} = $3;
>  			$node->{'port'}    = $4;
>
> -			my $country_code = &Location::Functions::lookup_country_code($db_handle, $node->{'address'});
> +			my $country_code = &Location::Functions::lookup_country_code($node->{'address'});
>  			$node->{'country_code'} = $country_code;
>
>  		# Flags
> --
> 2.20.1
>
>

  reply	other threads:[~2020-11-10 12:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-07 18:47 [PATCH 1/5] location-functions.pl: Use a single script-wide db_handle Stefan Schantl
2020-11-07 18:47 ` [PATCH 2/5] location-functions.pl: Add END block to release the database handle Stefan Schantl
2020-11-07 18:47 ` [PATCH 3/5] location-functions.pl: Add get_continent_code() function Stefan Schantl
2020-11-07 18:47 ` [PATCH 4/5] locations-functions.pl: Allow get_locations() function to skip special locations Stefan Schantl
2020-11-09 11:49   ` Michael Tremer
2020-11-07 18:47 ` [PATCH 5/5] Adjust CGI files to work with latest location-function.pl changes Stefan Schantl
2020-11-10 12:18   ` Bernhard Bitsch [this message]
2020-11-08 19:36 ` Aw: [PATCH 1/5] location-functions.pl: Use a single script-wide db_handle Bernhard Bitsch
2020-11-09 11:35   ` Michael Tremer
2020-11-09 12:13     ` Aw: " Bernhard Bitsch
2020-11-09 14:04       ` Michael Tremer
2020-11-09 15:16         ` Aw: " Bernhard Bitsch
2020-11-09 17:03           ` Michael Tremer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-e53b1cbc-e7c2-4f4a-b8a6-274aa3dec119-1605010680766@3c-app-gmx-bap35 \
    --to=bernhard.bitsch@gmx.de \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox