diff --git a/main.c b/main.c index 13c09b2..ca4a6d7 100644 --- a/main.c +++ b/main.c @@ -394,6 +394,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM if ( (LOWORD(wParam) >= IDM_DISCONNECTMENU) && (LOWORD(wParam) < IDM_DISCONNECTMENU + MAX_CONFIGS) ) { StopOpenVPN(&o.conn[LOWORD(wParam) - IDM_DISCONNECTMENU]); } + if ( (LOWORD(wParam) >= IDM_RECONNECTMENU) && (LOWORD(wParam) < IDM_RECONNECTMENU + MAX_CONFIGS) ) { + RestartOpenVPN(&o.conn[LOWORD(wParam) - IDM_RECONNECTMENU]); + } if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) { ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW); } diff --git a/openvpn-gui-res.h b/openvpn-gui-res.h index a46b263..34c8647 100644 --- a/openvpn-gui-res.h +++ b/openvpn-gui-res.h @@ -149,6 +149,7 @@ #define IDS_MENU_ASK_STOP_SERVICE 1022 #define IDS_MENU_IMPORT 1023 #define IDS_MENU_CLEARPASS 1024 +#define IDS_MENU_RECONNECT 1025 /* LogViewer Dialog */ #define IDS_ERR_START_LOG_VIEWER 1101 diff --git a/openvpn.c b/openvpn.c index 030c4c9..eb0e0a2 100644 --- a/openvpn.c +++ b/openvpn.c @@ -52,6 +52,7 @@ #define WM_OVPN_STOP (WM_APP + 10) #define WM_OVPN_SUSPEND (WM_APP + 11) +#define WM_OVPN_RESTART (WM_APP + 12) extern options_t o; @@ -1565,7 +1566,7 @@ StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) case ID_RESTART: c->state = reconnecting; SetFocus(GetDlgItem(c->hwndStatus, ID_EDT_LOG)); - ManagementCommand(c, "signal SIGHUP", NULL, regular); + RestartOpenVPN(c); return TRUE; } break; @@ -1628,6 +1629,18 @@ StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) KillTimer (hwndDlg, IDT_STOP_TIMER); } break; + + case WM_OVPN_RESTART: + c = (connection_t *) GetProp(hwndDlg, cfgProp); + /* external messages can trigger when we are not ready -- check the state */ + if (IsWindowEnabled(GetDlgItem(c->hwndStatus, ID_RESTART))) + ManagementCommand(c, "signal SIGHUP", NULL, regular); + if (!o.silent_connection) + { + SetForegroundWindow(c->hwndStatus); + ShowWindow(c->hwndStatus, SW_SHOW); + } + break; } return FALSE; } @@ -1955,6 +1968,11 @@ SuspendOpenVPN(int config) PostMessage(o.conn[config].hwndStatus, WM_OVPN_SUSPEND, 0, 0); } +void +RestartOpenVPN(connection_t *c) +{ + PostMessage(c->hwndStatus, WM_OVPN_RESTART, 0, 0); +} void SetStatusWinIcon(HWND hwndDlg, int iconId) diff --git a/openvpn.h b/openvpn.h index 2bfa1d2..f1d6860 100644 --- a/openvpn.h +++ b/openvpn.h @@ -26,6 +26,7 @@ BOOL StartOpenVPN(connection_t *); void StopOpenVPN(connection_t *); void SuspendOpenVPN(int config); +void RestartOpenVPN(connection_t *); BOOL CheckVersion(); void SetStatusWinIcon(HWND hwndDlg, int IconID); diff --git a/res/openvpn-gui-res-en.rc b/res/openvpn-gui-res-en.rc index 7f521e4..5c80fa3 100644 --- a/res/openvpn-gui-res-en.rc +++ b/res/openvpn-gui-res-en.rc @@ -247,6 +247,7 @@ BEGIN IDS_MENU_CLOSE "Exit" IDS_MENU_CONNECT "Connect" IDS_MENU_DISCONNECT "Disconnect" + IDS_MENU_RECONNECT "Reconnect" IDS_MENU_STATUS "Show Status" IDS_MENU_VIEWLOG "View Log" IDS_MENU_EDITCONFIG "Edit Config" diff --git a/tray.c b/tray.c index ffbf3f3..7227e5d 100644 --- a/tray.c +++ b/tray.c @@ -63,6 +63,7 @@ CreatePopupMenus() if (o.service_only == 0) { AppendMenu(hMenu, MF_STRING, IDM_CONNECTMENU, LoadLocalizedString(IDS_MENU_CONNECT)); AppendMenu(hMenu, MF_STRING, IDM_DISCONNECTMENU, LoadLocalizedString(IDS_MENU_DISCONNECT)); + AppendMenu(hMenu, MF_STRING, IDM_RECONNECTMENU, LoadLocalizedString(IDS_MENU_RECONNECT)); AppendMenu(hMenu, MF_STRING, IDM_STATUSMENU, LoadLocalizedString(IDS_MENU_STATUS)); AppendMenu(hMenu, MF_SEPARATOR, 0, 0); } @@ -117,6 +118,7 @@ CreatePopupMenus() if (o.service_only == 0) { AppendMenu(hMenuConn[i], MF_STRING, IDM_CONNECTMENU + i, LoadLocalizedString(IDS_MENU_CONNECT)); AppendMenu(hMenuConn[i], MF_STRING, IDM_DISCONNECTMENU + i, LoadLocalizedString(IDS_MENU_DISCONNECT)); + AppendMenu(hMenuConn[i], MF_STRING, IDM_RECONNECTMENU + i, LoadLocalizedString(IDS_MENU_RECONNECT)); AppendMenu(hMenuConn[i], MF_STRING, IDM_STATUSMENU + i, LoadLocalizedString(IDS_MENU_STATUS)); AppendMenu(hMenuConn[i], MF_SEPARATOR, 0, 0); } @@ -349,18 +351,21 @@ SetMenuStatus(connection_t *c, conn_state_t state) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED); + EnableMenuItem(hMenu, IDM_RECONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_GRAYED); } else if (state == connecting || state == resuming || state == connected) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED); + EnableMenuItem(hMenu, IDM_RECONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED); } else if (state == disconnecting) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED); + EnableMenuItem(hMenu, IDM_RECONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED); } if (c->flags & (FLAG_SAVE_AUTH_PASS | FLAG_SAVE_KEY_PASS)) @@ -384,18 +389,21 @@ SetMenuStatus(connection_t *c, conn_state_t state) { EnableMenuItem(hMenuConn[i], IDM_CONNECTMENU + i, MF_ENABLED); EnableMenuItem(hMenuConn[i], IDM_DISCONNECTMENU + i, MF_GRAYED); + EnableMenuItem(hMenuConn[i], IDM_RECONNECTMENU + i, MF_GRAYED); EnableMenuItem(hMenuConn[i], IDM_STATUSMENU + i, MF_GRAYED); } else if (state == connecting || state == resuming || state == connected) { EnableMenuItem(hMenuConn[i], IDM_CONNECTMENU + i, MF_GRAYED); EnableMenuItem(hMenuConn[i], IDM_DISCONNECTMENU + i, MF_ENABLED); + EnableMenuItem(hMenuConn[i], IDM_RECONNECTMENU + i, MF_ENABLED); EnableMenuItem(hMenuConn[i], IDM_STATUSMENU + i, MF_ENABLED); } else if (state == disconnecting) { EnableMenuItem(hMenuConn[i], IDM_CONNECTMENU + i, MF_GRAYED); EnableMenuItem(hMenuConn[i], IDM_DISCONNECTMENU + i, MF_GRAYED); + EnableMenuItem(hMenuConn[i], IDM_RECONNECTMENU + i, MF_GRAYED); EnableMenuItem(hMenuConn[i], IDM_STATUSMENU + i, MF_ENABLED); } if (c->flags & (FLAG_SAVE_AUTH_PASS | FLAG_SAVE_KEY_PASS)) diff --git a/tray.h b/tray.h index 88ee852..c8dd3df 100644 --- a/tray.h +++ b/tray.h @@ -42,6 +42,7 @@ #define IDM_EDITMENU (MAX_CONFIGS + IDM_VIEWLOGMENU) #define IDM_PASSPHRASEMENU (MAX_CONFIGS + IDM_EDITMENU) #define IDM_CLEARPASSMENU (MAX_CONFIGS + IDM_PASSPHRASEMENU) +#define IDM_RECONNECTMENU (MAX_CONFIGS + IDM_CLEARPASSMENU) void CreatePopupMenus(); void OnNotifyTray(LPARAM);