diff --git a/backend/app/dto/docker.go b/backend/app/dto/docker.go index 42bddcc15..4ee193d78 100644 --- a/backend/app/dto/docker.go +++ b/backend/app/dto/docker.go @@ -10,6 +10,7 @@ type DaemonJsonConf struct { Mirrors []string `json:"registryMirrors"` Registries []string `json:"insecureRegistries"` LiveRestore bool `json:"liveRestore"` + IPTables bool `json:"iptables"` CgroupDriver string `json:"cgroupDriver"` } diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index 069efcd07..e1cd5113b 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -34,6 +34,7 @@ type daemonJsonItem struct { Mirrors []string `json:"registry-mirrors"` Registries []string `json:"insecure-registries"` LiveRestore bool `json:"live-restore"` + IPTables bool `json:"iptables"` ExecOpts []string `json:"exec-opts"` } @@ -63,23 +64,26 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { } } if _, err := os.Stat(constant.DaemonJsonPath); err != nil { - return &dto.DaemonJsonConf{Status: status, Version: version} + return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} } file, err := os.ReadFile(constant.DaemonJsonPath) if err != nil { - return &dto.DaemonJsonConf{Status: status, Version: version} + return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} } var conf daemonJsonItem deamonMap := make(map[string]interface{}) if err := json.Unmarshal(file, &deamonMap); err != nil { - return &dto.DaemonJsonConf{Status: status, Version: version} + return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} } arr, err := json.Marshal(deamonMap) if err != nil { - return &dto.DaemonJsonConf{Status: status, Version: version} + return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} } if err := json.Unmarshal(arr, &conf); err != nil { - return &dto.DaemonJsonConf{Status: status, Version: version} + return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} + } + if _, ok := deamonMap["iptables"]; !ok { + conf.IPTables = true } driver := "cgroupfs" for _, opt := range conf.ExecOpts { @@ -93,6 +97,7 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { Version: version, Mirrors: conf.Mirrors, Registries: conf.Registries, + IPTables: conf.IPTables, LiveRestore: conf.LiveRestore, CgroupDriver: driver, } @@ -130,6 +135,11 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { } else { deamonMap["live-restore"] = req.LiveRestore } + if req.IPTables { + delete(deamonMap, "iptables") + } else { + deamonMap["live-restore"] = false + } if opts, ok := deamonMap["exec-opts"]; ok { if optsValue, isArray := opts.([]interface{}); isArray { for i := 0; i < len(optsValue); i++ { @@ -162,6 +172,12 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { } func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error { + if _, err := os.Stat(constant.DaemonJsonPath); err != nil && os.IsNotExist(err) { + if err = os.MkdirAll(path.Dir(constant.DaemonJsonPath), os.ModePerm); err != nil { + return err + } + _, _ = os.Create(constant.DaemonJsonPath) + } file, err := os.OpenFile(constant.DaemonJsonPath, os.O_WRONLY|os.O_TRUNC, 0640) if err != nil { return err diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index c30107d7e..66b4acc1a 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -252,6 +252,7 @@ export namespace Container { registryMirrors: Array; insecureRegistries: Array; liveRestore: boolean; + iptables: boolean; cgroupDriver: string; } } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 654015c8e..c0a02efa2 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1222,10 +1222,13 @@ const message = { cookieBlockList: 'Cookie Blacklist', firewall: 'Firewall', + dockerHelper: + 'Linux firewall {0} cannot disable Docker port mapping, you need to disable iptables in Docker configuration.', + quickJump: 'Quick jump', used: 'Used', unUsed: 'Unused', firewallHelper: '{0} System firewall', - firewallNotStart: 'The firewall service is not enabled at present, please enable it first!', + firewallNotStart: 'The system firewall is not enabled at present, please enable it first!', stopFirewallHelper: 'After the system firewall is disabled, the server loses security protection. Do you want to continue?', startFirewallHelper: diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index b99ba1429..90a935714 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1218,10 +1218,12 @@ const message = { cookieBlockList: 'Cookie 黑名单', firewall: '防火墙', + dockerHelper: 'Linux 防火墙 {0} 无法禁用 Docker 端口映射,需要在 Docker 配置中禁用 iptables', + quickJump: '快速跳转', used: '已使用', unUsed: '未使用', firewallHelper: '{0}系统防火墙', - firewallNotStart: '当前未开启防火墙服务,请先开启!', + firewallNotStart: '当前未开启系统防火墙,请先开启!', stopFirewallHelper: '系统防火墙关闭后,服务器将失去安全防护,是否继续?', startFirewallHelper: '系统防火墙开启后,可以更好的防护服务器安全,是否继续?', noPing: '禁 ping', diff --git a/frontend/src/views/container/setting/index.vue b/frontend/src/views/container/setting/index.vue index 7a9485f4b..cc539dfa3 100644 --- a/frontend/src/views/container/setting/index.vue +++ b/frontend/src/views/container/setting/index.vue @@ -62,6 +62,9 @@ v-model="form.registries" /> + + + {{ $t('container.liveHelper') }} @@ -153,6 +156,7 @@ const form = reactive({ mirrors: '', registries: '', liveRestore: false, + iptables: true, cgroupDriver: '', }); @@ -255,6 +259,7 @@ const onSubmitSave = async () => { return el !== null && el !== '' && el !== undefined; }), liveRestore: form.liveRestore, + iptables: form.iptables, cgroupDriver: form.cgroupDriver, }; loading.value = true; @@ -293,6 +298,7 @@ const search = async () => { form.version = res.data.version; form.cgroupDriver = res.data.cgroupDriver; form.liveRestore = res.data.liveRestore; + form.iptables = res.data.iptables; form.mirrors = res.data.registryMirrors ? res.data.registryMirrors.join('\n') : ''; form.registries = res.data.insecureRegistries ? res.data.insecureRegistries.join('\n') : ''; }; diff --git a/frontend/src/views/host/firewall/port/index.vue b/frontend/src/views/host/firewall/port/index.vue index 21919b7ca..b5bae2a47 100644 --- a/frontend/src/views/host/firewall/port/index.vue +++ b/frontend/src/views/host/firewall/port/index.vue @@ -8,6 +8,7 @@ v-model:loading="loading" v-model:mask-show="maskShow" v-model:status="fireStatus" + v-model:name="fireName" /> @@ -15,6 +16,23 @@ +