Skip to content

Commit

Permalink
feat: 测试插件
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Sep 17, 2024
1 parent 3193a15 commit 615744e
Show file tree
Hide file tree
Showing 11 changed files with 646 additions and 272 deletions.
1 change: 1 addition & 0 deletions internal/biz/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type WebsiteRepo interface {
UpdateDefaultConfig(req *request.WebsiteDefaultConfig) error
Count() (int64, error)
Get(id uint) (*types.WebsiteSetting, error)
GetByName(name string) (*types.WebsiteSetting, error)
List(page, limit uint) ([]*Website, int64, error)
Create(req *request.WebsiteCreate) (*Website, error)
Update(req *request.WebsiteUpdate) error
Expand Down
10 changes: 10 additions & 0 deletions internal/data/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ func (r *websiteRepo) Get(id uint) (*types.WebsiteSetting, error) {
return setting, err
}

func (r *websiteRepo) GetByName(name string) (*types.WebsiteSetting, error) {
website := new(biz.Website)
if err := app.Orm.Where("name", name).First(website).Error; err != nil {
return nil, err
}

return r.Get(website.ID)

}

func (r *websiteRepo) List(page, limit uint) ([]*biz.Website, int64, error) {
var websites []*biz.Website
var total int64
Expand Down
32 changes: 32 additions & 0 deletions internal/plugin/fail2ban/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fail2ban

import (
"github.com/go-chi/chi/v5"

"github.com/TheTNB/panel/pkg/pluginloader"
"github.com/TheTNB/panel/pkg/types"
)

func init() {
pluginloader.Register(&types.Plugin{
Slug: "fail2ban",
Name: "Fail2ban",
Description: "Fail2ban 扫描系统日志文件并从中找出多次尝试失败的IP地址,将该IP地址加入防火墙的拒绝访问列表中",
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`,
Route: func(r chi.Router) {
service := NewService()
r.Get("/jails", service.List)
r.Post("/jails", service.Add)
r.Delete("/jails", service.Delete)
r.Get("/jails/{name}", service.BanList)
r.Post("/unban", service.Unban)
r.Post("/whiteList", service.SetWhiteList)
r.Get("/whiteList", service.GetWhiteList)
},
})
}
29 changes: 29 additions & 0 deletions internal/plugin/fail2ban/request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fail2ban

type Add struct {
Name string `json:"name"`
Type string `json:"type"`
MaxRetry string `json:"maxretry"`
FindTime string `json:"findtime"`
BanTime string `json:"bantime"`
WebsiteName string `json:"website_name"`
WebsiteMode string `json:"website_mode"`
WebsitePath string `json:"website_path"`
}

type Delete struct {
Name string `json:"name"`
}

type BanList struct {
Name string `json:"name"`
}

type Unban struct {
Name string `json:"name"`
IP string `json:"ip"`
}

type SetWhiteList struct {
IP string `json:"ip"`
}
Loading

0 comments on commit 615744e

Please sign in to comment.