Show a prompt during profile import using --import

The user is prompted with a message showing the config
name that will be imported. The user can accept or cancel
the operation.

If the user was already prompted for over-write permission
because a config with the same name exists, no further dialog
is shown.

Import using the menu (Import File...) is not affected.

Rationale:
We want to set "Import" as the default verb for the context
menu of .ovpn files. This will allow import of configs by
double-click. Also when .ovpn file is downloaded using a browser,
setting the default bowser action to "open" will result in an import.
In such cases a silent import action could be surprising, and a
prompt showing what is being imported could provide a better UX.

On the flip-side, the prompt/dialog will also be shown when import
is done from the context menu of .ovpn by "right click and
choose import" or when "openvpn-gui.exe --import foo"
or "openvpn-gui.exe --command import foo" is executed. As import
is an action that does not result in an immediately visible result
(unlike, say, edit or print), a prompt requiring user action is of
some value even in these cases. At worst it's a minor annoyance.

See also: https://github.com/OpenVPN/openvpn-build/pull/227
and discussions there-in

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/469/head
Selva Nair 2021-11-16 23:11:26 -05:00
parent 650663dd62
commit 9c82e666d8
6 changed files with 14 additions and 6 deletions

2
as.c
View File

@ -682,7 +682,7 @@ ImportProfileFromURLDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
if (downloaded) {
EndDialog(hwndDlg, LOWORD(wParam));
ImportConfigFile(path);
ImportConfigFile(path, false); /* do not prompt user */
_wunlink(path);
}
return TRUE;

6
main.c
View File

@ -471,7 +471,7 @@ HandleCopyDataMessage(const COPYDATASTRUCT *copy_data)
}
else if(copy_data->dwData == WM_OVPN_IMPORT && str)
{
ImportConfigFile(str);
ImportConfigFile(str, true); /* prompt user */
}
else if (copy_data->dwData == WM_OVPN_NOTIFY)
{
@ -531,7 +531,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
/* if '--import' was specified, do it now */
if (o.action == WM_OVPN_IMPORT && o.action_arg)
{
ImportConfigFile(o.action_arg);
ImportConfigFile(o.action_arg, true); /* prompt user */
}
if (!AutoStartConnections()) {
@ -794,7 +794,7 @@ ImportConfigFileFromDisk()
if (GetOpenFileName(&fn))
{
ImportConfigFile(source);
ImportConfigFile(source, false); /* do not prompt user */
}
}

8
misc.c
View File

@ -646,7 +646,7 @@ open_url(const wchar_t *url)
extern options_t o;
void
ImportConfigFile(const TCHAR* source)
ImportConfigFile(const TCHAR* source, bool prompt_user)
{
TCHAR fileName[MAX_PATH] = _T("");
TCHAR ext[MAX_PATH] = _T("");
@ -683,6 +683,12 @@ ImportConfigFile(const TCHAR* source)
}
else
{
if (prompt_user
&& ShowLocalizedMsgEx(MB_YESNO, NULL, TEXT(PACKAGE_NAME),
IDS_NFO_IMPORT_SOURCE, fileName) == IDNO)
{
return;
}
WCHAR dest_dir[MAX_PATH+1];
swprintf(dest_dir, MAX_PATH, L"%ls\\%ls", o.config_dir, fileName);
dest_dir[MAX_PATH] = L'\0';

2
misc.h
View File

@ -72,7 +72,7 @@ DWORD md_final(md_ctx *ctx, BYTE *md);
/* Open specified http/https URL using ShellExecute. */
BOOL open_url(const wchar_t *url);
void ImportConfigFile(const TCHAR* path);
void ImportConfigFile(const TCHAR* path, bool prompt_user);
/*
* Helper function to convert UCS-2 text from a dialog item to UTF-8.

View File

@ -339,6 +339,7 @@
#define IDS_NFO_IMPORT_OVERWRITE 1904
#define IDS_ERR_IMPORT_SOURCE 1905
#define IDS_ERR_IMPORT_ACCESS 1906
#define IDS_NFO_IMPORT_SOURCE 1907
/* Save password related messages */
#define IDS_NFO_DELETE_PASS 2001

View File

@ -521,6 +521,7 @@ once as Administrator to update the registry."
%ls\n\nMake sure you have the right permissions."
IDS_NFO_IMPORT_SUCCESS "File imported successfully."
IDS_NFO_IMPORT_OVERWRITE "A config named ""%ls"" already exists. Do you want to replace it?"
IDS_NFO_IMPORT_SOURCE "Do you want to import the profile <%ls>?"
IDS_ERR_IMPORT_SOURCE "Cannot import file <%ls> as it is already in the global or local config directory"
IDS_ERR_IMPORT_ACCESS "Cannot import <%ls> as it is missing or not readable"