mirror of https://github.com/OpenVPN/openvpn-gui
Support user and global config directories
- Set default config directory (config_dir) to %UserProfile%\OpenVPN\config (saved and read back from HKCU\Software\OpenVPN-GUI\config_dir) - Add a global_config_dir variable read from HKLM\Software\OpenVPN\config_dir or set to OpenVPN-install-path\config - Scan both directories and their sub directories for connection profiles. In case of name conflicts config_dir gets priority over global_config_dir - Eliminate multiple warnings of duplicate configs Fixed on review (Thanks to leobasilio@gmail.com) - Fix wrongly used o.config_dir in 2 locations - Unrelated: Added missing CheckIServiceStatus to service.h Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/18/head
parent
7f73bcca0b
commit
77538dd0d0
2
main.c
2
main.c
|
@ -170,6 +170,8 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
|
||||||
if (!GetRegistryKeys()) {
|
if (!GetRegistryKeys()) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
EnsureDirExists(o.config_dir);
|
||||||
|
|
||||||
if (!CheckVersion()) {
|
if (!CheckVersion()) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ ConfigAlreadyExists(TCHAR *newconfig)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
AddConfigFileToList(int config, TCHAR *filename, TCHAR *config_dir)
|
AddConfigFileToList(int config, const TCHAR *filename, const TCHAR *config_dir)
|
||||||
{
|
{
|
||||||
connection_t *c = &o.conn[config];
|
connection_t *c = &o.conn[config];
|
||||||
int i;
|
int i;
|
||||||
|
@ -120,22 +120,18 @@ AddConfigFileToList(int config, TCHAR *filename, TCHAR *config_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
BuildFileList()
|
BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA find_obj;
|
WIN32_FIND_DATA find_obj;
|
||||||
HANDLE find_handle;
|
HANDLE find_handle;
|
||||||
TCHAR find_string[MAX_PATH];
|
TCHAR find_string[MAX_PATH];
|
||||||
TCHAR subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH];
|
TCHAR subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH];
|
||||||
TCHAR fullpath[MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
static int warn_no_configs = 1;
|
|
||||||
int subdirs = 0;
|
int subdirs = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Reset config counter */
|
_sntprintf_0(find_string, _T("%s\\*"), config_dir);
|
||||||
o.num_configs = 0;
|
|
||||||
|
|
||||||
_sntprintf_0(find_string, _T("%s\\*"), o.config_dir);
|
|
||||||
find_handle = FindFirstFile(find_string, &find_obj);
|
find_handle = FindFirstFile(find_string, &find_obj);
|
||||||
if (find_handle == INVALID_HANDLE_VALUE)
|
if (find_handle == INVALID_HANDLE_VALUE)
|
||||||
return;
|
return;
|
||||||
|
@ -152,9 +148,17 @@ BuildFileList()
|
||||||
match_t match_type = match(&find_obj, o.ext_string);
|
match_t match_type = match(&find_obj, o.ext_string);
|
||||||
if (match_type == match_file)
|
if (match_type == match_file)
|
||||||
{
|
{
|
||||||
_sntprintf_0(fullpath, _T("%s\\%s"), o.config_dir, find_obj.cFileName);
|
_sntprintf_0(fullpath, _T("%s\\%s"), config_dir, find_obj.cFileName);
|
||||||
|
|
||||||
|
if (ConfigAlreadyExists(find_obj.cFileName))
|
||||||
|
{
|
||||||
|
if (warn_duplicates)
|
||||||
|
ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (CheckReadAccess (fullpath))
|
if (CheckReadAccess (fullpath))
|
||||||
AddConfigFileToList(o.num_configs++, find_obj.cFileName, o.config_dir);
|
AddConfigFileToList(o.num_configs++, find_obj.cFileName, config_dir);
|
||||||
}
|
}
|
||||||
else if (match_type == match_dir)
|
else if (match_type == match_dir)
|
||||||
{
|
{
|
||||||
|
@ -163,7 +167,7 @@ BuildFileList()
|
||||||
&& subdirs < MAX_CONFIG_SUBDIRS)
|
&& subdirs < MAX_CONFIG_SUBDIRS)
|
||||||
{
|
{
|
||||||
/* Add dir to dir_table */
|
/* Add dir to dir_table */
|
||||||
_sntprintf_0(subdir_table[subdirs], _T("%s\\%s"), o.config_dir, find_obj.cFileName);
|
_sntprintf_0(subdir_table[subdirs], _T("%s\\%s"), config_dir, find_obj.cFileName);
|
||||||
subdirs++;
|
subdirs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +199,8 @@ BuildFileList()
|
||||||
|
|
||||||
if (ConfigAlreadyExists(find_obj.cFileName))
|
if (ConfigAlreadyExists(find_obj.cFileName))
|
||||||
{
|
{
|
||||||
ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName);
|
if (warn_duplicates)
|
||||||
|
ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,9 +209,22 @@ BuildFileList()
|
||||||
|
|
||||||
FindClose(find_handle);
|
FindClose(find_handle);
|
||||||
}
|
}
|
||||||
if (o.num_configs == 0 && warn_no_configs)
|
}
|
||||||
{
|
|
||||||
ShowLocalizedMsg(IDS_NFO_NO_CONFIGS, o.config_dir);
|
void
|
||||||
warn_no_configs = 0;
|
BuildFileList()
|
||||||
}
|
{
|
||||||
|
static bool issue_warnings = true;
|
||||||
|
|
||||||
|
o.num_configs = 0;
|
||||||
|
|
||||||
|
BuildFileList0 (o.config_dir, issue_warnings);
|
||||||
|
|
||||||
|
if (_tcscmp (o.global_config_dir, o.config_dir))
|
||||||
|
BuildFileList0 (o.global_config_dir, issue_warnings);
|
||||||
|
|
||||||
|
if (o.num_configs == 0 && issue_warnings)
|
||||||
|
ShowLocalizedMsg(IDS_NFO_NO_CONFIGS);
|
||||||
|
|
||||||
|
issue_warnings = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ typedef struct {
|
||||||
/* Registry values */
|
/* Registry values */
|
||||||
TCHAR exe_path[MAX_PATH];
|
TCHAR exe_path[MAX_PATH];
|
||||||
TCHAR config_dir[MAX_PATH];
|
TCHAR config_dir[MAX_PATH];
|
||||||
|
TCHAR global_config_dir[MAX_PATH];
|
||||||
TCHAR ext_string[16];
|
TCHAR ext_string[16];
|
||||||
TCHAR log_dir[MAX_PATH];
|
TCHAR log_dir[MAX_PATH];
|
||||||
TCHAR priority_string[64];
|
TCHAR priority_string[64];
|
||||||
|
|
|
@ -73,8 +73,15 @@ GetRegistryKeys()
|
||||||
if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\'))
|
if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\'))
|
||||||
_tcscat(openvpn_path, _T("\\"));
|
_tcscat(openvpn_path, _T("\\"));
|
||||||
|
|
||||||
|
/* an admin-defined global config dir defined in HKLM\OpenVPN\config_dir */
|
||||||
|
if (!GetRegistryValue(regkey, _T("config_dir"), o.global_config_dir, _countof(o.global_config_dir)))
|
||||||
|
{
|
||||||
|
/* use default = openvpnpath\config */
|
||||||
|
_sntprintf_0(o.global_config_dir, _T("%sconfig"), openvpn_path);
|
||||||
|
}
|
||||||
|
|
||||||
_sntprintf_0(temp_path, _T("%sconfig"), openvpn_path);
|
/* config_dir in user's profile by default */
|
||||||
|
_sntprintf_0(temp_path, _T("%s\\OpenVPN\\config"), profile_dir);
|
||||||
if (!GetRegKey(_T("config_dir"), o.config_dir,
|
if (!GetRegKey(_T("config_dir"), o.config_dir,
|
||||||
temp_path, _countof(o.config_dir))) return(false);
|
temp_path, _countof(o.config_dir))) return(false);
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ BEGIN
|
||||||
|
|
||||||
/* OpenVPN */
|
/* OpenVPN */
|
||||||
IDS_ERR_MANY_CONFIGS "OpenVPN GUI does not support more than %d configs. Please contact the author if you have the need for more."
|
IDS_ERR_MANY_CONFIGS "OpenVPN GUI does not support more than %d configs. Please contact the author if you have the need for more."
|
||||||
IDS_NFO_NO_CONFIGS "No readable connection profiles (config files) found at %s"
|
IDS_NFO_NO_CONFIGS "No readable connection profiles (config files) found"
|
||||||
IDS_ERR_ONE_CONN_OLD_VER "You can only have one connection running at the same time when using an older version on OpenVPN than 2.0-beta6."
|
IDS_ERR_ONE_CONN_OLD_VER "You can only have one connection running at the same time when using an older version on OpenVPN than 2.0-beta6."
|
||||||
IDS_ERR_STOP_SERV_OLD_VER "You cannot use OpenVPN GUI to start a connection while the OpenVPN Service is running (with OpenVPN 1.5/1.6). Stop OpenVPN Service first if you want to use OpenVPN GUI."
|
IDS_ERR_STOP_SERV_OLD_VER "You cannot use OpenVPN GUI to start a connection while the OpenVPN Service is running (with OpenVPN 1.5/1.6). Stop OpenVPN Service first if you want to use OpenVPN GUI."
|
||||||
IDS_ERR_CREATE_EVENT "CreateEvent failed on exit event: %s"
|
IDS_ERR_CREATE_EVENT "CreateEvent failed on exit event: %s"
|
||||||
|
|
Loading…
Reference in New Issue