From 7025c3655332ee5bf0e73814186d3968224eb134 Mon Sep 17 00:00:00 2001 From: Yihong Wu Date: Fri, 6 Jan 2023 22:22:14 +0900 Subject: [PATCH] Cedar/SM: Provide limited support for custom VPN Azure service --- src/Cedar/SM.c | 80 ++++++++++++++++++++++-------- src/Cedar/SMInner.h | 1 + src/PenCore/PenCore.rc | 1 + src/PenCore/resource.h | 1 + src/bin/hamcore/strtable_cn.stb | 1 + src/bin/hamcore/strtable_en.stb | 1 + src/bin/hamcore/strtable_ja.stb | 1 + src/bin/hamcore/strtable_ko.stb | 1 + src/bin/hamcore/strtable_pt_br.stb | 1 + src/bin/hamcore/strtable_ru.stb | 1 + src/bin/hamcore/strtable_tw.stb | 1 + 11 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/Cedar/SM.c b/src/Cedar/SM.c index 5bf88aa2..7901ba6f 100644 --- a/src/Cedar/SM.c +++ b/src/Cedar/SM.c @@ -260,6 +260,8 @@ void SmAzureSetStatus(HWND hWnd, SM_AZURE *a) st.IsEnabled = IsChecked(hWnd, R_ENABLE); + st.UseCustom = a->UseCustom; + if (CALL(hWnd, ScSetAzureStatus(a->s->Rpc, &st)) == false) { EndDialog(hWnd, 0); @@ -342,7 +344,9 @@ void SmAzureDlgRefresh(HWND hWnd, SM_AZURE *a) return; } - if (CALL(hWnd, ScGetDDnsClientStatus(a->s->Rpc, &ddns)) == false) + a->UseCustom = st.UseCustom; + + if (st.UseCustom == false && CALL(hWnd, ScGetDDnsClientStatus(a->s->Rpc, &ddns)) == false) { EndDialog(hWnd, 0); return; @@ -360,21 +364,38 @@ void SmAzureDlgRefresh(HWND hWnd, SM_AZURE *a) } SetShow(hWnd, S_HOSTNAME_BORDER, st.IsEnabled); - SetShow(hWnd, S_HOSTNAME_INFO, st.IsEnabled); + SetShow(hWnd, S_HOSTNAME_INFO, st.IsEnabled && st.UseCustom == false); + SetShow(hWnd, S_HOSTNAME_CUSTOM, st.IsEnabled && st.UseCustom); SetShow(hWnd, B_CHANGE, st.IsEnabled); + SetEnable(hWnd, B_CHANGE, st.IsEnabled && st.UseCustom == false); - if (st.IsEnabled == false || IsEmptyStr(ddns.CurrentHostName)) + if (st.IsEnabled) { - Hide(hWnd, E_HOST); + if (st.UseCustom && IsEmptyStr(st.CurrentHostname) == false) + { + StrCpy(tmp, sizeof(tmp), st.CurrentHostname); + + SetTextA(hWnd, E_HOST, tmp); + + Show(hWnd, E_HOST); + } + else if (st.UseCustom == false && IsEmptyStr(ddns.CurrentHostName) == false) + { + StrCpy(tmp, sizeof(tmp), ddns.CurrentHostName); + StrCat(tmp, sizeof(tmp), AZURE_DOMAIN_SUFFIX); + + SetTextA(hWnd, E_HOST, tmp); + + Show(hWnd, E_HOST); + } + else + { + Hide(hWnd, E_HOST); + } } else { - StrCpy(tmp, sizeof(tmp), ddns.CurrentHostName); - StrCat(tmp, sizeof(tmp), AZURE_DOMAIN_SUFFIX); - - SetTextA(hWnd, E_HOST, tmp); - - Show(hWnd, E_HOST); + Hide(hWnd, E_HOST); } } @@ -18309,11 +18330,11 @@ void SmServerDlgRefresh(HWND hWnd, SM_SERVER *p) { UniToStr3(s9, sizeof(s9), e->Traffic.Recv.BroadcastBytes + e->Traffic.Recv.UnicastBytes + - e->Traffic.Send.BroadcastBytes + e->Traffic.Send.UnicastBytes); +e->Traffic.Send.BroadcastBytes + e->Traffic.Send.UnicastBytes); - UniToStr3(s10, sizeof(s10), - e->Traffic.Recv.BroadcastCount + e->Traffic.Recv.UnicastCount + - e->Traffic.Send.BroadcastCount + e->Traffic.Send.UnicastCount); +UniToStr3(s10, sizeof(s10), + e->Traffic.Recv.BroadcastCount + e->Traffic.Recv.UnicastCount + + e->Traffic.Send.BroadcastCount + e->Traffic.Send.UnicastCount); } LvInsertAdd(b, @@ -18334,7 +18355,7 @@ void SmServerDlgRefresh(HWND hWnd, SM_SERVER *p) if (CALL(hWnd, ScEnumListener(p->Rpc, &t2))) { LVB *b = LvInsertStart(); - for (i = 0;i < t2.NumPort;i++) + for (i = 0; i < t2.NumPort; i++) { wchar_t tmp[MAX_SIZE]; wchar_t *status; @@ -18403,17 +18424,34 @@ void SmServerDlgRefresh(HWND hWnd, SM_SERVER *p) // VPN Azure client state acquisition Zero(&sta, sizeof(sta)); - if (ScGetAzureStatus(p->Rpc, &sta) == ERR_NO_ERROR && sta.IsEnabled && IsEmptyStr(st.CurrentFqdn) == false) + if (ScGetAzureStatus(p->Rpc, &sta) == ERR_NO_ERROR && sta.IsEnabled) { char tmp[MAX_SIZE]; - StrCpy(tmp, sizeof(tmp), st.CurrentHostName); - StrCat(tmp, sizeof(tmp), AZURE_DOMAIN_SUFFIX); + if (sta.UseCustom && IsEmptyStr(sta.CurrentHostname) == false) + { + StrCpy(tmp, sizeof(tmp), sta.CurrentHostname); - SetTextA(hWnd, E_AZURE_HOST, tmp); + SetTextA(hWnd, E_AZURE_HOST, tmp); - Show(hWnd, S_AZURE); - Show(hWnd, E_AZURE_HOST); + Show(hWnd, S_AZURE); + Show(hWnd, E_AZURE_HOST); + } + else if (sta.UseCustom == false && IsEmptyStr(st.CurrentFqdn) == false) + { + StrCpy(tmp, sizeof(tmp), st.CurrentHostName); + StrCat(tmp, sizeof(tmp), AZURE_DOMAIN_SUFFIX); + + SetTextA(hWnd, E_AZURE_HOST, tmp); + + Show(hWnd, S_AZURE); + Show(hWnd, E_AZURE_HOST); + } + else + { + Hide(hWnd, S_AZURE); + Hide(hWnd, E_AZURE_HOST); + } } else { diff --git a/src/Cedar/SMInner.h b/src/Cedar/SMInner.h index 2a9158ec..e00afe99 100644 --- a/src/Cedar/SMInner.h +++ b/src/Cedar/SMInner.h @@ -375,6 +375,7 @@ typedef struct SM_AZURE { SM_SERVER *s; bool OnSetup; + bool UseCustom; } SM_AZURE; diff --git a/src/PenCore/PenCore.rc b/src/PenCore/PenCore.rc index 3d356d3c..6009fd11 100644 --- a/src/PenCore/PenCore.rc +++ b/src/PenCore/PenCore.rc @@ -4498,6 +4498,7 @@ BEGIN CONTROL "@R_DISABLE",R_DISABLE,"Button",BS_AUTORADIOBUTTON,13,297,101,12 GROUPBOX "@S_HOSTNAME_BORDER",S_HOSTNAME_BORDER,123,264,204,48 LTEXT "@S_HOSTNAME_INFO",S_HOSTNAME_INFO,129,275,191,19 + LTEXT "@S_HOSTNAME_CUSTOM",S_HOSTNAME_CUSTOM,129,275,191,19 EDITTEXT E_HOST,129,295,118,13,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER PUSHBUTTON "@B_CHANGE",B_CHANGE,252,293,67,15 PUSHBUTTON "@B_WEB",B_WEB,332,261,72,30,BS_MULTILINE diff --git a/src/PenCore/resource.h b/src/PenCore/resource.h index 384d3ff9..a1be1430 100644 --- a/src/PenCore/resource.h +++ b/src/PenCore/resource.h @@ -1030,6 +1030,7 @@ #define B_NEW 1521 #define R_TRUST_DEFAULT 1521 #define B_CLEAR 1522 +#define S_HOSTNAME_CUSTOM 1523 #define B_ONLINE 1655 #define D_NM_CONNECT 1998 #define D_NM_MAIN 1999 diff --git a/src/bin/hamcore/strtable_cn.stb b/src/bin/hamcore/strtable_cn.stb index 35aeae02..3633fe7f 100644 --- a/src/bin/hamcore/strtable_cn.stb +++ b/src/bin/hamcore/strtable_cn.stb @@ -4146,6 +4146,7 @@ R_ENABLE 启用 VPN Azure(&E) R_DISABLE 禁用 VPN Azure(&D) S_HOSTNAME_BORDER 当前 VPN Azure 主机名 S_HOSTNAME_INFO VPN Azure 主机名与动态 DNS 主机名相同,但改变的域名后缀为“vpnazure.net”。 +S_HOSTNAME_CUSTOM 自定义 VPN Azure 服务已启用。VPN Azure 主机名只能通过 vpncmd 命令更改。 B_CHANGE 变更主机名(&H) B_WEB 如何使用 VPN Azure\r\n(访问网络) IDCANCEL 确定(&O) diff --git a/src/bin/hamcore/strtable_en.stb b/src/bin/hamcore/strtable_en.stb index fc8f6a62..3d5e7a17 100644 --- a/src/bin/hamcore/strtable_en.stb +++ b/src/bin/hamcore/strtable_en.stb @@ -4134,6 +4134,7 @@ R_ENABLE &Enable VPN Azure R_DISABLE &Disable VPN Azure S_HOSTNAME_BORDER Current VPN Azure Hostname S_HOSTNAME_INFO The VPN Azure hostname is same to the Dynamic DNS hostname, but altering the domain suffix to "vpnazure.net". +S_HOSTNAME_CUSTOM Custom VPN Azure service is enabled. The VPN Azure hostname can only be changed from the vpncmd command. B_CHANGE Change &Hostname B_WEB How to Use VPN Azure\r\n(Visit the Web) IDCANCEL &OK diff --git a/src/bin/hamcore/strtable_ja.stb b/src/bin/hamcore/strtable_ja.stb index a285d7af..741228c5 100644 --- a/src/bin/hamcore/strtable_ja.stb +++ b/src/bin/hamcore/strtable_ja.stb @@ -4139,6 +4139,7 @@ R_ENABLE VPN Azure を有効にする(&E) R_DISABLE VPN Azure を無効にする(&D) S_HOSTNAME_BORDER 現在の VPN Azure ホスト名 S_HOSTNAME_INFO VPN Azure ホスト名はダイナミック DNS サービスのホスト名のドメイン部分を "vpnazure.net" に変更したものが使用されます。 +S_HOSTNAME_CUSTOM カスタム VPN Azure サービスが有効になっています。VPN Azure ホスト名は、vpncmd コマンドからのみ変更できます。 B_CHANGE ホスト名の変更(&H) B_WEB VPN Azure の使い方\r\n(Web サイトを表示) IDCANCEL &OK diff --git a/src/bin/hamcore/strtable_ko.stb b/src/bin/hamcore/strtable_ko.stb index 335f9701..311144f1 100644 --- a/src/bin/hamcore/strtable_ko.stb +++ b/src/bin/hamcore/strtable_ko.stb @@ -4117,6 +4117,7 @@ R_ENABLE VPN Azure를 사용 (&E) R_DISABLE VPN Azure를 비활성화 (&D) S_HOSTNAME_BORDER 현재 VPN Azure 호스트 이름 S_HOSTNAME_INFO VPN Azure 호스트 이름은 동적 DNS 서비스 호스트 이름의 도메인 부분을 "vpnazure.net"로 변경 한 것이 사용됩니다. +S_HOSTNAME_CUSTOM Custom VPN Azure service is enabled. The VPN Azure hostname can only be changed from the vpncmd command. B_CHANGE 호스트 이름 변경 (&H) B_WEB VPN Azure 사용 \r\n (Web 사이트보기) IDCANCEL & OK diff --git a/src/bin/hamcore/strtable_pt_br.stb b/src/bin/hamcore/strtable_pt_br.stb index c89ce1d6..d0e7ef89 100644 --- a/src/bin/hamcore/strtable_pt_br.stb +++ b/src/bin/hamcore/strtable_pt_br.stb @@ -3863,6 +3863,7 @@ R_ENABLE &Ativar VPN Azure R_DISABLE &Desativar VPN Azure S_HOSTNAME_BORDER Nome do host atual da VPN Azure S_HOSTNAME_INFO O nome do host da VPN do Azure é igual ao nome do host do DNS dinâmico, mas alterando o sufixo do domínio para "vpnazure.net". +S_HOSTNAME_CUSTOM Custom VPN Azure service is enabled. The VPN Azure hostname can only be changed from the vpncmd command. B_CHANGE Mudar &Hostname B_WEB Como usar o VPN Azure\r\n (Visite o site) IDCANCEL &OK diff --git a/src/bin/hamcore/strtable_ru.stb b/src/bin/hamcore/strtable_ru.stb index d02cdcbd..5b0bc7df 100644 --- a/src/bin/hamcore/strtable_ru.stb +++ b/src/bin/hamcore/strtable_ru.stb @@ -4133,6 +4133,7 @@ R_ENABLE &Enable VPN Azure R_DISABLE &Disable VPN Azure S_HOSTNAME_BORDER Current VPN Azure Hostname S_HOSTNAME_INFO The VPN Azure hostname is same to the Dynamic DNS hostname, but altering the domain suffix to "vpnazure.net". +S_HOSTNAME_CUSTOM Custom VPN Azure service is enabled. The VPN Azure hostname can only be changed from the vpncmd command. B_CHANGE Change &Hostname B_WEB How to Use VPN Azure\r\n(Visit the Web) IDCANCEL &OK diff --git a/src/bin/hamcore/strtable_tw.stb b/src/bin/hamcore/strtable_tw.stb index 2ec3fb49..9a7517a7 100644 --- a/src/bin/hamcore/strtable_tw.stb +++ b/src/bin/hamcore/strtable_tw.stb @@ -4146,6 +4146,7 @@ R_ENABLE 啟用 VPN Azure(&E) R_DISABLE 禁用 VPN Azure(&D) S_HOSTNAME_BORDER 當前 VPN Azure 主機名稱 S_HOSTNAME_INFO VPN Azure 主機名稱與動態 DNS 主機名稱相同,但改變的功能變數名稱尾碼為“vpnazure.net”。 +S_HOSTNAME_CUSTOM 自定義 VPN Azure 服務已啟用。VPN Azure 主機名稱只能通過 vpncmd 命令更改。 B_CHANGE 變更主機名稱(&H) B_WEB 如何使用 VPN Azure\r\n(訪問網路) IDCANCEL 確定(&O)