From 28a568201c24dc66622847e379f305e3ab1282cc Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Wed, 11 Jan 2023 12:03:07 -0500 Subject: [PATCH] Handle CONNECTED,ROUTE_ERROR state message When connected, the daemon now reports the state as CONNECTED,ROUTE_ERROR on routing errors that would have been reported as CONNECTED,SUCCESS in the past. To not overly disrupt the current behaviour we treat CONNECTED,ROUTE_ERROR almost the same was as CONNECTED,SUCCESS except that an error is logged and the status window is popped up if not already open for all cases other that CONNECTED,SUCCESS. Further, the icons on the status window, is left at yellow and the status text is set to "Connected with routing errors" in case of ROUTE_ERROR. Tray and menu icons will change to green. Leaving them yellow is not persistent as we do not yet have a state variable in the GUI that distinguishes between "successfully connected" and "connected with route errors". TODO: re-work this CONNECTED state handling based on how critical ROUTE_ERROR is in real use. Signed-off-by: Selva Nair --- openvpn-gui-res.h | 2 ++ openvpn.c | 37 +++++++++++++++++++++++++++++++++---- res/openvpn-gui-res-en.rc | 2 ++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/openvpn-gui-res.h b/openvpn-gui-res.h index 91302b0..fcc45dd 100644 --- a/openvpn-gui-res.h +++ b/openvpn-gui-res.h @@ -259,6 +259,8 @@ #define IDS_NFO_STATE_RETRYING 1262 #define IDS_NFO_STATE_DISCONNECTING 1263 #define IDS_NFO_CONN_CANCELLED 1264 +#define IDS_NFO_STATE_ROUTE_ERROR 1265 +#define IDS_NFO_NOTIFY_ROUTE_ERROR 1266 /* Program Startup Related */ #define IDS_ERR_OPEN_DEBUG_FILE 1301 diff --git a/openvpn.c b/openvpn.c index 41bd94e..bfe01eb 100644 --- a/openvpn.c +++ b/openvpn.c @@ -311,12 +311,33 @@ OnStateChange(connection_t *c, char *data) strncpy_s(c->daemon_state, _countof(c->daemon_state), state, _TRUNCATE); + /* Connected state message could be SUCCESS or ERROR, ROUTE_ERROR. + * We treat both SUCCESS and ROUTE_ERROR similarly to preserve the + * current behaviour but show the status window and do not change + * icons to green if not "SUCCESS". + */ if (strcmp(state, "CONNECTED") == 0) { + bool success = !strcmp(message, "SUCCESS"); + parse_assigned_ip(c, pos + 1); - } - if (strcmp(state, "CONNECTED") == 0 && strcmp(message, "SUCCESS") == 0) - { + + if (!success) /* connection completed with errors */ + { + SetForegroundWindow(c->hwndStatus); + ShowWindow(c->hwndStatus, SW_SHOW); + /* The daemon does not currently log this error. Add a line to the status window */ + if (!strcmp(message, "ROUTE_ERROR")) + { + WriteStatusLog(c, L"ERROR: ", L"Some routes were not successfully added. The connection may not function correctly", false); + } + else + { + WriteStatusLog(c, L"ERROR: ", L"Connection completed with critical errors.", false); + return; + } + } + /* concatenate ipv4 and ipv6 addresses into one string */ WCHAR ip_txt[256]; WCHAR ip[64]; @@ -336,7 +357,8 @@ OnStateChange(connection_t *c, char *data) || (c->state == reconnecting && o.show_balloon == 2)) { TCHAR msg[256]; - LoadLocalizedStringBuf(msg, _countof(msg), IDS_NFO_NOW_CONNECTED, c->config_name); + DWORD id = success ? IDS_NFO_NOW_CONNECTED : IDS_NFO_NOTIFY_ROUTE_ERROR; + LoadLocalizedStringBuf(msg, _countof(msg), id, c->config_name); ShowTrayBalloon(msg, (ip[0] ? ip_txt : _T(""))); } @@ -351,6 +373,13 @@ OnStateChange(connection_t *c, char *data) SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); SetDlgItemTextW(c->hwndStatus, ID_TXT_IP, ip_txt); + + if (!success) + { + SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_ROUTE_ERROR)); + return; + } + SetStatusWinIcon(c->hwndStatus, ID_ICO_CONNECTED); /* Hide Status Window */ diff --git a/res/openvpn-gui-res-en.rc b/res/openvpn-gui-res-en.rc index 9f3f7b6..42117ef 100644 --- a/res/openvpn-gui-res-en.rc +++ b/res/openvpn-gui-res-en.rc @@ -424,6 +424,8 @@ View log file (%ls) for more details." IDS_NFO_SERVICE_ACTIVE_EXIT "You are currently connected (the OpenVPN Service is running). \ You will stay connected even if you exit OpenVPN GUI.\n\n\ Do you want to proceed and exit OpenVPN GUI?" + IDS_NFO_STATE_ROUTE_ERROR "Current State: Connected with route errors" + IDS_NFO_NOTIFY_ROUTE_ERROR "%ls connected with route errors" /* options – Resources */ IDS_NFO_USAGE "--help\t\t\t: Show this message.\n\