public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@mandelbit.com>
To: development@lists.ipfire.org
Cc: Antonio Quartulli <antonio@mandelbit.com>
Subject: [PATCH 2/3] ovpnmain.cgi/index.cgi: Use OpenVPN::n2n_status()
Date: Tue, 27 Oct 2026 23:21:09 +0100	[thread overview]
Message-ID: <20261027222110.2642078-3-antonio@mandelbit.com> (raw)
In-Reply-To: <20261027222110.2642078-1-antonio@mandelbit.com>

Both pages now use the same check, so a working N2N tunnel is no longer
shown as DISCONNECTED after an incomplete session attempt.

Fixes: #13897
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 html/cgi-bin/index.cgi    | 12 ++------
 html/cgi-bin/ovpnmain.cgi | 58 ++-------------------------------------
 2 files changed, 5 insertions(+), 65 deletions(-)

diff --git a/html/cgi-bin/index.cgi b/html/cgi-bin/index.cgi
index 0f51ba9ff..b5f23a59a 100644
--- a/html/cgi-bin/index.cgi
+++ b/html/cgi-bin/index.cgi
@@ -20,7 +20,6 @@
 ###############################################################################
 
 use strict;
-use Net::Telnet;
 use Sort::Naturally;
 
 # enable only the following on debugging purpose
@@ -31,6 +30,7 @@ require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 require "${General::swroot}/wireguard-functions.pl";
+require "${General::swroot}/ovpn-functions.pl";
 require "/opt/pakfire/lib/functions.pl";
 
 my %cgiparams=();
@@ -504,17 +504,11 @@ END
 					$count++;
 					my $tport = $ovpnconfig{$dkey}[22];
 					next if ($tport eq '');
-					my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport);
-					$tnet->open('127.0.0.1');
-					my @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/');
-					my @tustate = split(/\,/, $output[1]);
-					my $display;
+					my $display = _('DISCONNECTED');
 					my $display_colour = $Header::colourred;
-					if ( $tustate[1] eq 'CONNECTED' || ($tustate[1] eq 'WAIT')) {
+					if (&OpenVPN::n2n_status($tport) eq "CONNECTED") {
 						$display_colour = $Header::colourgreen;
 						$display = _('CONNECTED');
-					} else {
-						$display = $tustate[1];
 					}
 					if ($count %2){
 						$col = $color{'color22'};
diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi
index 35561f4e7..d28f895cd 100644
--- a/html/cgi-bin/ovpnmain.cgi
+++ b/html/cgi-bin/ovpnmain.cgi
@@ -31,7 +31,6 @@ use MIME::Base32;
 use MIME::Base64;
 use Net::DNS;
 use Net::Ping;
-use Net::Telnet;
 use Sort::Naturally;
 use URI::Encode qw(uri_encode uri_decode);;
 
@@ -39,6 +38,7 @@ require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/header.pl";
 require "${General::swroot}/countries.pl";
 require "${General::swroot}/location-functions.pl";
+require "${General::swroot}/ovpn-functions.pl";
 
 # enable only the following on debugging purpose
 #use warnings;
@@ -1024,60 +1024,6 @@ sub writecollectdconf {
 	&General::system("/usr/local/bin/collectdctrl", "restart");
 }
 
-sub openvpn_status($) {
-	my $port = shift;
-
-	# Create a new Telnet session
-	my $telnet = new Net::Telnet(
-		Port    => $port,
-		Timeout => 1,
-		Errmode => "return",
-	);
-
-	# Connect
-	$telnet->open("127.0.0.1");
-
-	# Send a command
-	my @output = $telnet->cmd(
-		String => "state",
-		Prompt => "/(END.*\n|ERROR:.*\n)/"
-	);
-
-	my ($time, $status) = split(/\,/, $output[1]);
-
-	###
-	#CONNECTING    -- OpenVPN's initial state.
-	#WAIT          -- (Client only) Waiting for initial response from server.
-	#AUTH          -- (Client only) Authenticating with server.
-	#GET_CONFIG    -- (Client only) Downloading configuration options from server.
-	#ASSIGN_IP     -- Assigning IP address to virtual network interface.
-	#ADD_ROUTES    -- Adding routes to system.
-	#CONNECTED     -- Initialization Sequence Completed.
-	#RECONNECTING  -- A restart has occurred.
-	#EXITING       -- A graceful exit is in progress.
-	####
-
-	if ($status eq "CONNECTING") {
-		return "DISCONNECTED";
-	} elsif ($status eq "WAIT") {
-		return "DISCONNECTED";
-	} elsif ($status eq "AUTH") {
-		return "DISCONNECTED";
-	} elsif ($status eq "GET_CONFIG") {
-		return "DISCONNECTED";
-	} elsif ($status eq "ASSIGN_IP") {
-		return "DISCONNECTED";
-	} elsif ($status eq "ADD_ROUTES") {
-		return "DISCONNECTED";
-	} elsif ($status eq "RECONNECTING") {
-		return "CONNECTED";
-	} elsif ($status eq "EXITING") {
-		return "DISCONNECTED";
-	}
-
-	return $status;
-}
-
 # Hook to regenerate the configuration files
 if ($ENV{"REMOTE_ADDR"} eq "") {
 	&writeserverconf();
@@ -5309,7 +5255,7 @@ END
 				my $port = $confighash{$key}[22];
 
 				if ($port ne "") {
-					$connstatus = &openvpn_status($confighash{$key}[22]);
+					$connstatus = &OpenVPN::n2n_status($port);
 				}
 			}
 
-- 
2.55.0



  parent reply	other threads:[~2026-10-27 22:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 22:21 [PATCH 0/3] OpenVPN: Fix N2N connections shown as DISCONNECTED while up Antonio Quartulli
2026-10-27 22:21 ` [PATCH 1/3] ovpn-functions.pl: Add a helper to get the status of N2N connections Antonio Quartulli
2026-10-27 22:21 ` Antonio Quartulli [this message]
2026-10-27 22:21 ` [PATCH 3/3] tests: Add tests for OpenVPN::n2n_status() Antonio Quartulli
2026-10-28 17:28 ` [PATCH 0/3] OpenVPN: Fix N2N connections shown as DISCONNECTED while up Michael Tremer
2026-10-28 19:20   ` Antonio Quartulli

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=20261027222110.2642078-3-antonio@mandelbit.com \
    --to=antonio@mandelbit.com \
    --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