From d0c37ecbccdadd52452dc6f2a5b5091892c90cdd Mon Sep 17 00:00:00 2001 From: Leonardo Basilio Date: Tue, 16 Feb 2016 22:19:52 -0200 Subject: [PATCH 1/5] Updating README build instructions --- README | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README b/README index 323361b..22c27c4 100644 --- a/README +++ b/README @@ -228,4 +228,8 @@ Building OpenVPN GUI from source * Start a bash shell by running msys.bat. -* Run "make" from the OpenVPN GUI source directory. +* Run at the OpenVPN GUI source directory: + +$ autoreconf -i +$ ./configure +$ make From 46a1bc715cc18e9d782e503cdcba5dfddde780e8 Mon Sep 17 00:00:00 2001 From: Leonardo Basilio Date: Tue, 16 Feb 2016 22:20:53 -0200 Subject: [PATCH 2/5] Adding "Import file" feature --- main.c | 54 +++++++++++++++++++++++++++++++++++++++ openvpn-gui-res.h | 6 +++++ res/openvpn-gui-res-en.rc | 5 ++++ res/openvpn-gui-res-pt.rc | 5 ++++ tray.c | 2 ++ tray.h | 1 + 6 files changed, 73 insertions(+) diff --git a/main.c b/main.c index 20e81ab..5f3644d 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "tray.h" #include "openvpn.h" @@ -53,6 +54,7 @@ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); static void ShowSettingsDialog(); void CloseApplication(HWND hwnd); +void ImportConfigFile(); /* Class name and window title */ TCHAR szClassName[ ] = _T("OpenVPN-GUI"); @@ -349,6 +351,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM ShowChangePassphraseDialog(&o.conn[LOWORD(wParam) - IDM_PASSPHRASEMENU]); } #endif + if (LOWORD(wParam) == IDM_IMPORT) { + ImportConfigFile(); + } if (LOWORD(wParam) == IDM_SETTINGS) { ShowSettingsDialog(); } @@ -525,6 +530,55 @@ CloseApplication(HWND hwnd) DestroyWindow(hwnd); } +void +ImportConfigFile() +{ + + TCHAR filter[32]; + + memset(filter, 0, sizeof(filter)); + _sntprintf_0(filter, _T("*.%s *.%s"), o.ext_string, o.ext_string); + filter[2 + _tcslen(o.ext_string)] = _T('\0'); + + OPENFILENAME fn; + TCHAR source[MAX_PATH] = _T(""); + + fn.lStructSize = sizeof(OPENFILENAME); + fn.hwndOwner = NULL; + fn.lpstrFilter = filter; + fn.lpstrCustomFilter = NULL; + fn.nFilterIndex = 1; + fn.lpstrFile = source; + fn.nMaxFile = MAX_PATH; + fn.lpstrFileTitle = NULL; + fn.lpstrInitialDir = NULL; + fn.lpstrTitle = NULL; + fn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST; + fn.lpstrDefExt = NULL; + + if (GetOpenFileName(&fn)) + { + + TCHAR destination[MAX_PATH]; + PTCHAR fileName = source + fn.nFileOffset; + + _sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName); + + if (!CopyFile(source, destination, TRUE)) + { + if (GetLastError() == ERROR_FILE_EXISTS) + { + fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0'); + ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName); + } + else + ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED); + } + + } + +} + #ifdef DEBUG void PrintDebugMsg(TCHAR *msg) { diff --git a/openvpn-gui-res.h b/openvpn-gui-res.h index 8377ce3..aee142e 100644 --- a/openvpn-gui-res.h +++ b/openvpn-gui-res.h @@ -107,6 +107,7 @@ #define IDS_MENU_SERVICEONLY_STOP 1020 #define IDS_MENU_SERVICEONLY_RESTART 1021 #define IDS_MENU_ASK_STOP_SERVICE 1022 +#define IDS_MENU_IMPORT 1023 /* LogViewer Dialog */ #define IDS_ERR_START_LOG_VIEWER 1101 @@ -241,4 +242,9 @@ #define IDS_ERR_WRITE_REGVALUE 1812 #define IDS_ERR_GET_PROFILE_DIR 1813 +/* Importation Related */ + +#define IDS_ERR_IMPORT_EXISTS 1901 +#define IDS_ERR_IMPORT_FAILED 1902 + #endif diff --git a/res/openvpn-gui-res-en.rc b/res/openvpn-gui-res-en.rc index 431f4bd..e6e4f7d 100644 --- a/res/openvpn-gui-res-en.rc +++ b/res/openvpn-gui-res-en.rc @@ -160,6 +160,7 @@ BEGIN IDS_TIP_CONNECTED_SINCE "\nConnected since: " IDS_TIP_ASSIGNED_IP "\nAssigned IP: %s" IDS_MENU_SERVICE "OpenVPN Service" + IDS_MENU_IMPORT "Import file…" IDS_MENU_SETTINGS "Settings…" IDS_MENU_CLOSE "Exit" IDS_MENU_CONNECT "Connect" @@ -339,4 +340,8 @@ BEGIN "once as Administrator to update the registry." IDS_ERR_READ_SET_KEY "Error reading and setting registry key ""%s""." IDS_ERR_WRITE_REGVALUE "Error writing registry value ""HKEY_CURRENT_USER\\%s\\%s""." + + /* importation */ + IDS_ERR_IMPORT_EXISTS "A config named ""%s"" already exists." + IDS_ERR_IMPORT_FAILED "Failed to import file." END diff --git a/res/openvpn-gui-res-pt.rc b/res/openvpn-gui-res-pt.rc index 5d1eb5d..6456346 100644 --- a/res/openvpn-gui-res-pt.rc +++ b/res/openvpn-gui-res-pt.rc @@ -147,6 +147,7 @@ BEGIN IDS_TIP_CONNECTED_SINCE "\nConectado desde: " IDS_TIP_ASSIGNED_IP "\nIP atribuído: %s" IDS_MENU_SERVICE "Serviço OpenVPN" + IDS_MENU_IMPORT "Importar arquivo…" IDS_MENU_SETTINGS "Configurações…" IDS_MENU_CLOSE "Sair" IDS_MENU_CONNECT "Conectar" @@ -324,4 +325,8 @@ BEGIN "uma vez como Administrador para alterar o registro." IDS_ERR_READ_SET_KEY "Erro ao ler e ajustar chave de registro ""%s""." IDS_ERR_WRITE_REGVALUE "Erro ao gravar valor da chave de registro ""HKEY_CURRENT_USER\\%s\\%s""." + + /* importation */ + IDS_ERR_IMPORT_EXISTS "Já existe uma configuração com o nome ""%s""." + IDS_ERR_IMPORT_FAILED "Falha ao importar o arquivo." END diff --git a/tray.c b/tray.c index 018b00e..150a106 100644 --- a/tray.c +++ b/tray.c @@ -91,6 +91,7 @@ CreatePopupMenus() AppendMenu(hMenu, MF_SEPARATOR, 0, 0); } + AppendMenu(hMenu, MF_STRING, IDM_IMPORT, LoadLocalizedString(IDS_MENU_IMPORT)); AppendMenu(hMenu, MF_STRING ,IDM_SETTINGS, LoadLocalizedString(IDS_MENU_SETTINGS)); AppendMenu(hMenu, MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDS_MENU_CLOSE)); @@ -116,6 +117,7 @@ CreatePopupMenus() AppendMenu(hMenu, MF_SEPARATOR, 0, 0); } + AppendMenu(hMenu, MF_STRING, IDM_IMPORT, LoadLocalizedString(IDS_MENU_IMPORT)); AppendMenu(hMenu, MF_STRING, IDM_SETTINGS, LoadLocalizedString(IDS_MENU_SETTINGS)); AppendMenu(hMenu, MF_STRING, IDM_CLOSE, LoadLocalizedString(IDS_MENU_CLOSE)); diff --git a/tray.h b/tray.h index 9225eff..f417698 100644 --- a/tray.h +++ b/tray.h @@ -33,6 +33,7 @@ #define IDM_SETTINGS 221 #define IDM_CLOSE 223 +#define IDM_IMPORT 224 #define IDM_CONNECTMENU 300 #define IDM_DISCONNECTMENU (MAX_CONFIGS + IDM_CONNECTMENU) From 01051c51be080be4830ee7ebb9c8f2887e153363 Mon Sep 17 00:00:00 2001 From: Leonardo Basilio Date: Tue, 16 Feb 2016 22:50:20 -0200 Subject: [PATCH 3/5] Make sure full config path exists before importing file --- main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.c b/main.c index 5f3644d..361f0e5 100644 --- a/main.c +++ b/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "tray.h" #include "openvpn.h" @@ -562,6 +563,9 @@ ImportConfigFile() TCHAR destination[MAX_PATH]; PTCHAR fileName = source + fn.nFileOffset; + /* make sure full config path exists */ + SHCreateDirectoryEx(NULL, o.config_dir, NULL); + _sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName); if (!CopyFile(source, destination, TRUE)) From 4c429d0b6b987d600176c8a0608d6dcf76108063 Mon Sep 17 00:00:00 2001 From: Leonardo Basilio Date: Thu, 18 Feb 2016 14:03:02 -0200 Subject: [PATCH 4/5] Fixes following pull request discussion * Proper filter string size * Copy config to subdirectory --- main.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 361f0e5..0a04546 100644 --- a/main.c +++ b/main.c @@ -29,7 +29,6 @@ #include #include #include -#include #include "tray.h" #include "openvpn.h" @@ -535,11 +534,9 @@ void ImportConfigFile() { - TCHAR filter[32]; + TCHAR filter[37]; - memset(filter, 0, sizeof(filter)); - _sntprintf_0(filter, _T("*.%s *.%s"), o.ext_string, o.ext_string); - filter[2 + _tcslen(o.ext_string)] = _T('\0'); + _sntprintf_0(filter, _T("*.%s%c*.%s%c"), o.ext_string, _T('\0'), o.ext_string, _T('\0')); OPENFILENAME fn; TCHAR source[MAX_PATH] = _T(""); @@ -559,26 +556,35 @@ ImportConfigFile() if (GetOpenFileName(&fn)) { - + TCHAR destination[MAX_PATH]; PTCHAR fileName = source + fn.nFileOffset; - /* make sure full config path exists */ - SHCreateDirectoryEx(NULL, o.config_dir, NULL); - _sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName); + + destination[_tcslen(destination) - _tcslen(o.ext_string) - 1] = _T('\0'); - if (!CopyFile(source, destination, TRUE)) + if (EnsureDirExists(destination)) { - if (GetLastError() == ERROR_FILE_EXISTS) + + _sntprintf_0(destination, _T("%s\\%s"), destination, fileName); + + if (!CopyFile(source, destination, TRUE)) { - fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0'); - ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName); + if (GetLastError() == ERROR_FILE_EXISTS) + { + fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0'); + ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName); + return; + } } else - ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED); + return; + } + ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED); + } } From b47d3545e4b658fc14500432bbb2de71171f9f81 Mon Sep 17 00:00:00 2001 From: Leonardo Basilio Date: Sun, 21 Feb 2016 12:15:40 -0300 Subject: [PATCH 5/5] Improving feedback messages when importing --- main.c | 5 ++++- openvpn-gui-res.h | 1 + res/openvpn-gui-res-en.rc | 4 +++- res/openvpn-gui-res-pt.rc | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 0a04546..03c0fc2 100644 --- a/main.c +++ b/main.c @@ -579,11 +579,14 @@ ImportConfigFile() } } else + { + ShowLocalizedMsg(IDS_NFO_IMPORT_SUCCESS); return; + } } - ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED); + ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED, destination); } diff --git a/openvpn-gui-res.h b/openvpn-gui-res.h index aee142e..4ff7c4e 100644 --- a/openvpn-gui-res.h +++ b/openvpn-gui-res.h @@ -246,5 +246,6 @@ #define IDS_ERR_IMPORT_EXISTS 1901 #define IDS_ERR_IMPORT_FAILED 1902 +#define IDS_NFO_IMPORT_SUCCESS 1903 #endif diff --git a/res/openvpn-gui-res-en.rc b/res/openvpn-gui-res-en.rc index e6e4f7d..aa028bb 100644 --- a/res/openvpn-gui-res-en.rc +++ b/res/openvpn-gui-res-en.rc @@ -343,5 +343,7 @@ BEGIN /* importation */ IDS_ERR_IMPORT_EXISTS "A config named ""%s"" already exists." - IDS_ERR_IMPORT_FAILED "Failed to import file." + IDS_ERR_IMPORT_FAILED "Failed to import file. The following path could not be created.\n\n" \ + "%s\n\nMake sure you have the right permissions." + IDS_NFO_IMPORT_SUCCESS "File imported successfully." END diff --git a/res/openvpn-gui-res-pt.rc b/res/openvpn-gui-res-pt.rc index 6456346..78ed4c2 100644 --- a/res/openvpn-gui-res-pt.rc +++ b/res/openvpn-gui-res-pt.rc @@ -328,5 +328,7 @@ BEGIN /* importation */ IDS_ERR_IMPORT_EXISTS "Já existe uma configuração com o nome ""%s""." - IDS_ERR_IMPORT_FAILED "Falha ao importar o arquivo." + IDS_ERR_IMPORT_FAILED "Falha ao importar o arquivo. O seguinte caminho não pôde ser criado.\n\n" \ + "%s\n\nCertifique-se de que você possui as permissões necessárias." + IDS_NFO_IMPORT_SUCCESS "Arquivo importado com sucesso." END