From c25e3d6a1924448fa988de0118b802b7de0a0405 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 17 Apr 2024 19:32:06 +0200 Subject: [PATCH] wireguard.cgi: Show origin of the connected peer Signed-off-by: Michael Tremer --- html/cgi-bin/wireguard.cgi | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/html/cgi-bin/wireguard.cgi b/html/cgi-bin/wireguard.cgi index d2bc80247..f319954cc 100644 --- a/html/cgi-bin/wireguard.cgi +++ b/html/cgi-bin/wireguard.cgi @@ -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'} - + $Lang::tr{'status'} @@ -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 = < + $country + +EOF + } + } } print < + + $location + +