From 8658473c812a718450cf8e0be0239b7f142f31b0 Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Tue, 7 Jun 2022 12:35:41 +0800 Subject: [PATCH] listen Privoxy host 0.0.0.0 fix issue https://github.com/ShadowsocksR-Live/shadowsocksr-native/issues/229 --- src/run_ssr_client.c | 13 +++++++++---- src/run_ssr_client.h | 4 ++-- src/ssrWin/main.c | 13 +++++++++++-- src/ssrWin/resource.h | Bin 5322 -> 5414 bytes src/ssrWin/ssrwin.rc | Bin 17608 -> 17856 bytes 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/run_ssr_client.c b/src/run_ssr_client.c index b929eab..572e62a 100644 --- a/src/run_ssr_client.c +++ b/src/run_ssr_client.c @@ -9,9 +9,10 @@ #include "run_ssr_client.h" #include "proxy_settings.h" #include "server_connectivity.h" +#include "utf8_to_wchar.h" #define PRIVOXY_CONFIG_CONTENT_FMT \ - "listen-address 127.0.0.1:%d\r\n" \ + "listen-address %s:%d\r\n" \ "forward-socks5 / 127.0.0.1:%d .\r\n" static DWORD WINAPI SsrClientThread(LPVOID lpParam); @@ -26,6 +27,7 @@ struct ssr_client_ctx { struct ssr_client_state* state; int delay_ms; uint16_t real_listen_port; + char privoxy_listen_host[MAX_PATH]; uint16_t privoxy_listen_port; }; @@ -35,7 +37,7 @@ const char* ssr_client_error_string(void) { return error_info; } -struct ssr_client_ctx* ssr_client_begin_run(struct server_config* config, const char* ssr_listen_host, int ssr_listen_port, int proxy_listen_port, int delay_quit_ms, int change_inet_opts) +struct ssr_client_ctx* ssr_client_begin_run(struct server_config* config, const char* ssr_listen_host, int ssr_listen_port, const char* proxy_listen_host, int proxy_listen_port, int delay_quit_ms, int change_inet_opts) { struct ssr_client_ctx* ctx = NULL; DWORD threadId = 0; @@ -74,6 +76,7 @@ struct ssr_client_ctx* ssr_client_begin_run(struct server_config* config, const ctx->config->listen_port = (unsigned short)ssr_listen_port; string_safe_assign(&ctx->config->listen_host, ssr_listen_host); + strcpy(ctx->privoxy_listen_host, proxy_listen_host); ctx->privoxy_listen_port = (uint16_t)proxy_listen_port; ctx->delay_ms = (delay_quit_ms < SSR_DELAY_QUIT_MIN) ? SSR_DELAY_QUIT_MIN : delay_quit_ms; @@ -86,7 +89,9 @@ struct ssr_client_ctx* ssr_client_begin_run(struct server_config* config, const if (error_code == 0) { ctx->hPrivoxySvr = CreateThread(NULL, 0, PrivoxyThread, ctx, 0, &threadId); if (change_inet_opts != 0) { - enable_system_proxy(PRIVOXY_LISTEN_ADDR, ctx->privoxy_listen_port); + wchar_t*p = utf8_to_wchar_string(ctx->privoxy_listen_host, &malloc); + enable_system_proxy(p, ctx->privoxy_listen_port); + free(p); } else { disable_system_proxy(); } @@ -163,7 +168,7 @@ static DWORD WINAPI PrivoxyThread(LPVOID lpParam) { } assert(ctx->real_listen_port != 0); - sprintf(content, PRIVOXY_CONFIG_CONTENT_FMT, ctx->privoxy_listen_port, ctx->real_listen_port); + sprintf(content, PRIVOXY_CONFIG_CONTENT_FMT, ctx->privoxy_listen_host, ctx->privoxy_listen_port, ctx->real_listen_port); hFile = CreateFileA(privoxy_config_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { diff --git a/src/run_ssr_client.h b/src/run_ssr_client.h index 0ca3fa4..121ee12 100644 --- a/src/run_ssr_client.h +++ b/src/run_ssr_client.h @@ -9,13 +9,13 @@ extern "C" { #define SSR_DELAY_QUIT_MIN 500 -#define PRIVOXY_LISTEN_ADDR L"127.0.0.1" +#define PRIVOXY_LISTEN_ADDR "127.0.0.1" #define PRIVOXY_LISTEN_PORT 8118 struct ssr_client_ctx; struct server_config; -struct ssr_client_ctx* ssr_client_begin_run(struct server_config* config, const char* ssr_listen_host, int ssr_listen_port, int proxy_listen_port, int delay_quit_ms, int change_inet_opts); +struct ssr_client_ctx* ssr_client_begin_run(struct server_config* config, const char* ssr_listen_host, int ssr_listen_port, const char* proxy_listen_host, int proxy_listen_port, int delay_quit_ms, int change_inet_opts); void ssr_client_terminate(struct ssr_client_ctx* ctx); const char* ssr_client_error_string(void); diff --git a/src/ssrWin/main.c b/src/ssrWin/main.c index c8047f6..d488147 100644 --- a/src/ssrWin/main.c +++ b/src/ssrWin/main.c @@ -37,6 +37,7 @@ struct main_wnd_data { BOOL auto_connect; char ssr_listen_host[MAX_PATH]; int ssr_listen_port; + char privoxy_listen_host[MAX_PATH]; int privoxy_listen_port; int delay_quit_ms; int change_inet_opts; @@ -347,7 +348,7 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar else { assert(wnd_data->client_ctx == NULL); config = retrieve_config_from_list_view(wnd_data->hListView, wnd_data->cur_selected); - wnd_data->client_ctx = ssr_client_begin_run(config, wnd_data->ssr_listen_host, wnd_data->ssr_listen_port, wnd_data->privoxy_listen_port, wnd_data->delay_quit_ms, wnd_data->change_inet_opts); + wnd_data->client_ctx = ssr_client_begin_run(config, wnd_data->ssr_listen_host, wnd_data->ssr_listen_port, wnd_data->privoxy_listen_host, wnd_data->privoxy_listen_port, wnd_data->delay_quit_ms, wnd_data->change_inet_opts); if (wnd_data->client_ctx == NULL) { const char*info = ssr_client_error_string(); put_string_to_rich_edit_control(wnd_data->hWndLogBox, TRUE, info, 2); @@ -444,6 +445,7 @@ static void on_wm_create(HWND hWnd, LPCREATESTRUCTW pcs) wnd_data->auto_run = FALSE; lstrcpyA(wnd_data->ssr_listen_host, "127.0.0.1"); wnd_data->ssr_listen_port = 0; + lstrcpyA(wnd_data->privoxy_listen_host, PRIVOXY_LISTEN_ADDR); wnd_data->privoxy_listen_port = PRIVOXY_LISTEN_PORT; wnd_data->delay_quit_ms = SSR_DELAY_QUIT_MIN; wnd_data->change_inet_opts = TRUE; @@ -482,6 +484,9 @@ static void on_wm_create(HWND hWnd, LPCREATESTRUCTW pcs) sizeBuff = sizeof(wnd_data->ssr_listen_port); lRet = RegQueryValueExW(hKey, L"ssr_listen_port", 0, &dwtype, (BYTE*)&wnd_data->ssr_listen_port, &sizeBuff); + sizeBuff = sizeof(wnd_data->privoxy_listen_host); + lRet = RegQueryValueExW(hKey, L"privoxy_listen_host", 0, &dwtype, (BYTE*)&wnd_data->privoxy_listen_host[0], &sizeBuff); + sizeBuff = sizeof(wnd_data->privoxy_listen_port); lRet = RegQueryValueExW(hKey, L"privoxy_listen_port", 0, &dwtype, (BYTE*)&wnd_data->privoxy_listen_port, &sizeBuff); @@ -542,7 +547,7 @@ static void on_wm_create(HWND hWnd, LPCREATESTRUCTW pcs) assert(wnd_data->client_ctx == NULL); config = retrieve_config_from_list_view(wnd_data->hListView, index); assert(config); - wnd_data->client_ctx = ssr_client_begin_run(config, wnd_data->ssr_listen_host, wnd_data->ssr_listen_port, wnd_data->privoxy_listen_port, wnd_data->delay_quit_ms, wnd_data->change_inet_opts); + wnd_data->client_ctx = ssr_client_begin_run(config, wnd_data->ssr_listen_host, wnd_data->ssr_listen_port, wnd_data->privoxy_listen_host, wnd_data->privoxy_listen_port, wnd_data->delay_quit_ms, wnd_data->change_inet_opts); if (wnd_data->client_ctx == NULL) { const char*info = ssr_client_error_string(); put_string_to_rich_edit_control(wnd_data->hWndLogBox, TRUE, info, 2); @@ -576,6 +581,7 @@ static void on_wm_destroy(HWND hWnd) { RegSetValueExW(hKey, L"auto_connect", 0, REG_BINARY, (BYTE*)&wnd_data->auto_connect, sizeof(wnd_data->auto_connect)); RegSetValueExW(hKey, L"ssr_listen_host", 0, REG_BINARY, (BYTE*)&wnd_data->ssr_listen_host[0], sizeof(wnd_data->ssr_listen_host)); RegSetValueExW(hKey, L"ssr_listen_port", 0, REG_BINARY, (BYTE*)&wnd_data->ssr_listen_port, sizeof(wnd_data->ssr_listen_port)); + RegSetValueExW(hKey, L"privoxy_listen_host", 0, REG_BINARY, (BYTE*)&wnd_data->privoxy_listen_host[0], sizeof(wnd_data->privoxy_listen_host)); RegSetValueExW(hKey, L"privoxy_listen_port", 0, REG_BINARY, (BYTE*)&wnd_data->privoxy_listen_port, sizeof(wnd_data->privoxy_listen_port)); RegSetValueExW(hKey, L"delay_quit_ms", 0, REG_BINARY, (BYTE*)&wnd_data->delay_quit_ms, sizeof(wnd_data->delay_quit_ms)); RegSetValueExW(hKey, L"change_inet_opts", 0, REG_BINARY, (BYTE*)&wnd_data->change_inet_opts, sizeof(wnd_data->change_inet_opts)); @@ -1323,6 +1329,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, CheckDlgButton(hDlg, IDC_CHK_AUTO_CONN, wnd_data->auto_connect); SetDlgItemTextA(hDlg, IDC_EDT_SSR_HOST, wnd_data->ssr_listen_host); SetDlgItemInt(hDlg, IDC_EDT_SSR_PORT, wnd_data->ssr_listen_port, FALSE); + SetDlgItemTextA(hDlg, IDC_EDT_PRIVOXY_HOST, wnd_data->privoxy_listen_host); SetDlgItemInt(hDlg, IDC_EDT_PRIVOXY_PORT, wnd_data->privoxy_listen_port, FALSE); SetDlgItemInt(hDlg, IDC_EDT_DELAY_MS, wnd_data->delay_quit_ms, FALSE); CheckDlgButton(hDlg, IDC_CHK_CHANGE_INET_OPTS, wnd_data->change_inet_opts); @@ -1336,6 +1343,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, CheckDlgButton(hDlg, IDC_CHK_AUTO_CONN, FALSE); SetDlgItemTextW(hDlg, IDC_EDT_SSR_HOST, L"127.0.0.1"); SetDlgItemTextW(hDlg, IDC_EDT_SSR_PORT, L"0"); + SetDlgItemTextA(hDlg, IDC_EDT_PRIVOXY_HOST, PRIVOXY_LISTEN_ADDR); SetDlgItemInt(hDlg, IDC_EDT_PRIVOXY_PORT, PRIVOXY_LISTEN_PORT, FALSE); SetDlgItemInt(hDlg, IDC_EDT_DELAY_MS, SSR_DELAY_QUIT_MIN, FALSE); CheckDlgButton(hDlg, IDC_CHK_CHANGE_INET_OPTS, TRUE); @@ -1346,6 +1354,7 @@ static INT_PTR CALLBACK OptionsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, wnd_data->auto_connect = IsDlgButtonChecked(hDlg, IDC_CHK_AUTO_CONN); GetDlgItemTextA(hDlg, IDC_EDT_SSR_HOST, wnd_data->ssr_listen_host, sizeof(wnd_data->ssr_listen_host)); wnd_data->ssr_listen_port = GetDlgItemInt(hDlg, IDC_EDT_SSR_PORT, NULL, FALSE); + GetDlgItemTextA(hDlg, IDC_EDT_PRIVOXY_HOST, wnd_data->privoxy_listen_host, sizeof(wnd_data->privoxy_listen_host)); wnd_data->privoxy_listen_port = GetDlgItemInt(hDlg, IDC_EDT_PRIVOXY_PORT, NULL, FALSE); wnd_data->delay_quit_ms = GetDlgItemInt(hDlg, IDC_EDT_DELAY_MS, NULL, FALSE); wnd_data->change_inet_opts = IsDlgButtonChecked(hDlg, IDC_CHK_CHANGE_INET_OPTS); diff --git a/src/ssrWin/resource.h b/src/ssrWin/resource.h index 91bf963e56c649b9b1ddeb8201b9d06189df7351..0356c4fc15492e02aa0aa520c12175b42749ffc1 100644 GIT binary patch delta 44 zcmV+{0Mq}ad|aF3csPccmMzZ diff --git a/src/ssrWin/ssrwin.rc b/src/ssrWin/ssrwin.rc index d4241a1446f8e322c32518349676c67d0aab367a..91e7ad7397a2113bd961b31f47262b2ea7ff47d6 100644 GIT binary patch delta 230 zcmX@n$#|ffaf6k{$9$3Z@NSZL1 zPj=MyoU9|J#2dg+#E{8Q#*oiY!B9EbRo$H3g24i)#%yvwQ11s#0bvgYe}-U&5TKX^ z(0mYSH2I-=B#Mm?JrElmfx4vNHUd?n+PJwzi;Z#eKNY3PUvyF?7x9ZsZZMLVd_ja| f@-j7_$t!flCbQ{iZC;}-$2j?$BH!jSx_`s~Cl5IA delta 176 zcmX@m&3K}daf6k{WFvKz$uVL|yygr#4CV|LK+=rCZ1O}==gAv11UM}iEWzSNlOL*U zPnHvRQ}$uVXGms9WXNGqU?^ZH0`e*tDuL`AhD?THh7yKUhP=s