From patchwork Sat Nov 7 18:47:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3647 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CT5pz4L3Sz3wlL for ; Sat, 7 Nov 2020 18:47:39 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CT5py1CK9z1lQ; Sat, 7 Nov 2020 18:47:38 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CT5px4wwHz2ydm; Sat, 7 Nov 2020 18:47:37 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CT5pv6z0dz2xGb for ; Sat, 7 Nov 2020 18:47:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CT5pt73l5zj3; Sat, 7 Nov 2020 18:47:34 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604774855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wMudWN7co6mwqVKai54bCx3mY7Yyhm10L/mRJ6PdiwU=; b=h2Kn9xTMAOlXsSSv+yKDMg4aayBjmLofP29c1agbcIthtKvZyFAA69TLjYqRK7BUKZeF+f eOsYGqN64WUnriBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604774855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wMudWN7co6mwqVKai54bCx3mY7Yyhm10L/mRJ6PdiwU=; b=JhA1EeYNnjuzElxtSSCzVYovwgMee7BjUsUPNQn474SirumyZvzjBAJkYJ2nzwPNsUHh4O 982OKC0I1gkodmN3gBDXuRMIh5gQT4X7IupPJ529yDHcgznKm6rVpuaaMPCtdrwGZCKX3z xGOUOsxpXFH1DVFXH1m9lt4QAOGVnWr6A1kI7JX8b71JvKBshP6HW81FAChgDUCOzzCDsJ qOo445zPouXHSuNnzEWopccR4CGvt4SetNJWMem3sMPANvoHA+ahoUqRnT+2iLYxG/rGCG jWB/uYhabN0m+VmIlnriNCUhpEA84LgE50Hpe69kJfWZmywD4oM/nRWIRaKYvg== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 1/5] location-functions.pl: Use a single script-wide db_handle. Date: Sat, 7 Nov 2020 19:47:20 +0100 Message-Id: <20201107184724.3590-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 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" Create and use a single script-wide database handle for libloc to prevent from creating multiple ones. This helps saving memory, especially on small systems. Reference #12515. Signed-off-by: Stefan Schantl --- config/cfgroot/location-functions.pl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index 2cfe7f908..9b1d0bfb5 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -55,6 +55,9 @@ our $keyfile = "$location_dir/signing-key.pem"; # Directory which contains the exported databases. our $xt_geoip_db_directory = "/usr/share/xt_geoip/"; +# Create libloc database handle. +my $db_handle = &init(); + # ## Tiny function to init the location database. # @@ -86,7 +89,7 @@ sub verify ($) { ## Function to the the country code of a given address. # sub lookup_country_code($$) { - my ($db_handle, $address) = @_; + my ($address) = @_; # Lookup the given address. my $country_code = &Location::lookup_country_code($db_handle, $address); @@ -174,9 +177,6 @@ sub get_full_country_name($) { # Function to get all available locations. sub get_locations() { - # Create libloc database handle. - my $db_handle = &init(); - # Get locations which are stored in the location database. my @database_locations = &Location::database_countries($db_handle); @@ -197,9 +197,6 @@ sub address_has_flags($) { # Array to store the flags of the address. my @flags; - # Init libloc database handle. - my $db_handle = &init(); - # Loop through the hash of possible network flags. foreach my $flag (keys(%network_flags)) { # Check if the address has the current flag. From patchwork Sat Nov 7 18:47:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3648 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CT5q12dG5z3wlL for ; Sat, 7 Nov 2020 18:47:41 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CT5py3Rbwz1mm; Sat, 7 Nov 2020 18:47:38 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CT5px5WRjz2yfh; Sat, 7 Nov 2020 18:47:37 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CT5pw3jDRz2xGb for ; Sat, 7 Nov 2020 18:47:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CT5pw1HVfzv9; Sat, 7 Nov 2020 18:47:36 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604774856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jawETcxq2NWCY9YP9uIbPFEs81CoYGukEIxumppXul0=; b=nNlPWEXdmvomEzQNft84GwCV2qrLVZY2AYz3G15a5F5y2tPPWQSswt2TGl7vUUdOBByK1X j+BXh0FD4EsnYFCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604774856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jawETcxq2NWCY9YP9uIbPFEs81CoYGukEIxumppXul0=; b=uNKLV/nlPTOs6PUHvCbcwqMygKv7MWTVuO1nvcm4JbDzwziVziQG/IQYXaAOGNbYMt8KDV tJncPcooX1xUtb4rLo02TKmDbFi7aN06lzZ5S/DnulwIWyz2gD85DlYf9l+Pj8Mr2ZlYnN R0lGlAcXrB+wAt2CmQemlak9fPqAXsHzPTVfQAyXBtbyyfkU39bmKsDW6Ind/PbBj1/uOw KJLalY6GZFv3/QmusssgxGiptqdDASnHyND4WGaODUaOP8/dZPsPMGu+xWO+wHxFudWC/8 /Tg11csKNP4RUe72EbR6XCZ5kcPeMKMvshE1KXEU0Ya3ZKJGXyxtWSaGdazFgA== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 2/5] location-functions.pl: Add END block to release the database handle. Date: Sat, 7 Nov 2020 19:47:21 +0100 Message-Id: <20201107184724.3590-2-stefan.schantl@ipfire.org> In-Reply-To: <20201107184724.3590-1-stefan.schantl@ipfire.org> References: <20201107184724.3590-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 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" Reference #12515. Signed-off-by: Stefan Schantl --- config/cfgroot/location-functions.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index 9b1d0bfb5..483703016 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -218,4 +218,14 @@ sub address_has_flags($) { return @flags; } +# Custom END declaration which will be executed when perl +# ends, to release the database handle to libloc. +END { + # Check if a database handle exists. + if ($db_handle) { + # Destroy libloc database handle. + &Location::DESTROY($db_handle); + } +} + 1; From patchwork Sat Nov 7 18:47:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3649 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CT5q23Yg2z3wlL for ; Sat, 7 Nov 2020 18:47:42 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CT5py6nWZz1pB; Sat, 7 Nov 2020 18:47:38 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CT5py656Vz2yb5; Sat, 7 Nov 2020 18:47:38 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CT5pw60w3z2xGb for ; Sat, 7 Nov 2020 18:47:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CT5pw42fPz1GP; Sat, 7 Nov 2020 18:47:36 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604774856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0lZe4e7+Mml3lZgYAI7g2eG5NJ9IZy6bvT0IM9KL2eQ=; b=J90u8g6CPqxbjrmDag8eVssOiLfMCT7FwIQsv23BHJ3hyXgSfFebPDfMWbj/Xq7K9STv0L uSTZ2Cdz0dHuZrAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604774856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0lZe4e7+Mml3lZgYAI7g2eG5NJ9IZy6bvT0IM9KL2eQ=; b=PrQ1WbUe+53KgM6eMxHm49YPUe/bZm367Bo6lHJKys+90rhO0+qDOkKyh3JCH+ovV3TJU2 mUo741+GWPN2odHtUR5fRSBEfHkdagi5ZquT2hbe1nD1LSr+9wRgQOyz8RaGYsTqxXZDDC T6ybIa0SUjlPNCg5C3xs6bjxPe9Xea/XNzIC8BX5JtzKwK0OG4JC0Xsnokheefb7lWQ36E W7VRAe7NHm/Vf4RkhPMNkdLGdkh1sYFbOUalXZDlqGRv4R/LVytZ+MWRBHyzP2RA7c63pN weatTrBGodJTmVNnD+YHSPAl4evN+HdQKJQ1QXcHhxJL24Z/nTknalTuzlBdIg== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 3/5] location-functions.pl: Add get_continent_code() function. Date: Sat, 7 Nov 2020 19:47:22 +0100 Message-Id: <20201107184724.3590-3-stefan.schantl@ipfire.org> In-Reply-To: <20201107184724.3590-1-stefan.schantl@ipfire.org> References: <20201107184724.3590-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 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" This tiny function is used to get the continent code for a given country code. Signed-off-by: Stefan Schantl --- config/cfgroot/location-functions.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index 483703016..e8db4ba9b 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -190,6 +190,16 @@ sub get_locations() { return @sorted_locations; } +# Function to get the continent code of a given country code. +sub get_continent_code($) { + my ($country_code) = @_; + + # Use location module to grab the continent code. + my $continent_code = &Location::get_continent_code($db_handle, $country_code); + + return $continent_code; +} + # Function to check if a given address has one ore more special flags. sub address_has_flags($) { my ($address) = @_; From patchwork Sat Nov 7 18:47:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3650 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CT5q25XdDz3wlM for ; Sat, 7 Nov 2020 18:47:42 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CT5pz0Jj1z1qJ; Sat, 7 Nov 2020 18:47:39 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CT5py6ll6z2ydZ; Sat, 7 Nov 2020 18:47:38 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CT5px1G09z2xGb for ; Sat, 7 Nov 2020 18:47:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CT5pw6KMKz1Qr; Sat, 7 Nov 2020 18:47:36 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604774857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lno+baKTSDpcQsPZWuvspwhQIgoFbKH2S0Wlvbx89Dc=; b=qGYxIb3X034xkOSUPE1f3CqWPTnE5E1ktzgnIM4e2swskttG5kilvKlIKr28G2dkFDtGwX 7WTn6H1tymE5SOCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604774857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lno+baKTSDpcQsPZWuvspwhQIgoFbKH2S0Wlvbx89Dc=; b=fwcLaYYME0ZO7rJSumTKtFI9XzXa4ak7991y4yy0tNksUN7AVzUbjyvLFHd3TeA2XHoR/3 KU8uWzRBPinXT/CLgL8b6j+02i7/qYvG5NIN1qkp/0APPbN6xMFvzLYuMMO1/18JrckpKZ 1pXgr0VhNtKeogjr7BC9ObxTlmYmPZpun+wAxZB7OaF59Mr6WakfiHP3/2jcAq7F4QyVaQ sG1WSrmbQ8S7wGNocDJyayTQVod9iKlTxZUljQ8GovXZXKPUD5DfAjwMp6P5v0Lt3Iom2u 7/6cYazNFA5o6Hr3O+551gZenqFTx8xiidKgS81f7GRLuFxRKpoXwjCwpn+fOw== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 4/5] locations-functions.pl: Allow get_locations() function to skip special locations. Date: Sat, 7 Nov 2020 19:47:23 +0100 Message-Id: <20201107184724.3590-4-stefan.schantl@ipfire.org> In-Reply-To: <20201107184724.3590-1-stefan.schantl@ipfire.org> References: <20201107184724.3590-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 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" When adding "no_special_locations" to the function call as argument the special locations liks "A1, A2, A3 etc" will not be added to the returned array as available locations. Signed-off-by: Stefan Schantl --- config/cfgroot/location-functions.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/config/cfgroot/location-functions.pl b/config/cfgroot/location-functions.pl index e8db4ba9b..fdf2c6efe 100644 --- a/config/cfgroot/location-functions.pl +++ b/config/cfgroot/location-functions.pl @@ -177,16 +177,24 @@ sub get_full_country_name($) { # Function to get all available locations. sub get_locations() { + my ($mode) = @_; + + # Set default mode to add_special_locations. + $mode = $mode ? $mode : "add_special_locations"; + # Get locations which are stored in the location database. - my @database_locations = &Location::database_countries($db_handle); + my @locations = &Location::database_countries($db_handle); - # Merge special locations array and the database locations array. - my @locations = (@special_locations, @database_locations); + # Check if the special locations should be added. + if ($mode ne "no_special_locations") { + # Merge special locations array and the database locations array. + @locations = (@special_locations, @locations); + } # Sort locations array in alphabetical order. my @sorted_locations = sort(@locations); - # Return the array.. + # Return the array. return @sorted_locations; } From patchwork Sat Nov 7 18:47:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3651 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CT5q46kWJz3wlL for ; Sat, 7 Nov 2020 18:47:44 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CT5pz48tkzpB; Sat, 7 Nov 2020 18:47:39 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CT5pz0Phkz2yfh; Sat, 7 Nov 2020 18:47:39 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CT5px3jG2z2xGb for ; Sat, 7 Nov 2020 18:47:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CT5px1Zncz1l6; Sat, 7 Nov 2020 18:47:37 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1604774857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XN4hLzOGm8muNyCPYwWkeLeU1PYW12aPu/x8RbgkpRQ=; b=qmM8rnW9w+WnWBfINaGEa0kMBRPXAF4zRpwdkM6etpHpEVi1MCP6QySDSwtpyUHs/IjfA5 Bh1qhr4wlZW84ZBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1604774857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XN4hLzOGm8muNyCPYwWkeLeU1PYW12aPu/x8RbgkpRQ=; b=fUu+pH88ZzCmE0X1tZ+2rEztwoPkJH14ndHD0bX/cV1E3Vfc4CwK0UAL52qvM+CnUYT6oz CPCF3DjhQ1q0BJkjtaIFp3pE3EGaCwalcQk3yu/CPKdTcicv4Dow/aRNQSBE/vWWaBniic 4HgsgTROcjnkl5MbdnUBHHsORK58Etynl9th8yPrmr0zyO8VU/IE1/3+kcLRTqMSmkdYSc 8UA7f3y+lqKZAcvHvYmDLN7SWgtt0MX66rit+QPZvrffxdPfOxzqOYyGmSGf3mNY1HilQ6 ++FQ6DAq2gj61gBTAGtcoo7iOHWR8i/DPRAh4whlC5b+VOCV6KyjNDAT1stEeg== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 5/5] Adjust CGI files to work with latest location-function.pl changes. Date: Sat, 7 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> References: <20201107184724.3590-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 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" Fixes #12515. Signed-off-by: Stefan Schantl --- 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 = ( ${Header::table1colour} ); undef (@dummy); -# Init libloc database connection. -my $libloc_db_handle = &Location::Functions::init(); - # check sorting arguments if ( $cgiin{'sort_field'} ~~ [ '1','2','3','4','5','6','7','8','9' ] ) { $SORT_FIELD = $cgiin{'sort_field'}; @@ -554,9 +551,9 @@ foreach my $line (@conntrack) { my $bytes_out = format_bytes($bytes[1]); # enumerate location information - my $srcccode = &Location::Functions::lookup_country_code($libloc_db_handle, $sip_ret); + my $srcccode = &Location::Functions::lookup_country_code($sip_ret); my $src_flag_icon = &Location::Functions::get_flag_icon($srcccode); - my $dstccode = &Location::Functions::lookup_country_code($libloc_db_handle, $dip_ret); + my $dstccode = &Location::Functions::lookup_country_code($dip_ret); my $dst_flag_icon = &Location::Functions::get_flag_icon($dstccode); # 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 -# 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(); # 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 ""; - 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 "
"; 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(); - # # $Lang::tr{'protocol'} # 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'} = "$ccode"; $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 "$Lang::tr{'ssh no active logins'}\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