mirror of https://github.com/OpenVPN/openvpn-gui
keep trying to connect to mgmt itf for 15 seconds
parent
2647513238
commit
b9edb7e62a
23
manage.c
23
manage.c
|
@ -36,6 +36,10 @@ extern options_t o;
|
||||||
|
|
||||||
static mgmt_msg_func rtmsg_handler[mgmt_rtmsg_type_max];
|
static mgmt_msg_func rtmsg_handler[mgmt_rtmsg_type_max];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Number of seconds to try connecting to management interface
|
||||||
|
*/
|
||||||
|
static const time_t max_connect_time = 15;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the real-time notification handlers
|
* Initialize the real-time notification handlers
|
||||||
|
@ -56,15 +60,9 @@ InitManagement(const mgmt_rtmsg_handler *handler)
|
||||||
* asynchronous socket event notification for it
|
* asynchronous socket event notification for it
|
||||||
*/
|
*/
|
||||||
BOOL
|
BOOL
|
||||||
OpenManagement(connection_t *c, u_long addr, u_short port)
|
OpenManagement(connection_t *c)
|
||||||
{
|
{
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
SOCKADDR_IN skaddr = {
|
|
||||||
.sin_family = AF_INET,
|
|
||||||
.sin_addr.s_addr = addr,
|
|
||||||
.sin_port = htons(port)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -76,7 +74,8 @@ OpenManagement(connection_t *c, u_long addr, u_short port)
|
||||||
FD_CONNECT|FD_READ|FD_WRITE|FD_CLOSE) != 0)
|
FD_CONNECT|FD_READ|FD_WRITE|FD_CLOSE) != 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
connect(c->manage.sk, (SOCKADDR *)&skaddr, sizeof(skaddr));
|
connect(c->manage.sk, (SOCKADDR *)&c->manage.skaddr, sizeof(c->manage.skaddr));
|
||||||
|
c->manage.timeout = time(NULL) + max_connect_time;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -200,8 +199,12 @@ OnManagement(SOCKET sk, LPARAM lParam)
|
||||||
switch (WSAGETSELECTEVENT(lParam))
|
switch (WSAGETSELECTEVENT(lParam))
|
||||||
{
|
{
|
||||||
case FD_CONNECT:
|
case FD_CONNECT:
|
||||||
if (WSAGETSELECTERROR(lParam))
|
if (WSAGETSELECTERROR(lParam)) {
|
||||||
SendMessage(c->hwndStatus, WM_CLOSE, 0, 0);
|
if (time(NULL) < c->manage.timeout)
|
||||||
|
connect(c->manage.sk, (SOCKADDR *)&c->manage.skaddr, sizeof(c->manage.skaddr));
|
||||||
|
else
|
||||||
|
SendMessage(c->hwndStatus, WM_CLOSE, 0, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FD_READ:
|
case FD_READ:
|
||||||
|
|
2
manage.h
2
manage.h
|
@ -63,7 +63,7 @@ typedef struct mgmt_cmd {
|
||||||
|
|
||||||
|
|
||||||
void InitManagement(const mgmt_rtmsg_handler *handler);
|
void InitManagement(const mgmt_rtmsg_handler *handler);
|
||||||
BOOL OpenManagement(connection_t *, u_long, u_short);
|
BOOL OpenManagement(connection_t *);
|
||||||
BOOL ManagementCommand(connection_t *, char *, mgmt_msg_func, mgmt_cmd_type);
|
BOOL ManagementCommand(connection_t *, char *, mgmt_msg_func, mgmt_cmd_type);
|
||||||
|
|
||||||
void OnManagement(SOCKET, LPARAM);
|
void OnManagement(SOCKET, LPARAM);
|
||||||
|
|
|
@ -539,7 +539,7 @@ ThreadOpenVPNStatus(void *p)
|
||||||
SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING));
|
SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING));
|
||||||
SetWindowText(c->hwndStatus, LoadLocalizedString(IDS_NFO_CONNECTION_XXX, conn_name));
|
SetWindowText(c->hwndStatus, LoadLocalizedString(IDS_NFO_CONNECTION_XXX, conn_name));
|
||||||
|
|
||||||
if (!OpenManagement(c, inet_addr("127.0.0.10"), c->manage.port))
|
if (!OpenManagement(c))
|
||||||
PostMessage(c->hwndStatus, WM_CLOSE, 0, 0);
|
PostMessage(c->hwndStatus, WM_CLOSE, 0, 0);
|
||||||
|
|
||||||
if (o.silent_connection[0] == '0')
|
if (o.silent_connection[0] == '0')
|
||||||
|
@ -660,11 +660,12 @@ StartOpenVPN(connection_t *c)
|
||||||
/* Construct command line */
|
/* Construct command line */
|
||||||
_sntprintf_0(cmdline, _T("openvpn "
|
_sntprintf_0(cmdline, _T("openvpn "
|
||||||
"--config \"%s\" %s --service %s 0 --log%s \"%s\" "
|
"--config \"%s\" %s --service %s 0 --log%s \"%s\" "
|
||||||
"--management 127.0.0.10 %hd stdin --auth-retry interact "
|
"--management %S %hd stdin --auth-retry interact "
|
||||||
"--management-hold --management-query-passwords --tls-exit"),
|
"--management-hold --management-query-passwords --tls-exit"),
|
||||||
c->config_file, proxy_string, exit_event_name,
|
c->config_file, proxy_string, exit_event_name,
|
||||||
(o.append_string[0] == '1' ? _T("-append") : _T("")),
|
(o.append_string[0] == '1' ? _T("-append") : _T("")),
|
||||||
c->log_path, c->manage.port);
|
c->log_path, inet_ntoa(c->manage.skaddr.sin_addr),
|
||||||
|
ntohs(c->manage.skaddr.sin_port));
|
||||||
|
|
||||||
/* Try to open the service pipe */
|
/* Try to open the service pipe */
|
||||||
service = CreateFile(_T("\\\\.\\pipe\\openvpn\\service"),
|
service = CreateFile(_T("\\\\.\\pipe\\openvpn\\service"),
|
||||||
|
|
|
@ -78,23 +78,26 @@ 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.conn[config];
|
connection_t *c = &o.conn[config];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
_tcsncpy(conn->config_file, filename, _countof(conn->config_file) - 1);
|
_tcsncpy(c->config_file, filename, _countof(c->config_file) - 1);
|
||||||
_tcsncpy(conn->config_dir, config_dir, _countof(conn->config_dir) - 1);
|
_tcsncpy(c->config_dir, config_dir, _countof(c->config_dir) - 1);
|
||||||
_tcsncpy(conn->config_name, conn->config_file, _countof(conn->config_name) - 1);
|
_tcsncpy(c->config_name, c->config_file, _countof(c->config_name) - 1);
|
||||||
conn->config_name[_tcslen(conn->config_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
c->config_name[_tcslen(c->config_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
||||||
_sntprintf_0(conn->log_path, _T("%s\\%s.log"), o.log_dir, conn->config_name);
|
_sntprintf_0(c->log_path, _T("%s\\%s.log"), o.log_dir, c->config_name);
|
||||||
conn->manage.sk = INVALID_SOCKET;
|
|
||||||
conn->manage.port = 25340 + config;
|
c->manage.sk = INVALID_SOCKET;
|
||||||
|
c->manage.skaddr.sin_family = AF_INET;
|
||||||
|
c->manage.skaddr.sin_addr.s_addr = inet_addr("127.0.0.10");
|
||||||
|
c->manage.skaddr.sin_port = htons(25340 + config);
|
||||||
|
|
||||||
/* Check if connection should be autostarted */
|
/* Check if connection should be autostarted */
|
||||||
for (i = 0; i < MAX_CONFIGS && o.auto_connect[i]; ++i)
|
for (i = 0; i < MAX_CONFIGS && o.auto_connect[i]; ++i)
|
||||||
{
|
{
|
||||||
if (_tcsicmp(conn->config_file, o.auto_connect[i]) == 0)
|
if (_tcsicmp(c->config_file, o.auto_connect[i]) == 0)
|
||||||
{
|
{
|
||||||
conn->auto_connect = true;
|
c->auto_connect = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue