From 824906707611296cb184c41c7abe8af6a9a79b1e Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Wed, 20 Jul 2011 17:28:08 +0200 Subject: [PATCH] let openvpn determine the Windows proxy settings --- openvpn-gui-res-de.rc | 2 +- openvpn-gui-res-en.rc | 2 +- openvpn-gui-res-fi.rc | 2 +- openvpn-gui-res-nl.rc | 2 +- openvpn-gui-res-pl.rc | 0 options.h | 2 +- proxy.c | 91 +++---------------------------------------- 7 files changed, 10 insertions(+), 91 deletions(-) mode change 100755 => 100644 openvpn-gui-res-pl.rc diff --git a/openvpn-gui-res-de.rc b/openvpn-gui-res-de.rc index 653115a..05d2b12 100644 --- a/openvpn-gui-res-de.rc +++ b/openvpn-gui-res-de.rc @@ -115,7 +115,7 @@ BEGIN GROUPBOX " ", 201, 6, 46, 235, 52 AUTORADIOBUTTON "OpenVPN Konfigurationsdatei verwenden", ID_RB_PROXY_OPENVPN, \ 13, 16, 200, 10, WS_GROUP | WS_TABSTOP - AUTORADIOBUTTON "Internet Explorer Einstellungen verwenden", \ + AUTORADIOBUTTON "System Proxy-Einstellungen verwenden", \ ID_RB_PROXY_MSIE, 13, 31, 200, 10 AUTORADIOBUTTON "Manuelle Konfiguration", ID_RB_PROXY_MANUAL, 13, 46, 85, 10 AUTORADIOBUTTON "HTTP Proxy", ID_RB_PROXY_HTTP, 20, 62, 90, 10, WS_GROUP | WS_TABSTOP diff --git a/openvpn-gui-res-en.rc b/openvpn-gui-res-en.rc index f1fcfdd..49748af 100644 --- a/openvpn-gui-res-en.rc +++ b/openvpn-gui-res-en.rc @@ -114,7 +114,7 @@ BEGIN GROUPBOX " ", 201, 6, 46, 235, 52 AUTORADIOBUTTON "Use OpenVPN Config-file Settings", ID_RB_PROXY_OPENVPN, \ 13, 16, 200, 10, WS_GROUP | WS_TABSTOP - AUTORADIOBUTTON "Use Internet Explorer Settings", \ + AUTORADIOBUTTON "Use System Proxy Settings", \ ID_RB_PROXY_MSIE, 13, 31, 200, 10 AUTORADIOBUTTON "Manual Configuration", ID_RB_PROXY_MANUAL, 13, 46, 79, 10 AUTORADIOBUTTON "HTTP Proxy", ID_RB_PROXY_HTTP, 20, 62, 90, 10, WS_GROUP | WS_TABSTOP diff --git a/openvpn-gui-res-fi.rc b/openvpn-gui-res-fi.rc index a245c32..f758d22 100644 --- a/openvpn-gui-res-fi.rc +++ b/openvpn-gui-res-fi.rc @@ -115,7 +115,7 @@ BEGIN GROUPBOX " ", 201, 6, 46, 235, 52 AUTORADIOBUTTON "Käytä asetustiedoston asetuksia", ID_RB_PROXY_OPENVPN, \ 13, 16, 200, 10, WS_GROUP | WS_TABSTOP - AUTORADIOBUTTON "Käytä Internet Explorerin asetuksia", \ + AUTORADIOBUTTON "Käytä järjestelmän välipalvelinasetuksia", \ ID_RB_PROXY_MSIE, 13, 31, 200, 10 AUTORADIOBUTTON "Määritä asetukset itse", ID_RB_PROXY_MANUAL, 13, 46, 84, 10 AUTORADIOBUTTON "HTTP-välipalvelin", ID_RB_PROXY_HTTP, 20, 62, 90, 10, WS_GROUP | WS_TABSTOP diff --git a/openvpn-gui-res-nl.rc b/openvpn-gui-res-nl.rc index 8021e0d..d77dbce 100644 --- a/openvpn-gui-res-nl.rc +++ b/openvpn-gui-res-nl.rc @@ -112,7 +112,7 @@ BEGIN GROUPBOX " ", 201, 6, 46, 235, 52 AUTORADIOBUTTON "Gebruik OpenVPN instellingen", ID_RB_PROXY_OPENVPN, \ 13, 16, 200, 10, WS_GROUP | WS_TABSTOP - AUTORADIOBUTTON "Gebruik Internet Explorer Instellingen", \ + AUTORADIOBUTTON "Gebruik Proxy Systeem Instellingen", \ ID_RB_PROXY_MSIE, 13, 31, 200, 10 AUTORADIOBUTTON "Handmatige Configuratie", ID_RB_PROXY_MANUAL, 13, 46, 90, 10 AUTORADIOBUTTON "HTTP Proxy", ID_RB_PROXY_HTTP, 20, 62, 90, 10, WS_GROUP | WS_TABSTOP diff --git a/openvpn-gui-res-pl.rc b/openvpn-gui-res-pl.rc old mode 100755 new mode 100644 diff --git a/options.h b/options.h index 6e7b4bf..82bb847 100644 --- a/options.h +++ b/options.h @@ -87,7 +87,7 @@ typedef enum { typedef enum { config, - browser, + system, manual } proxy_source_t; diff --git a/proxy.c b/proxy.c index 1ad67dc..076f276 100644 --- a/proxy.c +++ b/proxy.c @@ -201,7 +201,7 @@ LoadProxySettings(HWND hwndDlg) { SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_OPENVPN), BM_CLICK, 0, 0); } - else if (o.proxy_source == browser) + else if (o.proxy_source == system) { SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MSIE), BM_CLICK, 0, 0); } @@ -228,7 +228,7 @@ SaveProxySettings(HWND hwndDlg) } else if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED) { - o.proxy_source = browser; + o.proxy_source = system; proxy_source_string[0] = _T('1'); } else if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED) @@ -307,7 +307,7 @@ GetProxyRegistrySettings() } else if (proxy_source_string[0] == _T('1')) { - o.proxy_source = browser; + o.proxy_source = system; } else if (proxy_source_string[0] == _T('2')) { @@ -378,77 +378,6 @@ ProxyAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) } -/* - * GetIeHttpProxy() fetches the current IE proxy settings for HTTP. - * Coded by Ewan Bhamrah Harley , but refactored. - * - * If result string does not contain an '=' sign then there is a - * single proxy for all protocols. If multiple proxies are defined - * they are space seperated and have the form protocol=host[:port] - */ -static BOOL -GetIeHttpProxy(TCHAR *host, size_t *hostlen, TCHAR *port, size_t *portlen) -{ - INTERNET_PROXY_INFO pinfo; - DWORD psize = sizeof(pinfo); - const TCHAR *start, *colon, *space, *end; - const size_t _hostlen = *hostlen; - const size_t _portlen = *portlen; - - *hostlen = 0; - *portlen = 0; - - if (!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, (LPVOID) &pinfo, &psize)) - { - ShowLocalizedMsg(IDS_ERR_GET_MSIE_PROXY); - return FALSE; - } - - /* Check if a proxy is used */ - if (pinfo.dwAccessType != INTERNET_OPEN_TYPE_PROXY) - return TRUE; - - /* Check if a HTTP proxy is defined */ - start = _tcsstr(pinfo.lpszProxy, _T("http=")); - if (start == NULL && _tcschr(pinfo.lpszProxy, _T('='))) - return TRUE; - - /* Get the pointers needed for string extraction */ - start = (start ? start + 5 : pinfo.lpszProxy); - colon = _tcschr(start, _T(':')); - space = _tcschr(start, _T(' ')); - - /* Extract hostname */ - end = (colon ? colon : space); - if (end) - *hostlen = end - start; - else - *hostlen = _tcslen(start); - - if (_hostlen < *hostlen) - return FALSE; - - _tcsncpy(host, start, *hostlen); - - if (!colon) - return TRUE; - - start = colon + 1; - end = space; - if (end) - *portlen = end - start; - else - *portlen = _tcslen(start); - - if (_portlen < *portlen) - return FALSE; - - _tcsncpy(port, start, *portlen); - - return TRUE; -} - - /* * Construct the proxy options to append to the cmd-line. */ @@ -467,18 +396,8 @@ void ConstructProxyCmdLine(TCHAR *proxy_string, unsigned int size) o.proxy_socks_address, o.proxy_socks_port); } } - else if (o.proxy_source == browser) + else if (o.proxy_source == system) { - TCHAR host[64]; - TCHAR port[6]; - size_t hostlen = _tsizeof(host); - - size_t portlen = _tsizeof(port); - - if (GetIeHttpProxy(host, &hostlen, port, &portlen) && hostlen != 0) - { - __sntprintf_0(proxy_string, size, _T(" --http-proxy %s %s auto"), - host, (portlen ? port : _T("8080"))); - } + __sntprintf_0(proxy_string, size, _T(" --auto-proxy")); } }