Skip to content

Commit

Permalink
feat: 更新说明
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Aug 24, 2024
1 parent 6e9a496 commit b82bc21
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 201 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

交流QQ群:[12370907](https://jq.qq.com/?_wv=1027&k=I1oJKSTH) | 论坛:[tom.moe](https://tom.moe) | 赞助:[爱发电](https://afdian.com/a/TheTNB)

## 项目现状

**目前我在着手使用新的「自研」框架重构本项目,由于更改非常大需要一定时间,预期 8 月底会带来新的更新。**

## 优势

1. **极低占用:** 在 Debian 12 下部署面板 + LNMP 环境,内存占用不到 500 MB,遥遥领先于使用容器化的其他面板。
Expand Down
187 changes: 0 additions & 187 deletions app/http/controllers/plugins/openresty_controller.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package plugins
package openresty

import (
"regexp"
Expand All @@ -19,18 +19,18 @@ import (
"github.com/TheTNB/panel/v2/pkg/types"
)

type Fail2banController struct {
type Controller struct {
website internal.Website
}

func NewFail2banController() *Fail2banController {
return &Fail2banController{
func NewController() *Controller {
return &Controller{
website: services.NewWebsiteImpl(),
}
}

// List 所有 Fail2ban 规则
func (r *Fail2banController) List(ctx http.Context) http.Response {
func (r *Controller) List(ctx http.Context) http.Response {
raw, err := io.Read("/etc/fail2ban/jail.local")
if err != nil {
return h.Error(ctx, http.StatusUnprocessableEntity, err.Error())
Expand Down Expand Up @@ -77,7 +77,7 @@ func (r *Fail2banController) List(ctx http.Context) http.Response {
}

// Add 添加 Fail2ban 规则
func (r *Fail2banController) Add(ctx http.Context) http.Response {
func (r *Controller) Add(ctx http.Context) http.Response {
if sanitize := h.Sanitize(ctx, map[string]string{
"name": "required",
"type": "required|in:website,service",
Expand Down Expand Up @@ -217,7 +217,7 @@ logpath = ` + logPath + `
}

// Delete 删除规则
func (r *Fail2banController) Delete(ctx http.Context) http.Response {
func (r *Controller) Delete(ctx http.Context) http.Response {
jailName := ctx.Request().Input("name")
raw, err := io.Read("/etc/fail2ban/jail.local")
if err != nil {
Expand All @@ -242,7 +242,7 @@ func (r *Fail2banController) Delete(ctx http.Context) http.Response {
}

// BanList 获取封禁列表
func (r *Fail2banController) BanList(ctx http.Context) http.Response {
func (r *Controller) BanList(ctx http.Context) http.Response {
name := ctx.Request().Input("name")
if len(name) == 0 {
return h.Error(ctx, http.StatusUnprocessableEntity, "缺少参数")
Expand Down Expand Up @@ -283,7 +283,7 @@ func (r *Fail2banController) BanList(ctx http.Context) http.Response {
}

// Unban 解封
func (r *Fail2banController) Unban(ctx http.Context) http.Response {
func (r *Controller) Unban(ctx http.Context) http.Response {
name := ctx.Request().Input("name")
ip := ctx.Request().Input("ip")
if len(name) == 0 || len(ip) == 0 {
Expand All @@ -298,7 +298,7 @@ func (r *Fail2banController) Unban(ctx http.Context) http.Response {
}

// SetWhiteList 设置白名单
func (r *Fail2banController) SetWhiteList(ctx http.Context) http.Response {
func (r *Controller) SetWhiteList(ctx http.Context) http.Response {
ip := ctx.Request().Input("ip")
if len(ip) == 0 {
return h.Error(ctx, http.StatusUnprocessableEntity, "缺少参数")
Expand Down Expand Up @@ -327,7 +327,7 @@ func (r *Fail2banController) SetWhiteList(ctx http.Context) http.Response {
}

// GetWhiteList 获取白名单
func (r *Fail2banController) GetWhiteList(ctx http.Context) http.Response {
func (r *Controller) GetWhiteList(ctx http.Context) http.Response {
raw, err := io.Read("/etc/fail2ban/jail.local")
if err != nil {
return h.Error(ctx, http.StatusUnprocessableEntity, err.Error())
Expand Down
39 changes: 39 additions & 0 deletions app/plugins/fail2ban/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package openresty

import (
"github.com/goravel/framework/contracts/foundation"
"github.com/goravel/framework/contracts/route"

"github.com/TheTNB/panel/v2/app/http/middleware"
"github.com/TheTNB/panel/v2/app/plugins/loader"
"github.com/TheTNB/panel/v2/pkg/types"
)

func init() {
loader.Register(&types.Plugin{
Name: "Fail2ban",
Description: "Fail2ban 扫描系统日志文件并从中找出多次尝试失败的IP地址,将该IP地址加入防火墙的拒绝访问列表中",
Slug: "fail2ban",
Version: "1.0.2",
Requires: []string{},
Excludes: []string{},
Install: `bash /www/panel/scripts/fail2ban/install.sh`,
Uninstall: `bash /www/panel/scripts/fail2ban/uninstall.sh`,
Update: `bash /www/panel/scripts/fail2ban/update.sh`,
Boot: func(app foundation.Application) {
RouteFacade := app.MakeRoute()
RouteFacade.Prefix("api/plugins/fail2ban").Middleware(middleware.Session(), middleware.MustInstall()).Group(func(r route.Router) {
r.Prefix("openresty").Group(func(route route.Router) {
controller := NewController()
route.Get("jails", controller.List)
route.Post("jails", controller.Add)
route.Delete("jails", controller.Delete)
route.Get("jails/{name}", controller.BanList)
route.Post("unban", controller.Unban)
route.Post("whiteList", controller.SetWhiteList)
route.Get("whiteList", controller.GetWhiteList)
})
})
},
})
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions app/plugins/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func All() []*types.Plugin {
return data
}

// New 新注册插件
func New(plugin *types.Plugin) {
// Register 注册插件
func Register(plugin *types.Plugin) {
data = append(data, plugin)
}
File renamed without changes.
2 changes: 1 addition & 1 deletion app/plugins/openresty/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func init() {
loader.New(&types.Plugin{
loader.Register(&types.Plugin{
Name: "OpenResty",
Description: "OpenResty® 是一款基于 NGINX 和 LuaJIT 的 Web 平台",
Slug: "openresty",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b82bc21

Please sign in to comment.