]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/commitdiff
wireguard.cgi: Show origin of the connected peer
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Apr 2024 17:32:06 +0000 (19:32 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Apr 2025 14:47:53 +0000 (16:47 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/wireguard.cgi

index d2bc80247a9e8f3a5d9eebe82dd33eed2954c188..f319954ccbe86a65c70ce8b4e4e05ea3d2455e7b 100644 (file)
@@ -27,6 +27,7 @@ use CGI::Carp 'fatalsToBrowser';
 
 require "/var/ipfire/general-functions.pl";
 require "${General::swroot}/header.pl";
+require "${General::swroot}/location-functions.pl";
 
 my $INTF = "wg0";
 my @errormessages = ();
@@ -150,7 +151,7 @@ END
                                        $Lang::tr{'remark'}
                                </th>
 
-                               <th width='10%'>
+                               <th width='10%' colspan='2'>
                                        $Lang::tr{'status'}
                                </th>
 
@@ -172,6 +173,8 @@ END
                my $remarks  = $peers{$key}[7];
 
                my $connected = $Lang::tr{'capsclosed'};
+               my $country   = "ZZ";
+               my $location  = "";
 
                my $gif = ($enabled eq "on") ? "on.gif" : "off.gif";
                my @status = ("status");
@@ -179,6 +182,9 @@ END
                # Fetch the status of the peer (if possible)
                my $status = $dump{$pubkey} || ();
 
+               # Fetch the actual endpoint
+               my ($actual_endpoint, $actual_port) = split(/:/, $status->{"endpoint"}, 2);
+
                # WireGuard performs a handshake very two minutes, so we should be considered online then
                my $is_connected = (time - $status->{"latest-handshake"}) <= 120;
 
@@ -186,6 +192,23 @@ END
                        push(@status, "is-connected");
 
                        $connected = $Lang::tr{'capsopen'};
+
+                       # If we have an endpoint lets lookup the country
+                       if ($actual_endpoint) {
+                               $country = &Location::Functions::lookup_country_code($actual_endpoint);
+
+                               # If we found a country, let's show it
+                               if ($country) {
+                                       my $icon = &Location::Functions::get_flag_icon($country);
+
+                                       $location = <<EOF;
+                                               <a href="country.cgi#$country">
+                                                       <img src="$icon" border='0' align='absmiddle'
+                                                               alt='$country' title='$actual_endpoint:$actual_port - $country' />
+                                               </a>
+EOF
+                               }
+                       }
                }
 
                print <<END;
@@ -202,6 +225,10 @@ END
                                        $connected
                                </td>
 
+                               <td class="@status">
+                                       $location
+                               </td>
+
                                <td class="text-center">
                                        <form method='post'>
                                                <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif'