Browse Source

fix: Fail2ban 名称修改 (#3071)

pull/3072/head
ssongliu 1 year ago committed by GitHub
parent
commit
1df4a870a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      backend/app/api/v1/fail2ban.go
  2. 18
      backend/utils/toolbox/fail2ban.go
  3. 32
      cmd/server/docs/docs.go
  4. 28
      cmd/server/docs/swagger.json
  5. 28
      cmd/server/docs/swagger.yaml
  6. 8
      frontend/src/lang/modules/en.ts
  7. 8
      frontend/src/lang/modules/tw.ts
  8. 8
      frontend/src/lang/modules/zh.ts
  9. 2
      frontend/src/routers/modules/toolbox.ts
  10. 10
      frontend/src/views/toolbox/fail2ban/index.vue
  11. 2
      frontend/src/views/toolbox/index.vue

26
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

18
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 {

32
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": [

28
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": [

28
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:

8
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',

8
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: '最大重試次數',

8
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: '最大重试次数',

2
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: {

10
frontend/src/views/toolbox/fail2ban/index.vue

@ -3,7 +3,7 @@
<div class="app-status" style="margin-top: 20px">
<el-card v-if="form.isExist">
<div>
<el-tag effect="dark" type="success">Fail2Ban</el-tag>
<el-tag effect="dark" type="success">Fail2ban</el-tag>
<el-tag round class="status-content" v-if="form.isActive" type="success">
{{ $t('commons.status.running') }}
</el-tag>
@ -43,7 +43,7 @@
<el-card v-if="!form.isActive" class="mask-prompt">
<span>{{ $t('toolbox.fail2ban.unActive') }}</span>
</el-card>
<LayoutContent title="Fail2Ban" :divider="true" :class="{ mask: !form.isActive }">
<LayoutContent title="Fail2ban" :divider="true" :class="{ mask: !form.isActive }">
<template #toolbar>
<el-row>
<el-col :span="16">
@ -109,7 +109,7 @@
<div v-if="confShowType === 'all'">
<codemirror
:autofocus="true"
placeholder="# The Fail2Ban configuration file does not exist or is empty (/etc/ssh/sshd_config)"
placeholder="# The Fail2ban configuration file does not exist or is empty (/etc/ssh/sshd_config)"
:indent-with-tab="true"
:tabSize="4"
style="margin-top: 10px; height: calc(100vh - 460px)"
@ -128,7 +128,7 @@
</LayoutContent>
</div>
<div v-else>
<LayoutContent title="Fail2Ban" :divider="true">
<LayoutContent title="Fail2ban" :divider="true">
<template #main>
<div class="app-warn">
<div>
@ -245,7 +245,7 @@ const onChangeBanAction = () => {
const onOperate = async (operation: string) => {
let msg = operation === 'enable' || operation === 'disable' ? 'ssh.' : 'commons.button.';
ElMessageBox.confirm(i18n.global.t('toolbox.fail2ban.operation', [i18n.global.t(msg + operation)]), 'Fail2Ban', {
ElMessageBox.confirm(i18n.global.t('toolbox.fail2ban.operation', [i18n.global.t(msg + operation)]), 'Fail2ban', {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',

2
frontend/src/views/toolbox/index.vue

@ -20,7 +20,7 @@ const buttons = [
path: '/toolbox/supervisor',
},
{
label: 'Fail2Ban',
label: 'Fail2ban',
path: '/toolbox/fail2ban',
},
];

Loading…
Cancel
Save