From 1df4a870a02a787a160dc9a43b137b49beb73642 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:04:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Fail2ban=20=E5=90=8D=E7=A7=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20(#3071)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/fail2ban.go | 26 +++++++-------- backend/utils/toolbox/fail2ban.go | 18 +++++------ cmd/server/docs/docs.go | 32 +++++++++---------- cmd/server/docs/swagger.json | 28 ++++++++-------- cmd/server/docs/swagger.yaml | 28 ++++++++-------- frontend/src/lang/modules/en.ts | 8 ++--- frontend/src/lang/modules/tw.ts | 8 ++--- frontend/src/lang/modules/zh.ts | 8 ++--- frontend/src/routers/modules/toolbox.ts | 2 +- frontend/src/views/toolbox/fail2ban/index.vue | 10 +++--- frontend/src/views/toolbox/index.vue | 2 +- 11 files changed, 85 insertions(+), 85 deletions(-) diff --git a/backend/app/api/v1/fail2ban.go b/backend/app/api/v1/fail2ban.go index d4b4d0c21..5ffd2c3dc 100644 --- a/backend/app/api/v1/fail2ban.go +++ b/backend/app/api/v1/fail2ban.go @@ -9,9 +9,9 @@ import ( "github.com/gin-gonic/gin" ) -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Load fail2ban base info -// @Description 获取 Fail2Ban 基础信息 +// @Description 获取 Fail2ban 基础信息 // @Success 200 {object} dto.Fail2BanBaseInfo // @Security ApiKeyAuth // @Router /toolbox/fail2ban/base [get] @@ -25,9 +25,9 @@ func (b *BaseApi) LoadFail2BanBaseInfo(c *gin.Context) { helper.SuccessWithData(c, data) } -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Page fail2ban ip list -// @Description 获取 Fail2Ban ip +// @Description 获取 Fail2ban ip // @Accept json // @Param request body dto.Fail2BanSearch true "request" // @Success 200 {Array} string @@ -48,14 +48,14 @@ func (b *BaseApi) SearchFail2Ban(c *gin.Context) { helper.SuccessWithData(c, list) } -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Operate fail2ban -// @Description 修改 Fail2Ban 状态 +// @Description 修改 Fail2ban 状态 // @Accept json // @Param request body dto.Operate true "request" // @Security ApiKeyAuth // @Router /toolbox/fail2ban/operate [post] -// @x-panel-log {"bodyKeys":["operation"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"[operation] Fail2Ban","formatEN":"[operation] Fail2Ban"} +// @x-panel-log {"bodyKeys":["operation"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"[operation] Fail2ban","formatEN":"[operation] Fail2ban"} func (b *BaseApi) OperateFail2Ban(c *gin.Context) { var req dto.Operate if err := helper.CheckBindAndValidate(&req, c); err != nil { @@ -70,7 +70,7 @@ func (b *BaseApi) OperateFail2Ban(c *gin.Context) { helper.SuccessWithData(c, nil) } -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Operate sshd of fail2ban // @Description 配置 sshd // @Accept json @@ -91,15 +91,15 @@ func (b *BaseApi) OperateSSHD(c *gin.Context) { helper.SuccessWithData(c, nil) } -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Update fail2ban conf -// @Description 修改 Fail2Ban 配置 +// @Description 修改 Fail2ban 配置 // @Accept json // @Param request body dto.Fail2BanUpdate true "request" // @Success 200 // @Security ApiKeyAuth // @Router /toolbox/fail2ban/update [post] -// @x-panel-log {"bodyKeys":["key","value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改 Fail2Ban 配置 [key] => [value]","formatEN":"update fail2ban conf [key] => [value]"} +// @x-panel-log {"bodyKeys":["key","value"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"修改 Fail2ban 配置 [key] => [value]","formatEN":"update fail2ban conf [key] => [value]"} func (b *BaseApi) UpdateFail2BanConf(c *gin.Context) { var req dto.Fail2BanUpdate if err := helper.CheckBindAndValidate(&req, c); err != nil { @@ -113,7 +113,7 @@ func (b *BaseApi) UpdateFail2BanConf(c *gin.Context) { helper.SuccessWithData(c, nil) } -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Load fail2ban conf // @Description 获取 fail2ban 配置文件 // @Accept json @@ -131,7 +131,7 @@ func (b *BaseApi) LoadFail2BanConf(c *gin.Context) { helper.SuccessWithData(c, string(file)) } -// @Tags Fail2Ban +// @Tags Fail2ban // @Summary Update fail2ban conf by file // @Description 通过文件修改 fail2ban 配置 // @Accept json diff --git a/backend/utils/toolbox/fail2ban.go b/backend/utils/toolbox/fail2ban.go index c18eefb7b..cc70d2f38 100644 --- a/backend/utils/toolbox/fail2ban.go +++ b/backend/utils/toolbox/fail2ban.go @@ -11,7 +11,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/utils/systemctl" ) -type Fail2Ban struct{} +type Fail2ban struct{} const defaultPath = "/etc/fail2ban/jail.local" @@ -22,7 +22,7 @@ type FirewallClient interface { OperateSSHD(operate, ip string) error } -func NewFail2Ban() (*Fail2Ban, error) { +func NewFail2Ban() (*Fail2ban, error) { isExist, _ := systemctl.IsExist("fail2ban.service") if isExist { if _, err := os.Stat(defaultPath); err != nil { @@ -36,10 +36,10 @@ func NewFail2Ban() (*Fail2Ban, error) { } } } - return &Fail2Ban{}, nil + return &Fail2ban{}, nil } -func (f *Fail2Ban) Status() (bool, bool, bool) { +func (f *Fail2ban) Status() (bool, bool, bool) { isEnable, _ := systemctl.IsEnable("fail2ban.service") isActive, _ := systemctl.IsActive("fail2ban.service") isExist, _ := systemctl.IsExist("fail2ban.service") @@ -47,7 +47,7 @@ func (f *Fail2Ban) Status() (bool, bool, bool) { return isEnable, isActive, isExist } -func (f *Fail2Ban) Version() string { +func (f *Fail2ban) Version() string { stdout, err := cmd.Exec("fail2ban-client version") if err != nil { global.LOG.Errorf("load the fail2ban version failed, err: %s", stdout) @@ -56,7 +56,7 @@ func (f *Fail2Ban) Version() string { return strings.ReplaceAll(stdout, "\n", "") } -func (f *Fail2Ban) Operate(operate string) error { +func (f *Fail2ban) Operate(operate string) error { switch operate { case "start", "restart", "stop", "enable", "disable": stdout, err := cmd.Execf("systemctl %s fail2ban.service", operate) @@ -75,7 +75,7 @@ func (f *Fail2Ban) Operate(operate string) error { } } -func (f *Fail2Ban) ReBanIPs(ips []string) error { +func (f *Fail2ban) ReBanIPs(ips []string) error { ipItems, _ := f.ListBanned() stdout, err := cmd.Execf("fail2ban-client unban --all") if err != nil { @@ -92,7 +92,7 @@ func (f *Fail2Ban) ReBanIPs(ips []string) error { return nil } -func (f *Fail2Ban) ListBanned() ([]string, error) { +func (f *Fail2ban) ListBanned() ([]string, error) { var lists []string stdout, err := cmd.Exec("fail2ban-client get sshd banned") if err != nil { @@ -106,7 +106,7 @@ func (f *Fail2Ban) ListBanned() ([]string, error) { return lists, nil } -func (f *Fail2Ban) ListIgnore() ([]string, error) { +func (f *Fail2ban) ListIgnore() ([]string, error) { var lists []string stdout, err := cmd.Exec("fail2ban-client get sshd ignoreip") if err != nil { diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 86bafa69b..f086fade6 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1,5 +1,5 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" @@ -10406,9 +10406,9 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "获取 Fail2Ban 基础信息", + "description": "获取 Fail2ban 基础信息", "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Load fail2ban base info", "responses": { @@ -10433,7 +10433,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Load fail2ban conf", "responses": { @@ -10450,12 +10450,12 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "修改 Fail2Ban 状态", + "description": "修改 Fail2ban 状态", "consumes": [ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Operate fail2ban", "parameters": [ @@ -10475,8 +10475,8 @@ const docTemplate = `{ "bodyKeys": [ "operation" ], - "formatEN": "[operation] Fail2Ban", - "formatZH": "[operation] Fail2Ban", + "formatEN": "[operation] Fail2ban", + "formatZH": "[operation] Fail2ban", "paramKeys": [] } } @@ -10493,7 +10493,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Operate sshd of fail2ban", "parameters": [ @@ -10517,12 +10517,12 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "获取 Fail2Ban ip", + "description": "获取 Fail2ban ip", "consumes": [ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Page fail2ban ip list", "parameters": [ @@ -10553,12 +10553,12 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "修改 Fail2Ban 配置", + "description": "修改 Fail2ban 配置", "consumes": [ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Update fail2ban conf", "parameters": [ @@ -10584,7 +10584,7 @@ const docTemplate = `{ "value" ], "formatEN": "update fail2ban conf [key] =\u003e [value]", - "formatZH": "修改 Fail2Ban 配置 [key] =\u003e [value]", + "formatZH": "修改 Fail2ban 配置 [key] =\u003e [value]", "paramKeys": [] } } @@ -10601,7 +10601,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Update fail2ban conf by file", "parameters": [ diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 22d9e2bae..0a52636b0 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -10399,9 +10399,9 @@ "ApiKeyAuth": [] } ], - "description": "获取 Fail2Ban 基础信息", + "description": "获取 Fail2ban 基础信息", "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Load fail2ban base info", "responses": { @@ -10426,7 +10426,7 @@ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Load fail2ban conf", "responses": { @@ -10443,12 +10443,12 @@ "ApiKeyAuth": [] } ], - "description": "修改 Fail2Ban 状态", + "description": "修改 Fail2ban 状态", "consumes": [ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Operate fail2ban", "parameters": [ @@ -10468,8 +10468,8 @@ "bodyKeys": [ "operation" ], - "formatEN": "[operation] Fail2Ban", - "formatZH": "[operation] Fail2Ban", + "formatEN": "[operation] Fail2ban", + "formatZH": "[operation] Fail2ban", "paramKeys": [] } } @@ -10486,7 +10486,7 @@ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Operate sshd of fail2ban", "parameters": [ @@ -10510,12 +10510,12 @@ "ApiKeyAuth": [] } ], - "description": "获取 Fail2Ban ip", + "description": "获取 Fail2ban ip", "consumes": [ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Page fail2ban ip list", "parameters": [ @@ -10546,12 +10546,12 @@ "ApiKeyAuth": [] } ], - "description": "修改 Fail2Ban 配置", + "description": "修改 Fail2ban 配置", "consumes": [ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Update fail2ban conf", "parameters": [ @@ -10577,7 +10577,7 @@ "value" ], "formatEN": "update fail2ban conf [key] =\u003e [value]", - "formatZH": "修改 Fail2Ban 配置 [key] =\u003e [value]", + "formatZH": "修改 Fail2ban 配置 [key] =\u003e [value]", "paramKeys": [] } } @@ -10594,7 +10594,7 @@ "application/json" ], "tags": [ - "Fail2Ban" + "Fail2ban" ], "summary": "Update fail2ban conf by file", "parameters": [ diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 0b7494148..e88c98a30 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -11292,7 +11292,7 @@ paths: - Device /toolbox/fail2ban/base: get: - description: 获取 Fail2Ban 基础信息 + description: 获取 Fail2ban 基础信息 responses: "200": description: OK @@ -11302,7 +11302,7 @@ paths: - ApiKeyAuth: [] summary: Load fail2ban base info tags: - - Fail2Ban + - Fail2ban /toolbox/fail2ban/load/conf: get: consumes: @@ -11315,12 +11315,12 @@ paths: - ApiKeyAuth: [] summary: Load fail2ban conf tags: - - Fail2Ban + - Fail2ban /toolbox/fail2ban/operate: post: consumes: - application/json - description: 修改 Fail2Ban 状态 + description: 修改 Fail2ban 状态 parameters: - description: request in: body @@ -11333,13 +11333,13 @@ paths: - ApiKeyAuth: [] summary: Operate fail2ban tags: - - Fail2Ban + - Fail2ban x-panel-log: BeforeFunctions: [] bodyKeys: - operation - formatEN: '[operation] Fail2Ban' - formatZH: '[operation] Fail2Ban' + formatEN: '[operation] Fail2ban' + formatZH: '[operation] Fail2ban' paramKeys: [] /toolbox/fail2ban/operate/sshd: post: @@ -11358,12 +11358,12 @@ paths: - ApiKeyAuth: [] summary: Operate sshd of fail2ban tags: - - Fail2Ban + - Fail2ban /toolbox/fail2ban/search: post: consumes: - application/json - description: 获取 Fail2Ban ip + description: 获取 Fail2ban ip parameters: - description: request in: body @@ -11380,12 +11380,12 @@ paths: - ApiKeyAuth: [] summary: Page fail2ban ip list tags: - - Fail2Ban + - Fail2ban /toolbox/fail2ban/update: post: consumes: - application/json - description: 修改 Fail2Ban 配置 + description: 修改 Fail2ban 配置 parameters: - description: request in: body @@ -11400,14 +11400,14 @@ paths: - ApiKeyAuth: [] summary: Update fail2ban conf tags: - - Fail2Ban + - Fail2ban x-panel-log: BeforeFunctions: [] bodyKeys: - key - value formatEN: update fail2ban conf [key] => [value] - formatZH: 修改 Fail2Ban 配置 [key] => [value] + formatZH: 修改 Fail2ban 配置 [key] => [value] paramKeys: [] /toolbox/fail2ban/update/byconf: post: @@ -11428,7 +11428,7 @@ paths: - ApiKeyAuth: [] summary: Update fail2ban conf by file tags: - - Fail2Ban + - Fail2ban /websites: post: consumes: diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index a0d09f7a0..02d7beb17 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -933,10 +933,10 @@ const message = { dnsTestFailed: 'DNS configuration information is not available. Please modify and try again!', }, fail2ban: { - noFail2ban: 'Fail2Ban service not detected, please refer to the official documentation for installation', - unActive: 'The Fail2Ban service is not enabled at present, please enable it first!', - operation: 'Perform [{0}] operation on Fail2Ban service, continue?', - fail2banChange: 'Fail2Ban Configuration Modification', + noFail2ban: 'Fail2ban service not detected, please refer to the official documentation for installation', + unActive: 'The Fail2ban service is not enabled at present, please enable it first!', + operation: 'Perform [{0}] operation on Fail2ban service, continue?', + fail2banChange: 'Fail2ban Configuration Modification', ignoreHelper: 'The IP list in the whitelist will be ignored for blocking, continue?', bannedHelper: 'The IP list in the blacklist will be blocked by the server, continue?', maxRetry: 'Maximum Retry Attempts', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 9750d841a..b234743ad 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -886,10 +886,10 @@ const message = { dnsTestFailed: 'DNS 配置信息不可用,請修改後重試!', }, fail2ban: { - noFail2ban: '未檢測到 Fail2Ban 服務,請參考官方文檔進行安裝', - unActive: '當前未開啟 Fail2Ban 服務,請先開啟!', - operation: '對 Fail2Ban 服務進行 [{0}] 操作,是否繼續?', - fail2banChange: 'Fail2Ban 配置修改', + noFail2ban: '未檢測到 Fail2ban 服務,請參考官方文檔進行安裝', + unActive: '當前未開啟 Fail2ban 服務,請先開啟!', + operation: '對 Fail2ban 服務進行 [{0}] 操作,是否繼續?', + fail2banChange: 'Fail2ban 配置修改', ignoreHelper: '白名單中的 IP 列表將被忽略屏蔽,是否繼續?', bannedHelper: '黑名單中的 IP 列表將被伺服器屏蔽,是否繼續?', maxRetry: '最大重試次數', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index d870aee99..3c69fd3fa 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -887,10 +887,10 @@ const message = { dnsTestFailed: 'DNS 配置信息不可用,请修改后重试!', }, fail2ban: { - noFail2ban: '未检测到 Fail2Ban 服务,请参考官方文档进行安装', - unActive: '当前未开启 Fail2Ban 服务,请先开启!', - operation: '对 Fail2Ban 服务进行 [{0}] 操作,是否继续?', - fail2banChange: 'Fail2Ban 配置修改', + noFail2ban: '未检测到 Fail2ban 服务,请参考官方文档进行安装', + unActive: '当前未开启 Fail2ban 服务,请先开启!', + operation: '对 Fail2ban 服务进行 [{0}] 操作,是否继续?', + fail2banChange: 'Fail2ban 配置修改', ignoreHelper: '白名单中的 IP 列表将被忽略屏蔽,是否继续?', bannedHelper: '黑名单中的 IP 列表将被服务器屏蔽,是否继续?', maxRetry: '最大重试次数', diff --git a/frontend/src/routers/modules/toolbox.ts b/frontend/src/routers/modules/toolbox.ts index 2da2d05c3..3d20830b1 100644 --- a/frontend/src/routers/modules/toolbox.ts +++ b/frontend/src/routers/modules/toolbox.ts @@ -39,7 +39,7 @@ const toolboxRouter = { }, { path: 'fail2Ban', - name: 'Fail2Ban', + name: 'Fail2ban', component: () => import('@/views/toolbox/fail2ban/index.vue'), hidden: true, meta: { diff --git a/frontend/src/views/toolbox/fail2ban/index.vue b/frontend/src/views/toolbox/fail2ban/index.vue index 89011f044..bcb83925b 100644 --- a/frontend/src/views/toolbox/fail2ban/index.vue +++ b/frontend/src/views/toolbox/fail2ban/index.vue @@ -3,7 +3,7 @@
- Fail2Ban + Fail2ban {{ $t('commons.status.running') }} @@ -43,7 +43,7 @@ {{ $t('toolbox.fail2ban.unActive') }} - +