]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
ipinfo.cgi: Allow to display multiple flags.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 20 Sep 2020 07:25:19 +0000 (09:25 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 20 Sep 2020 07:25:19 +0000 (09:25 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/location-functions.pl
html/cgi-bin/ipinfo.cgi

index b0b8cd086605712bb047a964fe221e308e518daf..2cfe7f908fd92db2dd7c49be5630d8337bf2de79 100644 (file)
@@ -190,10 +190,13 @@ sub get_locations() {
        return @sorted_locations;
 }
 
-# Function to check if a given address has a special flag.
-sub address_has_flag($) {
+# Function to check if a given address has one ore more special flags.
+sub address_has_flags($) {
        my ($address) = @_;
 
+       # Array to store the flags of the address.
+       my @flags;
+
        # Init libloc database handle.
        my $db_handle = &init();
 
@@ -206,10 +209,16 @@ sub address_has_flag($) {
                        # Grab the mapped location code for this flag.
                        $mapped_code = $network_flags{$flag};
 
-                       # Return the code.
-                       return $mapped_code;
+                       # Add the mapped code to the array of flags.
+                       push(@flags, $mapped_code);
                }
        }
+
+       # Sort the array of flags.
+       @flags = sort(@flags);
+
+       # Return the array of flags.
+       return @flags;
 }
 
 1;
index cce6097ffd8e8f9e9ea5c6dbb5f589215597f0f4..6d703bc7efa96e3311ab743074f89098f864fcf7 100644 (file)
@@ -64,7 +64,7 @@ if (&General::validip($addr)) {
        # enumerate location information for IP address...
        my $db_handle = &Location::Functions::init();
        my $ccode = &Location::Functions::lookup_country_code($db_handle, $addr);
-       my $network_flag = &Location::Functions::address_has_flag($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);
@@ -111,12 +111,27 @@ if (&General::validip($addr)) {
        &Header::openbox('100%', 'left', $addr . " <a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a> (" . $hostname . ') : '.$whois_server);
 
        # Check if the address has a flag.
-       if ($network_flag) {
-               # Get
-               my $network_flag_name = &Location::Functions::get_full_country_name($network_flag);
+       if (@network_flags) {
+               # The message string which will be displayed.
+               my $message_string = "This address is marked as";
+
+               # Loop through the array of network_flags.
+               foreach my $network_flag (@network_flags) {
+                       # Get the network flag name.
+                       my $network_flag_name = &Location::Functions::get_full_country_name($network_flag);
+
+                       # Add the flag name to the message string.
+                       $message_string = "$message_string" . " $network_flag_name";
+
+                       # Check if the current processed is the last one.
+                       unless ($network_flag eq $network_flags[-1]) {
+                               # Add a "and" to the message string.
+                               $message_string = "$message_string" . " and ";
+                       }
+               }
 
-               # Display notice.
-               print "<h3>This address is marked as $network_flag_name.</h3>\n";
+               # Display the generated notice.
+               print "<h3>$message_string</h3>\n";
                print "<br>\n";
        }