From 204f9f1fbc9210f70cb9f76c8c9d567454d1a5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:19:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9D=A2=E6=9D=BF=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=8F=90=E4=BE=9B=20docker=20?= =?UTF-8?q?=E4=BB=A3=E7=90=86=20(#6986)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/docker.go | 17 ++++ frontend/src/lang/modules/en.ts | 3 + frontend/src/lang/modules/tw.ts | 3 + frontend/src/lang/modules/zh.ts | 3 + frontend/src/utils/util.ts | 26 +++++ frontend/src/views/setting/panel/index.vue | 3 + .../src/views/setting/panel/proxy/index.vue | 99 ++++++++++++++++--- 7 files changed, 143 insertions(+), 11 deletions(-) diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 2ff3adb4a..b662bce81 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -198,6 +198,23 @@ func (u *DockerService) UpdateConf(req dto.SettingUpdate) error { daemonMap["exec-opts"] = []string{"native.cgroupdriver=systemd"} } } + case "http-proxy", "https-proxy": + delete(daemonMap, "proxies") + if len(req.Value) > 0 { + proxies := map[string]interface{}{ + req.Key: req.Value, + } + daemonMap["proxies"] = proxies + } + case "socks5-proxy": + delete(daemonMap, "proxies") + if len(req.Value) > 0 { + proxies := map[string]interface{}{ + "http-proxy": req.Value, + "https-proxy": req.Value, + } + daemonMap["proxies"] = proxies + } } if len(daemonMap) == 0 { _ = os.Remove(constant.DaemonJsonPath) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 5e12d4238..e87a2b145 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1392,11 +1392,14 @@ const message = { proxyHelper: 'After setting up the proxy server, it will be effective in the following scenarios:', proxyHelper1: 'Downloading and synchronizing installation packages from the app store (Professional)', proxyHelper2: 'System version upgrades and retrieving update information (Professional)', + proxyHelper4: 'Docker Daemon provides network access proxy (Professional)', proxyHelper3: 'Verification and synchronization of system licenses', proxyType: 'Proxy Type', proxyUrl: 'Proxy Address', proxyPort: 'Proxy Port', proxyPasswdKeep: 'Remember Password', + proxyDocker: 'Docker Proxy', + proxyDockerHelper: 'Docker Daemon provides network access proxy', systemIPWarning: 'The server address is not currently set. Please set it in the control panel first!', systemIPWarning1: 'The current server address is set to {0}, and quick redirection is not possible!', defaultNetwork: 'Network Card', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 5b646bed3..260eeb62d 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1314,11 +1314,14 @@ const message = { proxyHelper: '設置代理伺服器後,將在以下場景中生效:', proxyHelper1: '應用商店的安裝包下載和同步(專業版功能)', proxyHelper2: '系統版本升級及獲取更新說明(專業版功能)', + proxyHelper4: 'Docker Daemon 提供網絡訪問代理(專業版功能)', proxyHelper3: '系統許可證的驗證和同步', proxyType: '代理類型', proxyUrl: '代理地址', proxyPort: '代理端口', proxyPasswdKeep: '記住密碼', + proxyDocker: 'Docker 代理', + proxyDockerHelper: '為 Docker Daemon 提供網絡訪問代理', systemIPWarning: '當前未設置服務器地址,請先在面板設置中設置!', systemIPWarning1: '當前服務器地址設置為 {0},無法快速跳轉!', defaultNetwork: '默認網卡', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index dd0bbf18d..fa12e84e1 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1317,10 +1317,13 @@ const message = { proxyHelper1: '应用商店的安装包下载和同步(专业版功能)', proxyHelper2: '系统版本升级及获取更新说明(专业版功能)', proxyHelper3: '系统许可证的验证和同步', + proxyHelper4: 'Docker Daemon 提供网络访问代理(专业版功能)', proxyType: '代理类型', proxyUrl: '代理地址', proxyPort: '代理端口', proxyPasswdKeep: '记住密码', + proxyDocker: 'Docker 代理', + proxyDockerHelper: '为 Docker Daemon 提供网络访问代理', systemIPWarning: '当前未设置服务器地址,请先在面板设置中设置!', systemIPWarning1: '当前服务器地址设置为 {0},无法快速跳转!', defaultNetwork: '默认网卡', diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index 655e36027..a7b070c86 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -589,3 +589,29 @@ export const getFileType = (extension: string) => { }); return type; }; + +export const escapeProxyURL = (url: string): string => { + const encodeMap: { [key: string]: string } = { + ':': '%%3A', + '/': '%%2F', + '?': '%%3F', + '#': '%%23', + '[': '%%5B', + ']': '%%5D', + '@': '%%40', + '!': '%%21', + $: '%%24', + '&': '%%26', + "'": '%%27', + '(': '%%28', + ')': '%%29', + '*': '%%2A', + '+': '%%2B', + ',': '%%2C', + ';': '%%3B', + '=': '%%3D', + '%': '%%25', + }; + + return url.replace(/[\/:?#[\]@!$&'()*+,;=%~]/g, (match) => encodeMap[match] || match); +}; diff --git a/frontend/src/views/setting/panel/index.vue b/frontend/src/views/setting/panel/index.vue index c77cd8baf..748c2a38e 100644 --- a/frontend/src/views/setting/panel/index.vue +++ b/frontend/src/views/setting/panel/index.vue @@ -239,6 +239,7 @@ const form = reactive({ proxyUser: '', proxyPasswd: '', proxyPasswdKeep: '', + proxyDocker: '', proHideMenus: ref(i18n.t('setting.unSetting')), hideMenuList: '', @@ -302,6 +303,7 @@ const search = async () => { form.theme = xpackRes.data.theme || globalStore.themeConfig.theme; form.themeColor = JSON.parse(xpackRes.data.themeColor); globalStore.themeConfig.themeColor = xpackRes.data.themeColor; + form.proxyDocker = xpackRes.data.proxyDocker; } } else { form.theme = res.data.theme; @@ -355,6 +357,7 @@ const onChangeProxy = () => { user: form.proxyUser, passwd: form.proxyPasswd, passwdKeep: form.proxyPasswdKeep, + proxyDocker: form.proxyDocker, }); }; const onChangeNetwork = () => { diff --git a/frontend/src/views/setting/panel/proxy/index.vue b/frontend/src/views/setting/panel/proxy/index.vue index d379a07c2..ffc46069c 100644 --- a/frontend/src/views/setting/panel/proxy/index.vue +++ b/frontend/src/views/setting/panel/proxy/index.vue @@ -19,6 +19,7 @@