refactor option handling code

pull/1/head
Heiko Hund 2010-04-09 06:01:30 +02:00
parent b0c1bd562c
commit a6e6d88115
18 changed files with 666 additions and 682 deletions

View File

@ -33,7 +33,7 @@
#include "options.h" #include "options.h"
#include "registry.h" #include "registry.h"
extern struct options o; extern options_t o;
static const LANGID fallbackLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL); static const LANGID fallbackLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL);
static LANGID gui_language; static LANGID gui_language;

20
main.c
View File

@ -54,7 +54,7 @@ TCHAR szClassName[ ] = _T("OpenVPN-GUI");
TCHAR szTitleText[ ] = _T("OpenVPN"); TCHAR szTitleText[ ] = _T("OpenVPN");
/* Options structure */ /* Options structure */
struct options o; options_t o;
int WINAPI WinMain (HINSTANCE hThisInstance, int WINAPI WinMain (HINSTANCE hThisInstance,
UNUSED HINSTANCE hPrevInstance, UNUSED HINSTANCE hPrevInstance,
@ -68,7 +68,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
/* initialize options to default state */ /* initialize options to default state */
init_options (&o); InitOptions(&o);
#ifdef DEBUG #ifdef DEBUG
/* Open debug file for output */ /* Open debug file for output */
@ -109,7 +109,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
/* Parse command-line options */ /* Parse command-line options */
Createargcargv(&o, GetCommandLine()); ProcessCommandLine(&o, GetCommandLine());
/* Check if a previous instance is already running. */ /* Check if a previous instance is already running. */
if ((FindWindow (szClassName, NULL)) != NULL) if ((FindWindow (szClassName, NULL)) != NULL)
@ -224,7 +224,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
StopOpenVPN(LOWORD(wParam) - IDM_DISCONNECTMENU); StopOpenVPN(LOWORD(wParam) - IDM_DISCONNECTMENU);
} }
if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) { if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) {
ShowWindow(o.cnn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW); ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
} }
if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) { if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) {
ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU); ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU);
@ -281,13 +281,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
/* Suspend running connections */ /* Suspend running connections */
for (i=0; i<o.num_configs; i++) for (i=0; i<o.num_configs; i++)
{ {
if (o.cnn[i].connect_status == CONNECTED) if (o.conn[i].state == connected)
SuspendOpenVPN(i); SuspendOpenVPN(i);
} }
/* Wait for all connections to suspend */ /* Wait for all connections to suspend */
for (i=0; i<10; i++, Sleep(500)) for (i=0; i<10; i++, Sleep(500))
if (CountConnectedState(SUSPENDING) == 0) break; if (CountConnState(suspending) == 0) break;
} }
return FALSE; return FALSE;
@ -296,11 +296,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
for (i=0; i<o.num_configs; i++) for (i=0; i<o.num_configs; i++)
{ {
/* Restart suspend connections */ /* Restart suspend connections */
if (o.cnn[i].connect_status == SUSPENDED) if (o.conn[i].state == suspended)
StartOpenVPN(i); StartOpenVPN(i);
/* If some connection never reached SUSPENDED state */ /* If some connection never reached SUSPENDED state */
if (o.cnn[i].connect_status == SUSPENDING) if (o.conn[i].state == suspending)
StopOpenVPN(i); StopOpenVPN(i);
} }
return FALSE; return FALSE;
@ -392,7 +392,7 @@ void CloseApplication(HWND hwnd)
{ {
int i, ask_exit=0; int i, ask_exit=0;
if (o.service_running == SERVICE_CONNECTED) if (o.service_state == service_connected)
{ {
if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_SERVICE_ACTIVE_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO) if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_SERVICE_ACTIVE_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO)
{ {
@ -401,7 +401,7 @@ void CloseApplication(HWND hwnd)
} }
for (i=0; i < o.num_configs; i++) { for (i=0; i < o.num_configs; i++) {
if (o.cnn[i].connect_status != 0) { if (o.conn[i].state != disconnected) {
ask_exit=1; ask_exit=1;
break; break;
} }

168
openvpn.c
View File

@ -36,6 +36,7 @@
#include "main.h" #include "main.h"
#include "openvpn.h" #include "openvpn.h"
#include "openvpn_monitor_process.h" #include "openvpn_monitor_process.h"
#include "openvpn_config.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "options.h" #include "options.h"
#include "scripts.h" #include "scripts.h"
@ -44,7 +45,7 @@
#include "passphrase.h" #include "passphrase.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
/* /*
* Creates a unique exit_event name based on the * Creates a unique exit_event name based on the
@ -52,15 +53,15 @@ extern struct options o;
*/ */
int CreateExitEvent(int config) int CreateExitEvent(int config)
{ {
o.cnn[config].exit_event = NULL; o.conn[config].exit_event = NULL;
if (o.oldversion == 1) if (o.oldversion == 1)
{ {
_sntprintf_0(o.cnn[config].exit_event_name, _T("openvpn_exit")); _sntprintf_0(o.conn[config].exit_event_name, _T("openvpn_exit"));
o.cnn[config].exit_event = CreateEvent (NULL, o.conn[config].exit_event = CreateEvent (NULL,
TRUE, TRUE,
FALSE, FALSE,
o.cnn[config].exit_event_name); o.conn[config].exit_event_name);
if (o.cnn[config].exit_event == NULL) if (o.conn[config].exit_event == NULL)
{ {
if (GetLastError() == ERROR_ACCESS_DENIED) if (GetLastError() == ERROR_ACCESS_DENIED)
{ {
@ -70,22 +71,22 @@ int CreateExitEvent(int config)
else else
{ {
/* error creating exit event */ /* error creating exit event */
ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.cnn[config].exit_event_name); ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.conn[config].exit_event_name);
} }
return(false); return(false);
} }
} }
else else
{ {
_sntprintf_0(o.cnn[config].exit_event_name, _T("openvpngui_exit_event_%d"), config); _sntprintf_0(o.conn[config].exit_event_name, _T("openvpngui_exit_event_%d"), config);
o.cnn[config].exit_event = CreateEvent (NULL, o.conn[config].exit_event = CreateEvent (NULL,
TRUE, TRUE,
FALSE, FALSE,
o.cnn[config].exit_event_name); o.conn[config].exit_event_name);
if (o.cnn[config].exit_event == NULL) if (o.conn[config].exit_event == NULL)
{ {
/* error creating exit event */ /* error creating exit event */
ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.cnn[config].exit_event_name); ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.conn[config].exit_event_name);
return(false); return(false);
} }
} }
@ -159,8 +160,8 @@ int StartOpenVPN(int config)
{ {
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
{ {
if ((o.cnn[i].connect_status != DISCONNECTED) && if ((o.conn[i].state != disconnected) &&
(o.cnn[i].connect_status != DISCONNECTING)) (o.conn[i].state != disconnecting))
{ {
is_connected=1; is_connected=1;
break; break;
@ -183,8 +184,8 @@ int StartOpenVPN(int config)
} }
/* Clear connection unique vars */ /* Clear connection unique vars */
o.cnn[config].failed_psw = 0; o.conn[config].failed_psw = 0;
CLEAR (o.cnn[config].ip); CLEAR (o.conn[config].ip);
/* Create our exit event */ /* Create our exit event */
if (!CreateExitEvent(config)) if (!CreateExitEvent(config))
@ -209,13 +210,13 @@ int StartOpenVPN(int config)
if (o.oldversion == 1) if (o.oldversion == 1)
{ {
_sntprintf_0(command_line, _T("openvpn --config \"%s\" %s"), _sntprintf_0(command_line, _T("openvpn --config \"%s\" %s"),
o.cnn[config].config_file, proxy_string); o.conn[config].config_file, proxy_string);
} }
else else
{ {
_sntprintf_0(command_line, _T("openvpn --service %s 0 --config \"%s\" %s"), _sntprintf_0(command_line, _T("openvpn --service %s 0 --config \"%s\" %s"),
o.cnn[config].exit_event_name, o.conn[config].exit_event_name,
o.cnn[config].config_file, o.conn[config].config_file,
proxy_string); proxy_string);
} }
@ -298,7 +299,7 @@ int StartOpenVPN(int config)
{ {
/* Close Handle failed */ /* Close Handle failed */
ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP); ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP);
CloseHandle (o.cnn[config].exit_event); CloseHandle (o.conn[config].exit_event);
return(0); return(0);
} }
hOutputReadTmp=NULL; hOutputReadTmp=NULL;
@ -323,7 +324,7 @@ int StartOpenVPN(int config)
TRUE, TRUE,
priority | CREATE_NO_WINDOW, priority | CREATE_NO_WINDOW,
NULL, NULL,
o.cnn[config].config_dir, o.conn[config].config_dir,
&start_info, &start_info,
&proc_info)) &proc_info))
{ {
@ -331,7 +332,7 @@ int StartOpenVPN(int config)
ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS, ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS,
o.exe_path, o.exe_path,
command_line, command_line,
o.cnn[config].config_dir); o.conn[config].config_dir);
goto failed; goto failed;
} }
@ -347,7 +348,7 @@ int StartOpenVPN(int config)
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE); ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE);
CloseHandle (o.cnn[config].exit_event); CloseHandle (o.conn[config].exit_event);
return(false); return(false);
} }
hOutputWrite = NULL; hOutputWrite = NULL;
@ -355,11 +356,11 @@ int StartOpenVPN(int config)
hErrorWrite = NULL; hErrorWrite = NULL;
/* Save StdIn and StdOut handles in our options struct */ /* Save StdIn and StdOut handles in our options struct */
o.cnn[config].hStdIn = hInputWrite; o.conn[config].hStdIn = hInputWrite;
o.cnn[config].hStdOut = hOutputRead; o.conn[config].hStdOut = hOutputRead;
/* Save Process Handle */ /* Save Process Handle */
o.cnn[config].hProcess=proc_info.hProcess; o.conn[config].hProcess=proc_info.hProcess;
/* Start Thread to show Status Dialog */ /* Start Thread to show Status Dialog */
@ -378,7 +379,7 @@ int StartOpenVPN(int config)
return(true); return(true);
failed: failed:
if (o.cnn[config].exit_event) CloseHandle (o.cnn[config].exit_event); if (o.conn[config].exit_event) CloseHandle (o.conn[config].exit_event);
if (hOutputWrite) CloseHandle (hOutputWrite); if (hOutputWrite) CloseHandle (hOutputWrite);
if (hOutputRead) CloseHandle (hOutputRead); if (hOutputRead) CloseHandle (hOutputRead);
if (hInputWrite) CloseHandle (hInputWrite); if (hInputWrite) CloseHandle (hInputWrite);
@ -391,32 +392,32 @@ failed:
void StopOpenVPN(int config) void StopOpenVPN(int config)
{ {
o.cnn[config].connect_status = DISCONNECTING; o.conn[config].state = disconnecting;
if (o.cnn[config].exit_event) { if (o.conn[config].exit_event) {
/* Run Disconnect script */ /* Run Disconnect script */
RunDisconnectScript(config, false); RunDisconnectScript(config, false);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE);
SetMenuStatus(config, DISCONNECTING); SetMenuStatus(config, disconnecting);
/* UserInfo: waiting for OpenVPN termination... */ /* UserInfo: waiting for OpenVPN termination... */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_WAIT_TERM)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_WAIT_TERM));
SetEvent(o.cnn[config].exit_event); SetEvent(o.conn[config].exit_event);
} }
} }
void SuspendOpenVPN(int config) void SuspendOpenVPN(int config)
{ {
o.cnn[config].connect_status = SUSPENDING; o.conn[config].state = suspending;
o.cnn[config].restart = true; o.conn[config].restart = true;
if (o.cnn[config].exit_event) { if (o.conn[config].exit_event) {
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE);
SetMenuStatus(config, DISCONNECTING); SetMenuStatus(config, disconnecting);
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_WAIT_TERM)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_WAIT_TERM));
SetEvent(o.cnn[config].exit_event); SetEvent(o.conn[config].exit_event);
} }
} }
@ -426,13 +427,13 @@ void StopAllOpenVPN()
int i; int i;
for(i=0; i < o.num_configs; i++) { for(i=0; i < o.num_configs; i++) {
if(o.cnn[i].connect_status != DISCONNECTED) if(o.conn[i].state != disconnected)
StopOpenVPN(i); StopOpenVPN(i);
} }
/* Wait for all connections to terminate (Max 5 sec) */ /* Wait for all connections to terminate (Max 5 sec) */
for (i=0; i<20; i++, Sleep(250)) for (i=0; i<20; i++, Sleep(250))
if (CountConnectedState(DISCONNECTED) == o.num_configs) break; if (CountConnState(disconnected) == o.num_configs) break;
} }
@ -516,12 +517,12 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
switch (LOWORD(wParam)) { switch (LOWORD(wParam)) {
case ID_DISCONNECT: case ID_DISCONNECT:
SetFocus(GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG)); SetFocus(GetDlgItem(o.conn[config].hwndStatus, ID_EDT_LOG));
StopOpenVPN(config); StopOpenVPN(config);
return TRUE; return TRUE;
case ID_HIDE: case ID_HIDE:
if (o.cnn[config].connect_status != DISCONNECTED) if (o.conn[config].state != disconnected)
{ {
ShowWindow(hwndDlg, SW_HIDE); ShowWindow(hwndDlg, SW_HIDE);
} }
@ -532,8 +533,8 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
return TRUE; return TRUE;
case ID_RESTART: case ID_RESTART:
SetFocus(GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG)); SetFocus(GetDlgItem(o.conn[config].hwndStatus, ID_EDT_LOG));
o.cnn[config].restart = true; o.conn[config].restart = true;
StopOpenVPN(config); StopOpenVPN(config);
return TRUE; return TRUE;
} }
@ -543,14 +544,14 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (wParam == TRUE) if (wParam == TRUE)
{ {
config = (UINT) GetProp(hwndDlg, cfgProp); config = (UINT) GetProp(hwndDlg, cfgProp);
if (o.cnn[config].hwndStatus) if (o.conn[config].hwndStatus)
SetFocus(GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG)); SetFocus(GetDlgItem(o.conn[config].hwndStatus, ID_EDT_LOG));
} }
return FALSE; return FALSE;
case WM_CLOSE: case WM_CLOSE:
config = (UINT) GetProp(hwndDlg, cfgProp); config = (UINT) GetProp(hwndDlg, cfgProp);
if (o.cnn[config].connect_status != DISCONNECTED) if (o.conn[config].state != disconnected)
{ {
ShowWindow(hwndDlg, SW_HIDE); ShowWindow(hwndDlg, SW_HIDE);
} }
@ -587,7 +588,7 @@ int AutoStartConnections()
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
{ {
if (o.cnn[i].auto_connect) if (o.conn[i].auto_connect)
StartOpenVPN(i); StartOpenVPN(i);
} }
@ -604,7 +605,7 @@ int VerifyAutoConnections()
match = false; match = false;
for (j=0; j < MAX_CONFIGS; j++) for (j=0; j < MAX_CONFIGS; j++)
{ {
if (_tcsicmp(o.cnn[j].config_file, o.auto_connect[i]) == 0) if (_tcsicmp(o.conn[j].config_file, o.auto_connect[i]) == 0)
{ {
match=true; match=true;
break; break;
@ -858,42 +859,27 @@ int CheckVersion()
return(1); return(1);
} }
/* Return num of connections with Status = CheckVal */
int CountConnectedState(int CheckVal)
{
int i;
int count=0;
for (i=0; i < o.num_configs; i++)
{
if (o.cnn[i].connect_status == CheckVal)
count++;
}
return (count);
}
void CheckAndSetTrayIcon() void CheckAndSetTrayIcon()
{ {
/* Show green icon if service is running */ /* Show green icon if service is running */
if (o.service_running == SERVICE_CONNECTED) if (o.service_state == service_connected)
{ {
SetTrayIcon(CONNECTED); SetTrayIcon(connected);
return; return;
} }
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
if (CountConnectedState(CONNECTED) != 0) if (CountConnState(connected) != 0)
SetTrayIcon(CONNECTED); SetTrayIcon(connected);
else else
{ {
if ((CountConnectedState(CONNECTING) != 0) || if ((CountConnState(connecting) != 0) ||
(CountConnectedState(RECONNECTING) != 0) || (CountConnState(reconnecting) != 0) ||
(o.service_running == SERVICE_CONNECTING)) (o.service_state == service_connecting))
SetTrayIcon(CONNECTING); SetTrayIcon(connecting);
else else
SetTrayIcon(DISCONNECTED); SetTrayIcon(disconnected);
} }
} }
@ -905,31 +891,31 @@ void ThreadOpenVPNStatus(int config)
MSG messages; MSG messages;
/* Cut of extention from config filename. */ /* Cut of extention from config filename. */
_tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name)); _tcsncpy(conn_name, o.conn[config].config_file, _tsizeof(conn_name));
conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0; conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0;
if (o.cnn[config].restart) if (o.conn[config].restart)
{ {
/* UserInfo: Connecting */ /* UserInfo: Connecting */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTING); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTING);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), TRUE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), TRUE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), TRUE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), TRUE);
SetFocus(GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG)); SetFocus(GetDlgItem(o.conn[config].hwndStatus, ID_EDT_LOG));
o.cnn[config].restart = false; o.conn[config].restart = false;
} }
else else
{ {
/* Create and Show Status Dialog */ /* Create and Show Status Dialog */
o.cnn[config].hwndStatus = CreateLocalizedDialogParam(ID_DLG_STATUS, StatusDialogFunc, config); o.conn[config].hwndStatus = CreateLocalizedDialogParam(ID_DLG_STATUS, StatusDialogFunc, config);
if (!o.cnn[config].hwndStatus) if (!o.conn[config].hwndStatus)
ExitThread(1); ExitThread(1);
/* UserInfo: Connecting */ /* UserInfo: Connecting */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING));
SetWindowText(o.cnn[config].hwndStatus, LoadLocalizedString(IDS_NFO_CONNECTION_XXX, conn_name)); SetWindowText(o.conn[config].hwndStatus, LoadLocalizedString(IDS_NFO_CONNECTION_XXX, conn_name));
if (o.silent_connection[0]=='0') if (o.silent_connection[0]=='0')
ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); ShowWindow(o.conn[config].hwndStatus, SW_SHOW);
} }
@ -948,7 +934,7 @@ void ThreadOpenVPNStatus(int config)
/* Run the message loop. It will run until GetMessage() returns 0 */ /* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0)) while (GetMessage (&messages, NULL, 0, 0))
{ {
if(!IsDialogMessage(o.cnn[config].hwndStatus, &messages)) if(!IsDialogMessage(o.conn[config].hwndStatus, &messages))
{ {
TranslateMessage(&messages); TranslateMessage(&messages);
DispatchMessage(&messages); DispatchMessage(&messages);

View File

@ -33,7 +33,6 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
int AutoStartConnections(); int AutoStartConnections();
int VerifyAutoConnections(); int VerifyAutoConnections();
int CheckVersion(); int CheckVersion();
int CountConnectedState(int CheckVal);
void CheckAndSetTrayIcon(); void CheckAndSetTrayIcon();
void SetStatusWinIcon(HWND hwndDlg, int IconID); void SetStatusWinIcon(HWND hwndDlg, int IconID);
void ThreadOpenVPNStatus(int status) __attribute__ ((noreturn)); void ThreadOpenVPNStatus(int status) __attribute__ ((noreturn));

View File

@ -35,7 +35,7 @@ typedef enum
match_dir match_dir
} match_t; } match_t;
extern struct options o; extern options_t o;
static match_t static match_t
match(const WIN32_FIND_DATA *find, const TCHAR *ext) match(const WIN32_FIND_DATA *find, const TCHAR *ext)
@ -65,7 +65,7 @@ ConfigAlreadyExists(TCHAR *newconfig)
int i; int i;
for (i = 0; i < o.num_configs; ++i) for (i = 0; i < o.num_configs; ++i)
{ {
if (_tcsicmp(o.cnn[i].config_file, newconfig) == 0) if (_tcsicmp(o.conn[i].config_file, newconfig) == 0)
return true; return true;
} }
return false; return false;
@ -75,7 +75,7 @@ ConfigAlreadyExists(TCHAR *newconfig)
static void static void
AddConfigFileToList(int config, TCHAR *filename, TCHAR *config_dir) AddConfigFileToList(int config, TCHAR *filename, TCHAR *config_dir)
{ {
connection_t *conn = &o.cnn[config]; connection_t *conn = &o.conn[config];
int i; int i;
_tcsncpy(conn->config_file, filename, _tsizeof(conn->config_file) - 1); _tcsncpy(conn->config_file, filename, _tsizeof(conn->config_file) - 1);
@ -178,3 +178,39 @@ BuildFileList()
} }
} }
/*
* Returns TRUE if option exist in config file.
*/
bool
ConfigFileOptionExist(int config, const char *option)
{
FILE *fp;
char line[256];
TCHAR path[MAX_PATH];
_tcsncpy(path, o.conn[config].config_dir, _tsizeof(path));
if (path[_tcslen(path) - 1] != _T('\\'))
_tcscat(path, _T("\\"));
_tcsncat(path, o.conn[config].config_file, _tsizeof(path) - _tcslen(path) - 1);
fp = _tfopen(path, _T("r"));
if (fp == NULL)
{
ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, path);
return false;
}
while (fgets(line, sizeof(line), fp))
{
if (strncmp(line, option, sizeof(option)) == 0)
{
fclose(fp);
return true;
}
}
fclose(fp);
return false;
}

View File

@ -22,6 +22,9 @@
#ifndef OPENVPN_CONFIG_H #ifndef OPENVPN_CONFIG_H
#define OPENVPN_CONFIG_H #define OPENVPN_CONFIG_H
#include "main.h"
void BuildFileList(); void BuildFileList();
bool ConfigFileOptionExist(int, const char *);
#endif #endif

View File

@ -38,7 +38,7 @@
#include "tray.h" #include "tray.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
/* Wait for a complete line (CR/LF) and return it. /* Wait for a complete line (CR/LF) and return it.
* Return values: * Return values:
@ -203,29 +203,29 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
RunConnectScript(config, false); RunConnectScript(config, false);
/* Save time when we got connected. */ /* Save time when we got connected. */
o.cnn[config].connected_since = time(NULL); o.conn[config].connected_since = time(NULL);
o.cnn[config].connect_status = CONNECTED; o.conn[config].state = connected;
SetMenuStatus(config, CONNECTED); SetMenuStatus(config, connected);
SetTrayIcon(CONNECTED); SetTrayIcon(connected);
/* Remove Proxy Auth file */ /* Remove Proxy Auth file */
DeleteFile(o.proxy_authfile); DeleteFile(o.proxy_authfile);
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.conn[config].failed_psw_attempts = 0;
/* UserInfo: Connected */ /* UserInfo: Connected */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTED); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTED);
/* Show Tray Balloon msg */ /* Show Tray Balloon msg */
if (o.show_balloon[0] != '0') if (o.show_balloon[0] != '0')
{ {
LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.conn[config].config_name);
if (_tcslen(o.cnn[config].ip) > 0) if (_tcslen(o.conn[config].ip) > 0)
{ {
ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.conn[config].ip));
} }
else else
{ {
@ -234,7 +234,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
} }
/* Hide Status Window */ /* Hide Status Window */
ShowWindow(o.cnn[config].hwndStatus, SW_HIDE); ShowWindow(o.conn[config].hwndStatus, SW_HIDE);
} }
/* Check for failed passphrase log message */ /* Check for failed passphrase log message */
@ -244,9 +244,9 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
(strstr(line, "Received AUTH_FAILED control message") != NULL) || (strstr(line, "Received AUTH_FAILED control message") != NULL) ||
(strstr(line, "Auth username is empty") != NULL)) (strstr(line, "Auth username is empty") != NULL))
{ {
o.cnn[config].failed_psw_attempts++; o.conn[config].failed_psw_attempts++;
o.cnn[config].failed_psw=1; o.conn[config].failed_psw=1;
o.cnn[config].restart=true; o.conn[config].restart=true;
} }
/* Check for "certificate has expired" message */ /* Check for "certificate has expired" message */
@ -280,10 +280,10 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
#ifdef _UNICODE #ifdef _UNICODE
/* Convert the IP address to Unicode */ /* Convert the IP address to Unicode */
o.cnn[config].ip[0] = _T('\0'); o.conn[config].ip[0] = _T('\0');
MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.cnn[config].ip, _tsizeof(o.cnn[config].ip)); MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.conn[config].ip, _tsizeof(o.conn[config].ip));
#else #else
strncpy(o.cnn[config].ip, ip_addr, sizeof(o.cnn[config].ip)); strncpy(o.conn[config].ip, ip_addr, sizeof(o.conn[config].ip));
#endif #endif
} }
} }
@ -298,12 +298,12 @@ void monitor_openvpnlog_while_connected(int config, char *line)
if (strstr(line, "process restarting") != NULL) if (strstr(line, "process restarting") != NULL)
{ {
/* Set connect_status = ReConnecting */ /* Set connect_status = ReConnecting */
o.cnn[config].connect_status = RECONNECTING; o.conn[config].state = reconnecting;
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Set Status Window Controls "ReConnecting" */ /* Set Status Window Controls "ReConnecting" */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_RECONNECTING)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_RECONNECTING));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTING); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTING);
} }
} }
@ -319,20 +319,20 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
/* Check for Connected message */ /* Check for Connected message */
if (strstr(line, o.connect_string) != NULL) if (strstr(line, o.connect_string) != NULL)
{ {
o.cnn[config].connect_status = CONNECTED; o.conn[config].state = connected;
SetTrayIcon(CONNECTED); SetTrayIcon(connected);
/* Set Status Window Controls "Connected" */ /* Set Status Window Controls "Connected" */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTED); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTED);
/* Show Tray Balloon msg */ /* Show Tray Balloon msg */
if (o.show_balloon[0] == '2') if (o.show_balloon[0] == '2')
{ {
LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.conn[config].config_name);
if (_tcslen(o.cnn[config].ip) > 0) if (_tcslen(o.conn[config].ip) > 0)
{ {
ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.conn[config].ip));
} }
else else
{ {
@ -348,9 +348,9 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
(strstr(line, "Received AUTH_FAILED control message") != NULL) || (strstr(line, "Received AUTH_FAILED control message") != NULL) ||
(strstr(line, "Auth username is empty") != NULL)) (strstr(line, "Auth username is empty") != NULL))
{ {
o.cnn[config].failed_psw_attempts++; o.conn[config].failed_psw_attempts++;
o.cnn[config].failed_psw=1; o.conn[config].failed_psw=1;
o.cnn[config].restart=true; o.conn[config].restart=true;
} }
/* Check for "certificate has expired" message */ /* Check for "certificate has expired" message */
@ -384,10 +384,10 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
#ifdef _UNICODE #ifdef _UNICODE
/* Convert the IP address to Unicode */ /* Convert the IP address to Unicode */
o.cnn[config].ip[0] = _T('\0'); o.conn[config].ip[0] = _T('\0');
MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.cnn[config].ip, _tsizeof(o.cnn[config].ip)); MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.conn[config].ip, _tsizeof(o.conn[config].ip));
#else #else
strncpy(o.cnn[config].ip, ip_addr, sizeof(o.cnn[config].ip)); strncpy(o.conn[config].ip, ip_addr, sizeof(o.conn[config].ip));
#endif #endif
} }
} }
@ -416,25 +416,25 @@ void WatchOpenVPNProcess(int config)
filemode[0] = _T('a'); filemode[0] = _T('a');
/* Set Connect_Status = "Connecting" */ /* Set Connect_Status = "Connecting" */
o.cnn[config].connect_status = CONNECTING; o.conn[config].state = connecting;
/* Set Tray Icon = "Connecting" if no other connections are running */ /* Set Tray Icon = "Connecting" if no other connections are running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Set MenuStatus = "Connecting" */ /* Set MenuStatus = "Connecting" */
SetMenuStatus(config, CONNECTING); SetMenuStatus(config, connecting);
/* Clear failed_password flag */ /* Clear failed_password flag */
o.cnn[config].failed_psw = 0; o.conn[config].failed_psw = 0;
/* Open log file */ /* Open log file */
if ((fd=_tfopen(o.cnn[config].log_path, filemode)) == NULL) if ((fd=_tfopen(o.conn[config].log_path, filemode)) == NULL)
ShowLocalizedMsg(IDS_ERR_OPEN_LOG_WRITE, o.cnn[config].log_path); ShowLocalizedMsg(IDS_ERR_OPEN_LOG_WRITE, o.conn[config].log_path);
LogWindow = GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG); LogWindow = GetDlgItem(o.conn[config].hwndStatus, ID_EDT_LOG);
while(TRUE) while(TRUE)
{ {
if ((ret=ReadLineFromStdOut(o.cnn[config].hStdOut, config, line)) == 1) if ((ret=ReadLineFromStdOut(o.conn[config].hStdOut, config, line)) == 1)
{ {
/* Do nothing if line length = 0 */ /* Do nothing if line length = 0 */
@ -469,13 +469,13 @@ void WatchOpenVPNProcess(int config)
SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) line); SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) line);
#endif #endif
if (o.cnn[config].connect_status == CONNECTING) /* Connecting state */ if (o.conn[config].state == connecting) /* Connecting state */
monitor_openvpnlog_while_connecting(config, line); monitor_openvpnlog_while_connecting(config, line);
if (o.cnn[config].connect_status == CONNECTED) /* Connected state */ if (o.conn[config].state == connected) /* Connected state */
monitor_openvpnlog_while_connected(config, line); monitor_openvpnlog_while_connected(config, line);
if (o.cnn[config].connect_status == RECONNECTING) /* ReConnecting state */ if (o.conn[config].state == reconnecting) /* ReConnecting state */
monitor_openvpnlog_while_reconnecting(config, line); monitor_openvpnlog_while_reconnecting(config, line);
} }
else break; else break;
@ -489,56 +489,56 @@ void WatchOpenVPNProcess(int config)
if (fd != NULL) fclose(fd); if (fd != NULL) fclose(fd);
/* Close StdIn/StdOut handles */ /* Close StdIn/StdOut handles */
CloseHandle(o.cnn[config].hStdIn); CloseHandle(o.conn[config].hStdIn);
CloseHandle(o.cnn[config].hStdOut); CloseHandle(o.conn[config].hStdOut);
/* Close exitevent handle */ /* Close exitevent handle */
CloseHandle(o.cnn[config].exit_event); CloseHandle(o.conn[config].exit_event);
o.cnn[config].exit_event = NULL; o.conn[config].exit_event = NULL;
/* Enable/Disable menuitems for this connections */ /* Enable/Disable menuitems for this connections */
SetMenuStatus(config, DISCONNECTING); SetMenuStatus(config, disconnecting);
/* Remove Proxy Auth file */ /* Remove Proxy Auth file */
DeleteFile(o.proxy_authfile); DeleteFile(o.proxy_authfile);
/* Process died outside our control */ /* Process died outside our control */
if(o.cnn[config].connect_status == CONNECTED) if(o.conn[config].state == connected)
{ {
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.conn[config].failed_psw_attempts = 0;
/* Set connect_status = "Not Connected" */ /* Set connect_status = "Not Connected" */
o.cnn[config].connect_status=DISCONNECTED; o.conn[config].state=disconnected;
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Show Status Window */ /* Show Status Window */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONNECTED)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONNECTED));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_DISCONNECTED); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_DISCONNECTED);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE);
SetForegroundWindow(o.cnn[config].hwndStatus); SetForegroundWindow(o.conn[config].hwndStatus);
ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); ShowWindow(o.conn[config].hwndStatus, SW_SHOW);
ShowLocalizedMsg(IDS_NFO_CONN_TERMINATED, o.cnn[config].config_name); ShowLocalizedMsg(IDS_NFO_CONN_TERMINATED, o.conn[config].config_name);
/* Close Status Window */ /* Close Status Window */
SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0);
} }
/* We have failed to connect */ /* We have failed to connect */
else if(o.cnn[config].connect_status == CONNECTING) else if(o.conn[config].state == connecting)
{ {
/* Set connect_status = "DisConnecting" */ /* Set connect_status = "DisConnecting" */
o.cnn[config].connect_status=DISCONNECTING; o.conn[config].state=disconnecting;
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
if ((o.cnn[config].failed_psw) && if ((o.conn[config].failed_psw) &&
(o.cnn[config].failed_psw_attempts < o.psw_attempts)) (o.conn[config].failed_psw_attempts < o.psw_attempts))
{ {
/* Restart OpenVPN to make another attempt to connect */ /* Restart OpenVPN to make another attempt to connect */
PostMessage(o.hWnd, WM_COMMAND, (WPARAM) IDM_CONNECTMENU + config, 0); PostMessage(o.hWnd, WM_COMMAND, (WPARAM) IDM_CONNECTMENU + config, 0);
@ -546,42 +546,42 @@ void WatchOpenVPNProcess(int config)
else else
{ {
/* Show Status Window */ /* Show Status Window */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_DISCONNECTED); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_DISCONNECTED);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE);
SetForegroundWindow(o.cnn[config].hwndStatus); SetForegroundWindow(o.conn[config].hwndStatus);
ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); ShowWindow(o.conn[config].hwndStatus, SW_SHOW);
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.conn[config].failed_psw_attempts = 0;
ShowLocalizedMsg(IDS_NFO_CONN_FAILED, o.cnn[config].config_name); ShowLocalizedMsg(IDS_NFO_CONN_FAILED, o.conn[config].config_name);
/* Set connect_status = "Not Connected" */ /* Set connect_status = "Not Connected" */
o.cnn[config].connect_status=DISCONNECTED; o.conn[config].state=disconnected;
/* Close Status Window */ /* Close Status Window */
SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0);
/* Reset restart flag */ /* Reset restart flag */
o.cnn[config].restart=false; o.conn[config].restart=false;
} }
} }
/* We have failed to reconnect */ /* We have failed to reconnect */
else if(o.cnn[config].connect_status == RECONNECTING) else if(o.conn[config].state == reconnecting)
{ {
/* Set connect_status = "DisConnecting" */ /* Set connect_status = "DisConnecting" */
o.cnn[config].connect_status=DISCONNECTING; o.conn[config].state=disconnecting;
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
if ((o.cnn[config].failed_psw) && if ((o.conn[config].failed_psw) &&
(o.cnn[config].failed_psw_attempts < o.psw_attempts)) (o.conn[config].failed_psw_attempts < o.psw_attempts))
{ {
/* Restart OpenVPN to make another attempt to connect */ /* Restart OpenVPN to make another attempt to connect */
PostMessage(o.hWnd, WM_COMMAND, (WPARAM) IDM_CONNECTMENU + config, 0); PostMessage(o.hWnd, WM_COMMAND, (WPARAM) IDM_CONNECTMENU + config, 0);
@ -589,42 +589,42 @@ void WatchOpenVPNProcess(int config)
else else
{ {
/* Show Status Window */ /* Show Status Window */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED_RECONN)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED_RECONN));
SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_DISCONNECTED); SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_DISCONNECTED);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE);
SetForegroundWindow(o.cnn[config].hwndStatus); SetForegroundWindow(o.conn[config].hwndStatus);
ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); ShowWindow(o.conn[config].hwndStatus, SW_SHOW);
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.conn[config].failed_psw_attempts = 0;
ShowLocalizedMsg(IDS_NFO_RECONN_FAILED, o.cnn[config].config_name); ShowLocalizedMsg(IDS_NFO_RECONN_FAILED, o.conn[config].config_name);
/* Set connect_status = "Not Connected" */ /* Set connect_status = "Not Connected" */
o.cnn[config].connect_status=DISCONNECTED; o.conn[config].state=disconnected;
/* Close Status Window */ /* Close Status Window */
SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0);
/* Reset restart flag */ /* Reset restart flag */
o.cnn[config].restart=false; o.conn[config].restart=false;
} }
} }
/* We have chosed to Disconnect */ /* We have chosed to Disconnect */
else if(o.cnn[config].connect_status == DISCONNECTING) else if(o.conn[config].state == disconnecting)
{ {
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.conn[config].failed_psw_attempts = 0;
/* Set connect_status = "Not Connected" */ /* Set connect_status = "Not Connected" */
o.cnn[config].connect_status=DISCONNECTED; o.conn[config].state=disconnected;
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
if (o.cnn[config].restart) if (o.conn[config].restart)
{ {
/* Restart OpenVPN */ /* Restart OpenVPN */
StartOpenVPN(config); StartOpenVPN(config);
@ -632,26 +632,26 @@ void WatchOpenVPNProcess(int config)
else else
{ {
/* Close Status Window */ /* Close Status Window */
SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0);
} }
} }
/* We have chosed to Suspend */ /* We have chosed to Suspend */
else if(o.cnn[config].connect_status == SUSPENDING) else if(o.conn[config].state == suspending)
{ {
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.conn[config].failed_psw_attempts = 0;
/* Set connect_status = "SUSPENDED" */ /* Set connect_status = "SUSPENDED" */
o.cnn[config].connect_status=SUSPENDED; o.conn[config].state=suspended;
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_SUSPENDED)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_SUSPENDED));
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
} }
/* Enable/Disable menuitems for this connections */ /* Enable/Disable menuitems for this connections */
SetMenuStatus(config, DISCONNECTED); SetMenuStatus(config, disconnected);
} }

240
options.c
View File

@ -2,6 +2,7 @@
* OpenVPN-GUI -- A Windows GUI for OpenVPN. * OpenVPN-GUI -- A Windows GUI for OpenVPN.
* *
* Copyright (C) 2004 Mathias Sundman <mathias@nilings.se> * Copyright (C) 2004 Mathias Sundman <mathias@nilings.se>
* 2010 Heiko Hund <heikoh@users.sf.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,117 +32,18 @@
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h" #include "localization.h"
extern struct options o; #define streq(x, y) (_tcscmp((x), (y)) == 0)
void extern options_t o;
init_options (struct options *opt)
{
CLEAR (*opt);
}
int Createargcargv(struct options *options, TCHAR *command_line)
{
int argc;
TCHAR **argv;
TCHAR* arg;
int myindex;
// count the arguments
argc = 0;
arg = command_line;
while (arg[0] != 0) {
while (arg[0] != 0 && arg[0] == ' ') {
arg++;
}
if (arg[0] != 0) {
argc++;
if (arg[0] == '\"') {
arg++;
while (arg[0] != 0 && arg[0] != '\"') {
arg++;
}
}
while (arg[0] != 0 && arg[0] != ' ') {
arg++;
}
}
}
// tokenize the arguments
argv = (TCHAR**) malloc(argc * sizeof(TCHAR*));
arg = command_line;
myindex = 0;
while (arg[0] != 0) {
while (arg[0] != 0 && arg[0] == ' ') {
arg++;
}
if (arg[0] != 0) {
if (arg[0] == '\"') {
arg++;
argv[myindex] = arg;
myindex++;
while (arg[0] != 0 && arg[0] != '\"') {
arg++;
}
if (arg[0] != 0) {
arg[0] = 0;
arg++;
}
while (arg[0] != 0 && arg[0] != ' ') {
arg++;
}
}
else {
argv[myindex] = arg;
myindex++;
while (arg[0] != 0 && arg[0] != ' ') {
arg++;
}
if (arg[0] != 0) {
arg[0] = 0;
arg++;
}
}
}
}
parse_argv(options, argc, argv);
free(argv);
return(0);
}
static int static int
add_option (struct options *options, add_option(options_t *options, int i, TCHAR **p)
int i,
TCHAR *p[])
{ {
if (streq(p[0], _T("help"))) if (streq(p[0], _T("help")))
{ {
TCHAR usagecaption[200]; TCHAR caption[200];
LoadLocalizedStringBuf(caption, _tsizeof(caption), IDS_NFO_USAGECAPTION);
LoadLocalizedStringBuf(usagecaption, _tsizeof(usagecaption), IDS_NFO_USAGECAPTION); MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), caption, MB_OK);
MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), usagecaption, MB_OK);
exit(0); exit(0);
} }
else if (streq(p[0], _T("connect")) && p[1]) else if (streq(p[0], _T("connect")) && p[1])
@ -154,9 +56,7 @@ add_option (struct options *options,
ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS);
exit(1); exit(1);
} }
options->auto_connect[auto_connect_nr++] = p[1];
options->auto_connect[auto_connect_nr] = p[1];
auto_connect_nr++;
} }
else if (streq(p[0], _T("exe_path")) && p[1]) else if (streq(p[0], _T("exe_path")) && p[1])
{ {
@ -251,14 +151,12 @@ add_option (struct options *options,
else if (streq(p[0], _T("disconnectscript_timeout")) && p[1]) else if (streq(p[0], _T("disconnectscript_timeout")) && p[1])
{ {
++i; ++i;
_tcsncpy(options->disconnectscript_timeout_string, p[1], _tcsncpy(options->disconnectscript_timeout_string, p[1], _tsizeof(options->disconnectscript_timeout_string) - 1);
_tsizeof(options->disconnectscript_timeout_string) - 1);
} }
else if (streq(p[0], _T("preconnectscript_timeout")) && p[1]) else if (streq(p[0], _T("preconnectscript_timeout")) && p[1])
{ {
++i; ++i;
_tcsncpy(options->preconnectscript_timeout_string, p[1], _tcsncpy(options->preconnectscript_timeout_string, p[1], _tsizeof(options->preconnectscript_timeout_string) - 1);
_tsizeof(options->preconnectscript_timeout_string) - 1);
} }
else else
{ {
@ -269,10 +167,9 @@ add_option (struct options *options,
return i; return i;
} }
void
parse_argv (struct options* options, static void
int argc, parse_argv(options_t *options, int argc, TCHAR **argv)
TCHAR *argv[])
{ {
int i, j; int i, j;
@ -282,13 +179,13 @@ parse_argv (struct options* options,
TCHAR *p[MAX_PARMS]; TCHAR *p[MAX_PARMS];
CLEAR(p); CLEAR(p);
p[0] = argv[i]; p[0] = argv[i];
if (_tcsncmp(p[0], _T("--"), 2)) if (_tcsncmp(p[0], _T("--"), 2) != 0)
{ {
/* Missing -- before option. */ /* Missing -- before option. */
ShowLocalizedMsg(IDS_ERR_BAD_PARAMETER, p[0]); ShowLocalizedMsg(IDS_ERR_BAD_PARAMETER, p[0]);
exit(0); exit(0);
} }
else
p[0] += 2; p[0] += 2;
for (j = 1; j < MAX_PARMS; ++j) for (j = 1; j < MAX_PARMS; ++j)
@ -296,48 +193,101 @@ parse_argv (struct options* options,
if (i + j < argc) if (i + j < argc)
{ {
TCHAR *arg = argv[i + j]; TCHAR *arg = argv[i + j];
if (_tcsncmp (arg, _T("--"), 2)) if (_tcsncmp(arg, _T("--"), 2) == 0)
p[j] = arg;
else
break; break;
p[j] = arg;
} }
} }
i = add_option(options, i, p); i = add_option(options, i, p);
} }
} }
/*
* Returns TRUE if option exist in config file.
*/
int ConfigFileOptionExist(int config, const char *option)
{
FILE *fp;
char line[256];
TCHAR configfile_path[MAX_PATH];
_tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path)); void
if (configfile_path[_tcslen(configfile_path) - 1] != _T('\\')) InitOptions(options_t *opt)
_tcscat(configfile_path, _T("\\"));
_tcsncat(configfile_path, o.cnn[config].config_file,
_tsizeof(configfile_path) - _tcslen(configfile_path) - 1);
if (!(fp=_tfopen(configfile_path, _T("r"))))
{ {
/* can't open config file */ CLEAR(*opt);
ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, configfile_path);
return(0);
} }
while (fgets(line, sizeof (line), fp))
void
ProcessCommandLine(options_t *options, TCHAR *command_line)
{ {
if ((strncmp(line, option, sizeof(option)) == 0)) TCHAR **argv;
TCHAR *pos = command_line;
int argc = 0;
/* Count the arguments */
do
{ {
fclose(fp); while (*pos == _T(' '))
return(1); ++pos;
if (*pos == _T('\0'))
break;
++argc;
while (*pos != _T('\0') && *pos != _T(' '))
++pos;
} }
while (*pos != _T('\0'));
if (argc == 0)
return;
/* Tokenize the arguments */
argv = (TCHAR**) malloc(argc * sizeof(TCHAR*));
pos = command_line;
argc = 0;
do
{
while (*pos == _T(' '))
pos++;
if (*pos == _T('\0'))
break;
if (*pos == _T('\"'))
{
argv[argc++] = ++pos;
while (*pos != _T('\0') && *pos != _T('\"'))
++pos;
}
else
{
argv[argc++] = pos;
while (*pos != _T('\0') && *pos != _T(' '))
++pos;
} }
fclose(fp); if (*pos == _T('\0'))
return(0); break;
*pos++ = _T('\0');
}
while (*pos != _T('\0'));
parse_argv(options, argc, argv);
free(argv);
}
/* Return num of connections with state = check */
int
CountConnState(conn_state_t check)
{
int i;
int count = 0;
for (i = 0; i < o.num_configs; ++i)
{
if (o.conn[i].state == check)
++count;
}
return count;
} }

115
options.h
View File

@ -2,6 +2,7 @@
* OpenVPN-GUI -- A Windows GUI for OpenVPN. * OpenVPN-GUI -- A Windows GUI for OpenVPN.
* *
* Copyright (C) 2004 Mathias Sundman <mathias@nilings.se> * Copyright (C) 2004 Mathias Sundman <mathias@nilings.se>
* 2010 Heiko Hund <heikoh@users.sf.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,6 +21,9 @@
* *
*/ */
#ifndef OPTIONS_H
#define OPTIONS_H
#include <windows.h> #include <windows.h>
#include <time.h> #include <time.h>
@ -27,68 +31,89 @@
* Maximum number of parameters associated with an option, * Maximum number of parameters associated with an option,
* including the option name itself. * including the option name itself.
*/ */
#define MAX_PARMS 5 #define MAX_PARMS 5 /* May number of parameters per option */
#define MAX_CONFIGS 50 /* Max number of config-files to read. */ #define MAX_CONFIGS 50 /* Max number of config-files to read */
#define MAX_CONFIG_SUBDIRS 50 /* Max number of subdirs to scan */ #define MAX_CONFIG_SUBDIRS 50 /* Max number of subdirs to scan for configs */
/* connect_status STATES */
#define DISCONNECTED 0
#define CONNECTING 1
#define CONNECTED 2
#define RECONNECTING 3
#define DISCONNECTING 4
#define SUSPENDING 5
#define SUSPENDED 6
/* OpenVPN Service STATES */ /* connection states */
#define SERVICE_NOACCESS -1 typedef enum {
#define SERVICE_DISCONNECTED 0 disconnected,
#define SERVICE_CONNECTING 1 connecting,
#define SERVICE_CONNECTED 2 reconnecting,
connected,
disconnecting,
suspending,
suspended
} conn_state_t;
/* Connections parameters */ /* Connections parameters */
typedef struct typedef struct {
{
TCHAR config_file[MAX_PATH]; /* Name of the config file */ TCHAR config_file[MAX_PATH]; /* Name of the config file */
TCHAR config_name[MAX_PATH]; /* Name of the connection */ TCHAR config_name[MAX_PATH]; /* Name of the connection */
TCHAR config_dir[MAX_PATH]; /* Path to this configs dir */ TCHAR config_dir[MAX_PATH]; /* Path to this configs dir */
TCHAR log_path[MAX_PATH]; /* Path to Logfile */ TCHAR log_path[MAX_PATH]; /* Path to Logfile */
TCHAR ip[16]; /* Assigned IP address for this connection */ TCHAR ip[16]; /* Assigned IP address for this connection */
TCHAR exit_event_name[50]; /* Exit Event name for this connection */ TCHAR exit_event_name[50]; /* Exit Event name for this connection */
int connect_status; /* 0=Not Connected 1=Connecting BOOL auto_connect; /* AutoConnect at startup id TRUE */
2=Connected 3=Reconnecting 4=Disconnecting */ BOOL restart; /* Restart connection after termination if TRUE*/
int auto_connect; /* true=AutoConnect at startup */ BOOL failed_psw; /* TRUE if OpenVPN failed because of wrong psw */
int failed_psw; /* 1=OpenVPN failed because of wrong psw */ conn_state_t state; /* State the connection currently is in */
int failed_psw_attempts; /* # of failed attempts maid to enter psw */ int failed_psw_attempts; /* # of failed attempts made to enter psw */
int restart; /* true=Restart connection after termination */
time_t connected_since; /* Time when the connection was established */ time_t connected_since; /* Time when the connection was established */
HANDLE exit_event; HANDLE exit_event;
HANDLE hProcess; HANDLE hProcess;
HANDLE hStdOut; HANDLE hStdOut;
HANDLE hStdIn; HANDLE hStdIn;
HWND hwndStatus; /* Handle to Status Dialog Window */ HWND hwndStatus;
} connection_t; } connection_t;
typedef enum {
service_noaccess = -1,
service_disconnected = 0,
service_connecting = 1,
service_connected = 2
} service_state_t;
typedef enum {
config,
browser,
manual
} proxy_source_t;
typedef enum {
http,
socks
} proxy_t;
/* All options used within OpenVPN GUI */ /* All options used within OpenVPN GUI */
struct options typedef struct {
{
/* Array of configs to autostart */ /* Array of configs to autostart */
const TCHAR *auto_connect[MAX_CONFIGS]; const TCHAR *auto_connect[MAX_CONFIGS];
/* Connection parameters */ /* Connection parameters */
connection_t cnn[MAX_CONFIGS]; /* Connection structure */ connection_t conn[MAX_CONFIGS]; /* Connection structure */
int num_configs; /* Number of configs */ int num_configs; /* Number of configs */
int oldversion; /* 1=OpenVPN version below 2.0-beta6 */ BOOL oldversion; /* OpenVPN version below 2.0-beta6 if TRUE */
service_state_t service_state; /* State of the OpenVPN Service */
char connect_string[100]; /* String to look for to report connected */ char connect_string[100]; /* String to look for to report connected */
int psw_attempts; /* Number of psw attemps to allow */ int psw_attempts; /* Number of psw attemps to allow */
int connectscript_timeout; /* Connect Script execution timeout (sec) */ int connectscript_timeout; /* Connect Script execution timeout (sec) */
int disconnectscript_timeout; /* Disconnect Script execution timeout (sec) */ int disconnectscript_timeout; /* Disconnect Script execution timeout (sec) */
int preconnectscript_timeout; /* Preconnect Script execution timeout (sec) */ int preconnectscript_timeout; /* Preconnect Script execution timeout (sec) */
int service_running; /* true if OpenVPN Service is started */
HWND hWnd; /* Main Window Handle */ /* Proxy Settings */
HINSTANCE hInstance; proxy_source_t proxy_source; /* Where to get proxy information from */
proxy_t proxy_type; /* The type of proxy to use */
BOOL proxy_http_auth; /* TRUE is proxy authentication is used */
TCHAR proxy_http_address[100]; /* HTTP Proxy Address */
TCHAR proxy_http_port[6]; /* HTTP Proxy Port */
TCHAR proxy_socks_address[100]; /* SOCKS Proxy Address */
TCHAR proxy_socks_port[6]; /* SOCKS Proxy Address */
TCHAR proxy_authfile[100]; /* Path to proxy auth file */
/* Registry values */ /* Registry values */
TCHAR exe_path[MAX_PATH]; TCHAR exe_path[MAX_PATH];
@ -113,24 +138,16 @@ struct options
TCHAR disconnectscript_timeout_string[4]; TCHAR disconnectscript_timeout_string[4];
TCHAR preconnectscript_timeout_string[4]; TCHAR preconnectscript_timeout_string[4];
/* Proxy Settings */
int proxy_source; /* 0=OpenVPN config, 1=IE, 2=Manual */
int proxy_type; /* 0=HTTP, 1=SOCKS */
int proxy_http_auth; /* 0=Auth Disabled, 1=Auth Enabled */
TCHAR proxy_http_address[100]; /* HTTP Proxy Address */
TCHAR proxy_http_port[6]; /* HTTP Proxy Port */
TCHAR proxy_socks_address[100]; /* SOCKS Proxy Address */
TCHAR proxy_socks_port[6]; /* SOCKS Proxy Address */
TCHAR proxy_authfile[100]; /* Path to proxy auth file */
/* Debug file pointer */
#ifdef DEBUG #ifdef DEBUG
FILE *debug_fp; FILE *debug_fp;
#endif #endif
};
#define streq(x, y) (!_tcscmp((x), (y))) HWND hWnd;
void init_options (struct options *o); HINSTANCE hInstance;
int Createargcargv(struct options* options, TCHAR* command_line); } options_t;
void parse_argv (struct options* options, int argc, TCHAR *argv[]);
int ConfigFileOptionExist(int config, const char *option); void InitOptions(options_t *);
void ProcessCommandLine(options_t *, TCHAR *);
int CountConnState(conn_state_t);
#endif

View File

@ -37,7 +37,7 @@
#endif #endif
WCHAR passphrase[256]; WCHAR passphrase[256];
extern struct options o; extern options_t o;
int ConvertUnicode2Ascii(WCHAR str_unicode[], char str_ascii[], unsigned int str_ascii_size) int ConvertUnicode2Ascii(WCHAR str_unicode[], char str_ascii[], unsigned int str_ascii_size)
{ {
@ -85,14 +85,14 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
CLEAR(passphrase_ascii); CLEAR(passphrase_ascii);
ConvertUnicode2Ascii(passphrase, passphrase_ascii, sizeof(passphrase_ascii)); ConvertUnicode2Ascii(passphrase, passphrase_ascii, sizeof(passphrase_ascii));
if (!WriteFile(o.cnn[config].hStdIn, passphrase_ascii, if (!WriteFile(o.conn[config].hStdIn, passphrase_ascii,
strlen(passphrase_ascii), &nCharsWritten, NULL)) strlen(passphrase_ascii), &nCharsWritten, NULL))
{ {
/* PassPhrase -> stdin failed */ /* PassPhrase -> stdin failed */
ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN); ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN);
} }
} }
if (!WriteFile(o.cnn[config].hStdIn, "\r\n", if (!WriteFile(o.conn[config].hStdIn, "\r\n",
2, &nCharsWritten, NULL)) 2, &nCharsWritten, NULL))
{ {
/* CR -> stdin failed */ /* CR -> stdin failed */
@ -120,7 +120,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
CLEAR(passphrase_ascii); CLEAR(passphrase_ascii);
ConvertUnicode2Ascii(passphrase, passphrase_ascii, sizeof(passphrase_ascii)); ConvertUnicode2Ascii(passphrase, passphrase_ascii, sizeof(passphrase_ascii));
if (!WriteFile(o.cnn[config].hStdIn, passphrase_ascii, if (!WriteFile(o.conn[config].hStdIn, passphrase_ascii,
strlen(passphrase_ascii), &nCharsWritten, NULL)) strlen(passphrase_ascii), &nCharsWritten, NULL))
{ {
/* PassPhrase -> stdin failed */ /* PassPhrase -> stdin failed */
@ -129,7 +129,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
} }
else else
{ {
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.conn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
/* CR -> stdin failed */ /* CR -> stdin failed */
@ -163,7 +163,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (strlen(user_auth.username) > 0) if (strlen(user_auth.username) > 0)
{ {
if (!WriteFile(o.cnn[config].hStdIn, user_auth.username, if (!WriteFile(o.conn[config].hStdIn, user_auth.username,
strlen(user_auth.username), &nCharsWritten, NULL)) strlen(user_auth.username), &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(IDS_ERR_AUTH_USERNAME2STDIN); ShowLocalizedMsg(IDS_ERR_AUTH_USERNAME2STDIN);
@ -171,7 +171,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
} }
else else
{ {
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.conn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(IDS_ERR_CR2STDIN); ShowLocalizedMsg(IDS_ERR_CR2STDIN);
@ -180,7 +180,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (strlen(user_auth.password) > 0) if (strlen(user_auth.password) > 0)
{ {
if (!WriteFile(o.cnn[config].hStdIn, user_auth.password, if (!WriteFile(o.conn[config].hStdIn, user_auth.password,
strlen(user_auth.password), &nCharsWritten, NULL)) strlen(user_auth.password), &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(IDS_ERR_AUTH_PASSWORD2STDIN); ShowLocalizedMsg(IDS_ERR_AUTH_PASSWORD2STDIN);
@ -188,7 +188,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
} }
else else
{ {
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.conn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(IDS_ERR_CR2STDIN); ShowLocalizedMsg(IDS_ERR_CR2STDIN);
@ -331,7 +331,7 @@ void ChangePassphraseThread(int config)
int keyfile_format=0; int keyfile_format=0;
/* Cut of extention from config filename. */ /* Cut of extention from config filename. */
_tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name)); _tcsncpy(conn_name, o.conn[config].config_file, _tsizeof(conn_name));
conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0; conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0;
/* Get Key filename from config file */ /* Get Key filename from config file */
@ -594,7 +594,7 @@ int ParseKeyFilenameLine(int config, TCHAR *keyfilename, size_t keyfilenamesize,
/* Prepend filename with configdir path if needed */ /* Prepend filename with configdir path if needed */
if ((keyfilename[0] != '\\') && (keyfilename[0] != '/') && (keyfilename[1] != ':')) if ((keyfilename[0] != '\\') && (keyfilename[0] != '/') && (keyfilename[1] != ':'))
{ {
_tcsncpy(temp_filename, o.cnn[config].config_dir, _tsizeof(temp_filename)); _tcsncpy(temp_filename, o.conn[config].config_dir, _tsizeof(temp_filename));
if (temp_filename[_tcslen(temp_filename) - 1] != '\\') if (temp_filename[_tcslen(temp_filename) - 1] != '\\')
_tcscat(temp_filename, _T("\\")); _tcscat(temp_filename, _T("\\"));
_tcsncat(temp_filename, keyfilename, _tcsncat(temp_filename, keyfilename,
@ -820,10 +820,10 @@ int GetKeyFilename(int config, TCHAR *keyfilename, size_t keyfilenamesize, int *
int found_pkcs12=0; int found_pkcs12=0;
TCHAR configfile_path[MAX_PATH]; TCHAR configfile_path[MAX_PATH];
_tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path)); _tcsncpy(configfile_path, o.conn[config].config_dir, _tsizeof(configfile_path));
if (!(configfile_path[_tcslen(configfile_path)-1] == '\\')) if (!(configfile_path[_tcslen(configfile_path)-1] == '\\'))
_tcscat(configfile_path, _T("\\")); _tcscat(configfile_path, _T("\\"));
_tcsncat(configfile_path, o.cnn[config].config_file, _tcsncat(configfile_path, o.conn[config].config_file,
_tsizeof(configfile_path) - _tcslen(configfile_path) - 1); _tsizeof(configfile_path) - _tcslen(configfile_path) - 1);
if (!(fp=_tfopen(configfile_path, _T("r")))) if (!(fp=_tfopen(configfile_path, _T("r"))))

42
proxy.c
View File

@ -33,7 +33,7 @@
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam)
{ {
@ -181,7 +181,7 @@ int CheckProxySettings(HWND hwndDlg)
void LoadProxySettings(HWND hwndDlg) void LoadProxySettings(HWND hwndDlg)
{ {
/* Set Proxy type, address and port */ /* Set Proxy type, address and port */
if (o.proxy_type == 0) /* HTTP Proxy */ if (o.proxy_type == http) /* HTTP Proxy */
{ {
CheckRadioButton(hwndDlg, ID_RB_PROXY_HTTP, ID_RB_PROXY_SOCKS, ID_RB_PROXY_HTTP); CheckRadioButton(hwndDlg, ID_RB_PROXY_HTTP, ID_RB_PROXY_SOCKS, ID_RB_PROXY_HTTP);
SetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address); SetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address);
@ -197,11 +197,11 @@ void LoadProxySettings(HWND hwndDlg)
if (o.proxy_http_auth) CheckDlgButton(hwndDlg, ID_CB_PROXY_AUTH, BST_CHECKED); if (o.proxy_http_auth) CheckDlgButton(hwndDlg, ID_CB_PROXY_AUTH, BST_CHECKED);
/* Set Proxy Settings Source */ /* Set Proxy Settings Source */
if (o.proxy_source == 0) if (o.proxy_source == config)
SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_OPENVPN), BM_CLICK, 0, 0); SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_OPENVPN), BM_CLICK, 0, 0);
if (o.proxy_source == 1) if (o.proxy_source == browser)
SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MSIE), BM_CLICK, 0, 0); SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MSIE), BM_CLICK, 0, 0);
if (o.proxy_source == 2) if (o.proxy_source == manual)
SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MANUAL), BM_CLICK, 0, 0); SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MANUAL), BM_CLICK, 0, 0);
} }
@ -216,24 +216,24 @@ void SaveProxySettings(HWND hwndDlg)
/* Save Proxy Settings Source */ /* Save Proxy Settings Source */
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_OPENVPN) == BST_CHECKED) if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_OPENVPN) == BST_CHECKED)
{ {
o.proxy_source = 0; o.proxy_source = config;
proxy_source_string[0] = _T('0'); proxy_source_string[0] = _T('0');
} }
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED) if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED)
{ {
o.proxy_source = 1; o.proxy_source = browser;
proxy_source_string[0] = _T('1'); proxy_source_string[0] = _T('1');
} }
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED) if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED)
{ {
o.proxy_source = 2; o.proxy_source = manual;
proxy_source_string[0] = _T('2'); proxy_source_string[0] = _T('2');
} }
/* Save Proxy type, address and port */ /* Save Proxy type, address and port */
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_HTTP) == BST_CHECKED) if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_HTTP) == BST_CHECKED)
{ {
o.proxy_type = 0; o.proxy_type = http;
proxy_type_string[0] = _T('0'); proxy_type_string[0] = _T('0');
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address, GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address,
@ -247,7 +247,7 @@ void SaveProxySettings(HWND hwndDlg)
} }
else else
{ {
o.proxy_type = 1; o.proxy_type = socks;
proxy_type_string[0] = _T('1'); proxy_type_string[0] = _T('1');
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_socks_address, GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_socks_address,
@ -332,17 +332,17 @@ void GetProxyRegistrySettings()
_tsizeof(proxy_http_auth_string)); _tsizeof(proxy_http_auth_string));
if (proxy_source_string[0] == _T('1')) if (proxy_source_string[0] == _T('1'))
o.proxy_source=1; o.proxy_source = config;
if (proxy_source_string[0] == _T('2')) if (proxy_source_string[0] == _T('2'))
o.proxy_source=2; o.proxy_source = browser;
if (proxy_source_string[0] == _T('3')) if (proxy_source_string[0] == _T('3'))
o.proxy_source=3; o.proxy_source = manual;
if (proxy_type_string[0] == _T('1')) if (proxy_type_string[0] == _T('1'))
o.proxy_type=1; o.proxy_type = socks;
if (proxy_http_auth_string[0] == _T('1')) if (proxy_http_auth_string[0] == _T('1'))
o.proxy_http_auth=1; o.proxy_http_auth = TRUE;
RegCloseKey(regkey); RegCloseKey(regkey);
} }
@ -467,11 +467,11 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size)
CLEAR(proxy_string); CLEAR(proxy_string);
if (o.proxy_source == PROXY_SOURCE_MANUAL) if (o.proxy_source == manual)
{ {
if (o.proxy_type == PROXY_TYPE_HTTP) if (o.proxy_type == http)
{ {
if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) if (o.proxy_http_auth)
{ {
/* Ask for Proxy username/password */ /* Ask for Proxy username/password */
LocalizedDialogBox(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc); LocalizedDialogBox(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc);
@ -487,7 +487,7 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size)
o.proxy_http_port); o.proxy_http_port);
} }
} }
if (o.proxy_type == PROXY_TYPE_SOCKS) if (o.proxy_type == socks)
{ {
_sntprintf_0(proxy_string, _T("--socks-proxy %s %s"), _sntprintf_0(proxy_string, _T("--socks-proxy %s %s"),
o.proxy_socks_address, o.proxy_socks_address,
@ -495,7 +495,7 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size)
} }
} }
else if (o.proxy_source == PROXY_SOURCE_IE) else if (o.proxy_source == browser)
{ {
TCHAR host[64]; TCHAR host[64];
TCHAR port[6]; TCHAR port[6];
@ -504,7 +504,7 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size)
if (GetIeHttpProxy(host, &hostlen, port, &portlen) && hostlen != 0) if (GetIeHttpProxy(host, &hostlen, port, &portlen) && hostlen != 0)
{ {
if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) if (o.proxy_http_auth)
{ {
/* Ask for Proxy username/password */ /* Ask for Proxy username/password */
LocalizedDialogBox(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc); LocalizedDialogBox(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc);

View File

@ -19,14 +19,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define PROXY_SOURCE_OPENVPN 0
#define PROXY_SOURCE_IE 1
#define PROXY_SOURCE_MANUAL 2
#define PROXY_TYPE_HTTP 0
#define PROXY_TYPE_SOCKS 1
#define PROXY_HTTP_NO_AUTH 0
#define PROXY_HTTP_ASK_AUTH 1
BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
int CheckProxySettings(HWND hwndDlg); int CheckProxySettings(HWND hwndDlg);
void LoadProxySettings(HWND hwndDlg); void LoadProxySettings(HWND hwndDlg);

View File

@ -32,7 +32,7 @@
#include "registry.h" #include "registry.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
int int
GetRegistryKeys() GetRegistryKeys()

View File

@ -29,7 +29,7 @@
#include "options.h" #include "options.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
void RunConnectScript(int config, int run_as_service) void RunConnectScript(int config, int run_as_service)
{ {
@ -45,10 +45,10 @@ void RunConnectScript(int config, int run_as_service)
int i, TimeOut; int i, TimeOut;
/* Cut of extention from config filename and add "_up.bat". */ /* Cut of extention from config filename and add "_up.bat". */
_tcsncpy(batch_file, o.cnn[config].config_file, _tsizeof(batch_file)); _tcsncpy(batch_file, o.conn[config].config_file, _tsizeof(batch_file));
batch_file[_tcslen(batch_file) - (_tcslen(o.ext_string)+1)]=0; batch_file[_tcslen(batch_file) - (_tcslen(o.ext_string)+1)]=0;
_tcsncat(batch_file, _T("_up.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1); _tcsncat(batch_file, _T("_up.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1);
_sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); _sntprintf_0(command_line, _T("%s\\%s"), o.conn[config].config_dir, batch_file);
/* Return if no script exists */ /* Return if no script exists */
@ -63,7 +63,7 @@ void RunConnectScript(int config, int run_as_service)
if (!run_as_service) if (!run_as_service)
{ {
/* UserInfo: Connect Script running */ /* UserInfo: Connect Script running */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT));
} }
CLEAR (start_info); CLEAR (start_info);
@ -87,7 +87,7 @@ void RunConnectScript(int config, int run_as_service)
((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE : ((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE :
(DWORD) CREATE_NO_WINDOW), (DWORD) CREATE_NO_WINDOW),
NULL, NULL,
o.cnn[config].config_dir, //start-up dir o.conn[config].config_dir, //start-up dir
&start_info, &start_info,
&proc_info)) &proc_info))
{ {
@ -146,9 +146,9 @@ void RunDisconnectScript(int config, int run_as_service)
int i, TimeOut; int i, TimeOut;
/* Append "_down.bat" to config name. */ /* Append "_down.bat" to config name. */
_tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file)); _tcsncpy(batch_file, o.conn[config].config_name, _tsizeof(batch_file));
_tcsncat(batch_file, _T("_down.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1); _tcsncat(batch_file, _T("_down.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1);
_sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); _sntprintf_0(command_line, _T("%s\\%s"), o.conn[config].config_dir, batch_file);
/* Return if no script exists */ /* Return if no script exists */
@ -163,7 +163,7 @@ void RunDisconnectScript(int config, int run_as_service)
if (!run_as_service) if (!run_as_service)
{ {
/* UserInfo: Disconnect Script running */ /* UserInfo: Disconnect Script running */
SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONN_SCRIPT)); SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONN_SCRIPT));
} }
CLEAR (start_info); CLEAR (start_info);
@ -187,7 +187,7 @@ void RunDisconnectScript(int config, int run_as_service)
((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE : ((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE :
(DWORD) CREATE_NO_WINDOW), (DWORD) CREATE_NO_WINDOW),
NULL, NULL,
o.cnn[config].config_dir, //start-up dir o.conn[config].config_dir, //start-up dir
&start_info, &start_info,
&proc_info)) &proc_info))
{ {
@ -226,9 +226,9 @@ void RunPreconnectScript(int config)
int i, TimeOut; int i, TimeOut;
/* Append "_pre.bat" to config name. */ /* Append "_pre.bat" to config name. */
_tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file)); _tcsncpy(batch_file, o.conn[config].config_name, _tsizeof(batch_file));
_tcsncat(batch_file, _T("_pre.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1); _tcsncat(batch_file, _T("_pre.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1);
_sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); _sntprintf_0(command_line, _T("%s\\%s"), o.conn[config].config_dir, batch_file);
/* Return if no script exists */ /* Return if no script exists */
@ -261,7 +261,7 @@ void RunPreconnectScript(int config)
((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE : ((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE :
(DWORD) CREATE_NO_WINDOW), (DWORD) CREATE_NO_WINDOW),
NULL, NULL,
o.cnn[config].config_dir, //start-up dir o.conn[config].config_dir, //start-up dir
&start_info, &start_info,
&proc_info)) &proc_info))
{ {

View File

@ -32,7 +32,7 @@
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
int MyStartService() int MyStartService()
{ {
@ -46,7 +46,7 @@ int MyStartService()
int i; int i;
/* Set Service Status = Connecting */ /* Set Service Status = Connecting */
o.service_running = SERVICE_CONNECTING; o.service_state = service_connecting;
SetServiceMenuStatus(); SetServiceMenuStatus();
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
@ -157,7 +157,7 @@ int MyStartService()
RunConnectScript(i, true); RunConnectScript(i, true);
/* Set Service Status = Connected */ /* Set Service Status = Connected */
o.service_running = SERVICE_CONNECTED; o.service_state = service_connected;
SetServiceMenuStatus(); SetServiceMenuStatus();
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
@ -169,7 +169,7 @@ int MyStartService()
failed: failed:
/* Set Service Status = Disconnecting */ /* Set Service Status = Disconnecting */
o.service_running = SERVICE_DISCONNECTED; o.service_state = service_disconnected;
SetServiceMenuStatus(); SetServiceMenuStatus();
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
return(false); return(false);
@ -220,7 +220,7 @@ int MyStopService()
return(false); return(false);
} }
o.service_running = SERVICE_DISCONNECTED; o.service_state = service_disconnected;
SetServiceMenuStatus(); SetServiceMenuStatus();
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
return(true); return(true);
@ -253,7 +253,7 @@ int CheckServiceStatus()
SC_MANAGER_CONNECT); // Connect rights SC_MANAGER_CONNECT); // Connect rights
if (NULL == schSCManager) { if (NULL == schSCManager) {
o.service_running = SERVICE_NOACCESS; o.service_state = service_noaccess;
SetServiceMenuStatus(); SetServiceMenuStatus();
return(false); return(false);
} }
@ -266,7 +266,7 @@ int CheckServiceStatus()
if (schService == NULL) { if (schService == NULL) {
/* open vpn service failed */ /* open vpn service failed */
ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE); ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE);
o.service_running = SERVICE_NOACCESS; o.service_state = service_noaccess;
SetServiceMenuStatus(); SetServiceMenuStatus();
return(false); return(false);
} }
@ -282,16 +282,16 @@ int CheckServiceStatus()
if (ssStatus.dwCurrentState == SERVICE_RUNNING) if (ssStatus.dwCurrentState == SERVICE_RUNNING)
{ {
o.service_running = SERVICE_CONNECTED; o.service_state = service_connected;
SetServiceMenuStatus(); SetServiceMenuStatus();
SetTrayIcon(CONNECTED); SetTrayIcon(connected);
return(true); return(true);
} }
else else
{ {
o.service_running = SERVICE_DISCONNECTED; o.service_state = service_disconnected;
SetServiceMenuStatus(); SetServiceMenuStatus();
SetTrayIcon(DISCONNECTED); SetTrayIcon(disconnected);
return(false); return(false);
} }
} }

71
tray.c
View File

@ -50,7 +50,7 @@ HMENU hMenuConn[MAX_CONFIGS];
HMENU hMenuService; HMENU hMenuService;
NOTIFYICONDATA ni; NOTIFYICONDATA ni;
extern struct options o; extern options_t o;
// Mouse clicks on tray // Mouse clicks on tray
void OnNotifyTray(LPARAM lParam) void OnNotifyTray(LPARAM lParam)
@ -63,7 +63,7 @@ void OnNotifyTray(LPARAM lParam)
switch(lParam) { switch(lParam) {
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
/* Re-read configs and re-create menus if no connection is running */ /* Re-read configs and re-create menus if no connection is running */
if (CountConnectedState(DISCONNECTED) == o.num_configs) if (CountConnState(disconnected) == o.num_configs)
{ {
DestroyPopupMenus(); DestroyPopupMenus();
BuildFileList(); BuildFileList();
@ -82,11 +82,11 @@ void OnNotifyTray(LPARAM lParam)
if (o.service_only[0]=='1') if (o.service_only[0]=='1')
{ {
/* Start OpenVPN Service */ /* Start OpenVPN Service */
if (o.service_running == SERVICE_DISCONNECTED) if (o.service_state == service_disconnected)
{ {
MyStartService(); MyStartService();
} }
else if (o.service_running == SERVICE_CONNECTED) else if (o.service_state == service_connected)
{ {
/* Stop OpenVPN service */ /* Stop OpenVPN service */
if (MessageBox(NULL, LoadLocalizedString(IDS_MENU_ASK_STOP_SERVICE), _T(PACKAGE_NAME), MB_YESNO | MB_SETFOREGROUND) == IDYES) if (MessageBox(NULL, LoadLocalizedString(IDS_MENU_ASK_STOP_SERVICE), _T(PACKAGE_NAME), MB_YESNO | MB_SETFOREGROUND) == IDYES)
@ -101,7 +101,7 @@ void OnNotifyTray(LPARAM lParam)
connected_config = -1; connected_config = -1;
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
{ {
if(o.cnn[i].connect_status != DISCONNECTED) if(o.conn[i].state != disconnected)
{ {
if (connected_config == -1) if (connected_config == -1)
{ {
@ -116,19 +116,19 @@ void OnNotifyTray(LPARAM lParam)
} }
if (connected_config != -1) if (connected_config != -1)
{ {
ShowWindow(o.cnn[connected_config].hwndStatus, SW_SHOW); ShowWindow(o.conn[connected_config].hwndStatus, SW_SHOW);
SetForegroundWindow(o.cnn[connected_config].hwndStatus); SetForegroundWindow(o.conn[connected_config].hwndStatus);
} }
/* Re-read configs and re-create menus if no connection is running */ /* Re-read configs and re-create menus if no connection is running */
if (CountConnectedState(DISCONNECTED) == o.num_configs) if (CountConnState(disconnected) == o.num_configs)
{ {
DestroyPopupMenus(); DestroyPopupMenus();
BuildFileList(); BuildFileList();
CreatePopupMenus(); CreatePopupMenus();
/* Start connection if only one config exist */ /* Start connection if only one config exist */
if ((o.num_configs == 1) && (o.cnn[0].connect_status == DISCONNECTED)) if ((o.num_configs == 1) && (o.conn[0].state == disconnected))
StartOpenVPN(0); StartOpenVPN(0);
} }
} }
@ -152,7 +152,6 @@ void OnDestroyTray()
void CreatePopupMenus() void CreatePopupMenus()
{ {
int i; int i;
//extern struct options o;
/* Create Main menu */ /* Create Main menu */
hMenu=CreatePopupMenu(); hMenu=CreatePopupMenu();
@ -230,14 +229,14 @@ void CreateItemList()
AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, LoadLocalizedString(IDS_MENU_ABOUT)); AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, LoadLocalizedString(IDS_MENU_ABOUT));
AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDS_MENU_CLOSE)); AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDS_MENU_CLOSE));
SetMenuStatus(0, DISCONNECTED); SetMenuStatus(0, disconnected);
} }
else else
{ {
/* Create Main menu with all connections */ /* Create Main menu with all connections */
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
AppendMenu(hMenu,MF_POPUP,(UINT) hMenuConn[i],o.cnn[i].config_name); AppendMenu(hMenu,MF_POPUP,(UINT) hMenuConn[i],o.conn[i].config_name);
if (o.num_configs > 0) if (o.num_configs > 0)
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
if (o.allow_service[0]=='1' && o.service_only[0]=='0') if (o.allow_service[0]=='1' && o.service_only[0]=='0')
@ -279,7 +278,7 @@ void CreateItemList()
} }
#endif #endif
SetMenuStatus(i, DISCONNECTED); SetMenuStatus(i, disconnected);
} }
} }
@ -331,7 +330,7 @@ void ShowTrayIcon()
* connected=1 -> Connecting * connected=1 -> Connecting
* connected=2 -> Connected * connected=2 -> Connected
*/ */
void SetTrayIcon(int connected) void SetTrayIcon(conn_state_t connected)
{ {
TCHAR msg[500]; TCHAR msg[500];
TCHAR msg_connected[100]; TCHAR msg_connected[100];
@ -353,14 +352,14 @@ void SetTrayIcon(int connected)
first_conn=1; first_conn=1;
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
{ {
if(o.cnn[i].connect_status == CONNECTED) if(o.conn[i].state == connected)
{ {
/* Append connection name to Icon Tip Msg */ /* Append connection name to Icon Tip Msg */
if (first_conn) if (first_conn)
_tcsncat(msg, msg_connected, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, msg_connected, _tsizeof(msg) - _tcslen(msg) - 1);
else else
_tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1);
_tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, o.conn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1);
first_conn=0; first_conn=0;
config=i; config=i;
} }
@ -369,32 +368,32 @@ void SetTrayIcon(int connected)
first_conn=1; first_conn=1;
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
{ {
if((o.cnn[i].connect_status == CONNECTING) || if((o.conn[i].state == connecting) ||
(o.cnn[i].connect_status == RECONNECTING)) (o.conn[i].state == reconnecting))
{ {
/* Append connection name to Icon Tip Msg */ /* Append connection name to Icon Tip Msg */
if (first_conn) if (first_conn)
_tcsncat(msg, msg_connecting, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, msg_connecting, _tsizeof(msg) - _tcslen(msg) - 1);
else else
_tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1);
_tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, o.conn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1);
first_conn=0; first_conn=0;
} }
} }
if (CountConnectedState(CONNECTED) == 1) if (CountConnState(connected) == 1)
{ {
/* Append "Connected Since and Assigned IP msg" */ /* Append "Connected Since and Assigned IP msg" */
time_t con_time; time_t con_time;
con_time=time(NULL); con_time=time(NULL);
_tcsftime(connected_since, _tsizeof(connected_since), _T("%b %d, %H:%M"), _tcsftime(connected_since, _tsizeof(connected_since), _T("%b %d, %H:%M"),
localtime(&o.cnn[config].connected_since)); localtime(&o.conn[config].connected_since));
_tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _tsizeof(msg) - _tcslen(msg) - 1);
_tcsncat(msg, connected_since, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, connected_since, _tsizeof(msg) - _tcslen(msg) - 1);
if (_tcslen(o.cnn[config].ip) > 0) if (_tcslen(o.conn[config].ip) > 0)
{ {
TCHAR assigned_ip[100]; TCHAR assigned_ip[100];
_sntprintf_0(assigned_ip, LoadLocalizedString(IDS_TIP_ASSIGNED_IP), o.cnn[config].ip); _sntprintf_0(assigned_ip, LoadLocalizedString(IDS_TIP_ASSIGNED_IP), o.conn[config].ip);
_tcsncat(msg, assigned_ip, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, assigned_ip, _tsizeof(msg) - _tcslen(msg) - 1);
} }
} }
@ -427,7 +426,7 @@ void ShowTrayBalloon(TCHAR *infotitle_msg, TCHAR *info_msg)
} }
void SetMenuStatus (int config, int bCheck) void SetMenuStatus (int config, conn_state_t state)
{ {
/* bCheck values: /* bCheck values:
* 0 - Not Connected * 0 - Not Connected
@ -441,25 +440,25 @@ void SetMenuStatus (int config, int bCheck)
if (o.num_configs == 1) if (o.num_configs == 1)
{ {
if (bCheck == DISCONNECTED) if (state == disconnected)
{ {
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_ENABLED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_STATUSMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_GRAYED);
} }
if (bCheck == CONNECTING) if (state == connecting)
{ {
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED);
EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED);
} }
if (bCheck == CONNECTED) if (state == connected)
{ {
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED);
EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED);
} }
if (bCheck == DISCONNECTING) if (state == disconnecting)
{ {
EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED);
EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED);
@ -468,29 +467,29 @@ void SetMenuStatus (int config, int bCheck)
} }
else else
{ {
iState = ((bCheck == CONNECTED) || (bCheck == DISCONNECTING)) ? iState = ((state == connected) || (state == disconnecting)) ?
MF_CHECKED : MF_UNCHECKED ; MF_CHECKED : MF_UNCHECKED ;
CheckMenuItem (hMenu, (UINT) hMenuConn[config], iState) ; CheckMenuItem (hMenu, (UINT) hMenuConn[config], iState) ;
if (bCheck == DISCONNECTED) if (state == disconnected)
{ {
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_ENABLED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_GRAYED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_GRAYED);
} }
if (bCheck == CONNECTING) if (state == connecting)
{ {
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_ENABLED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_ENABLED);
} }
if (bCheck == CONNECTED) if (state == connected)
{ {
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_ENABLED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_ENABLED);
} }
if (bCheck == DISCONNECTING) if (state == disconnecting)
{ {
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED);
EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_GRAYED);
@ -513,15 +512,15 @@ void SetServiceMenuStatus()
hMenuHandle = hMenuService; hMenuHandle = hMenuService;
if ((o.service_running == SERVICE_NOACCESS) || if ((o.service_state == service_noaccess) ||
(o.service_running == SERVICE_CONNECTING)) (o.service_state == service_connecting))
{ {
/* Service is disabled */ /* Service is disabled */
EnableMenuItem(hMenuHandle, IDM_SERVICE_START, MF_GRAYED); EnableMenuItem(hMenuHandle, IDM_SERVICE_START, MF_GRAYED);
EnableMenuItem(hMenuHandle, IDM_SERVICE_STOP, MF_GRAYED); EnableMenuItem(hMenuHandle, IDM_SERVICE_STOP, MF_GRAYED);
EnableMenuItem(hMenuHandle, IDM_SERVICE_RESTART, MF_GRAYED); EnableMenuItem(hMenuHandle, IDM_SERVICE_RESTART, MF_GRAYED);
} }
else if (o.service_running == SERVICE_CONNECTED) else if (o.service_state == service_connected)
{ {
/* Service is running */ /* Service is running */
EnableMenuItem(hMenuHandle, IDM_SERVICE_START, MF_GRAYED); EnableMenuItem(hMenuHandle, IDM_SERVICE_START, MF_GRAYED);

6
tray.h
View File

@ -19,6 +19,8 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "options.h"
#define WM_NOTIFYICONTRAY (WM_APP + 1) #define WM_NOTIFYICONTRAY (WM_APP + 1)
//Popup Menu items //Popup Menu items
@ -52,10 +54,10 @@ void DestroyPopupMenus(); //Destroy popup menus
void OnNotifyTray(LPARAM lParam); //Tray message (mouse clicks on tray icon) void OnNotifyTray(LPARAM lParam); //Tray message (mouse clicks on tray icon)
void OnDestroyTray(void); //WM_DESTROY message void OnDestroyTray(void); //WM_DESTROY message
void ShowTrayIcon(); //Put app icon in systray void ShowTrayIcon(); //Put app icon in systray
void SetTrayIcon(int connected); //Change systray icon void SetTrayIcon(conn_state_t connected); //Change systray icon
BOOL LoadAppIcon(); //Application icon BOOL LoadAppIcon(); //Application icon
void CreateItemList(); //Crate Popup menu void CreateItemList(); //Crate Popup menu
void SetMenuStatus (int config, int bCheck); //Mark connection as connected/disconnected void SetMenuStatus (int config, conn_state_t state); //Mark connection as connected/disconnected
void SetServiceMenuStatus(); //Diabled Service menu items. void SetServiceMenuStatus(); //Diabled Service menu items.
void ShowTrayBalloon(TCHAR *infotitle_msg, TCHAR *info_msg); void ShowTrayBalloon(TCHAR *infotitle_msg, TCHAR *info_msg);

View File

@ -30,7 +30,7 @@
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h" #include "localization.h"
extern struct options o; extern options_t o;
void ViewLog(int config) void ViewLog(int config)
{ {
@ -46,7 +46,7 @@ void ViewLog(int config)
CLEAR (sa); CLEAR (sa);
CLEAR (sd); CLEAR (sd);
_sntprintf_0(filename, _T("%s \"%s\""), o.log_viewer, o.cnn[config].log_path); _sntprintf_0(filename, _T("%s \"%s\""), o.log_viewer, o.conn[config].log_path);
/* fill in STARTUPINFO struct */ /* fill in STARTUPINFO struct */
GetStartupInfo(&start_info); GetStartupInfo(&start_info);
@ -88,7 +88,7 @@ void EditConfig(int config)
CLEAR (sa); CLEAR (sa);
CLEAR (sd); CLEAR (sd);
_sntprintf_0(filename, _T("%s \"%s\\%s\""), o.editor, o.cnn[config].config_dir, o.cnn[config].config_file); _sntprintf_0(filename, _T("%s \"%s\\%s\""), o.editor, o.conn[config].config_dir, o.conn[config].config_file);
/* fill in STARTUPINFO struct */ /* fill in STARTUPINFO struct */
GetStartupInfo(&start_info); GetStartupInfo(&start_info);
@ -105,7 +105,7 @@ void EditConfig(int config)
TRUE, TRUE,
CREATE_NEW_CONSOLE, CREATE_NEW_CONSOLE,
NULL, NULL,
o.cnn[config].config_dir, //start-up dir o.conn[config].config_dir, //start-up dir
&start_info, &start_info,
&proc_info)) &proc_info))
{ {