wol 测试

WafRateLimitTest 测试 X-Forwarded-For
This commit is contained in:
Shikong 2022-11-11 22:43:21 +08:00
parent 6662b67ca5
commit d12286939f
5 changed files with 170 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package test package test
import ( import (
"fmt"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"gofiber.study.skcks.cn/common/errorx" "gofiber.study.skcks.cn/common/errorx"
"gofiber.study.skcks.cn/common/logger" "gofiber.study.skcks.cn/common/logger"
@ -10,6 +11,8 @@ import (
"gofiber.study.skcks.cn/model/dto" "gofiber.study.skcks.cn/model/dto"
"gofiber.study.skcks.cn/model/vo" "gofiber.study.skcks.cn/model/vo"
"gofiber.study.skcks.cn/services/waf" "gofiber.study.skcks.cn/services/waf"
"gofiber.study.skcks.cn/services/wol"
"strconv"
"time" "time"
) )
@ -194,7 +197,13 @@ func (c *Controller) VerifyCaptchaTest() {
// @Router /test/waf/access [get] // @Router /test/waf/access [get]
func (c *Controller) WafRateLimitTest() { func (c *Controller) WafRateLimitTest() {
c.Router.Add(fiber.MethodGet, "/waf/access", func(ctx *fiber.Ctx) error { c.Router.Add(fiber.MethodGet, "/waf/access", func(ctx *fiber.Ctx) error {
access := waf.Service.Access(ctx.IP()) logger.Log.Infof("ip: %v", ctx.GetReqHeaders())
ip := ctx.GetReqHeaders()["X-Forwarded-For"]
if len(ip) == 0 {
ip = ctx.IP()
}
access := waf.Service.Access(ip)
if !access { if !access {
return ctx.JSON(errorx.NewErrorWithCode(fiber.StatusTooManyRequests, "访问频率超过限制")) return ctx.JSON(errorx.NewErrorWithCode(fiber.StatusTooManyRequests, "访问频率超过限制"))
} }
@ -202,3 +211,31 @@ func (c *Controller) WafRateLimitTest() {
return ctx.JSON(response.NewResponse("正常访问")) return ctx.JSON(response.NewResponse("正常访问"))
}) })
} }
// WolTest wol 测试
//
// @Summary wol 测试
// @Description wol 测试
// @Tags Test
// @Accept json
// @Produce json
// @Param mac query string true "mac"
// @Success 200 {object} response.Response{data=string}
// @Failure default {object} errorx.CodeErrorResponse
// @Router /test/wol [get]
func (c *Controller) WolTest() {
c.Router.Add(fiber.MethodGet, "/wol", func(ctx *fiber.Ctx) error {
mac := ctx.Query("mac")
port, err := strconv.Atoi(ctx.Query("port", "9"))
if err := errorx.ParseError(err); err != nil {
return ctx.JSON(err)
}
err = wol.Services.WakeUp(mac, port)
if err := errorx.ParseError(err); err != nil {
return ctx.JSON(err)
} else {
return ctx.JSON(response.NewResponse(fmt.Sprintf("%s 唤醒成功", mac)))
}
})
}

View File

@ -758,6 +758,56 @@ const docTemplate = `{
} }
} }
}, },
"/test/wol": {
"get": {
"description": "wol 测试",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Test"
],
"summary": "wol 测试",
"parameters": [
{
"type": "string",
"description": "mac",
"name": "mac",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.Response"
},
{
"type": "object",
"properties": {
"data": {
"type": "string"
}
}
}
]
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/errorx.CodeErrorResponse"
}
}
}
}
},
"/user/account": { "/user/account": {
"get": { "get": {
"security": [ "security": [

View File

@ -750,6 +750,56 @@
} }
} }
}, },
"/test/wol": {
"get": {
"description": "wol 测试",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Test"
],
"summary": "wol 测试",
"parameters": [
{
"type": "string",
"description": "mac",
"name": "mac",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.Response"
},
{
"type": "object",
"properties": {
"data": {
"type": "string"
}
}
}
]
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/errorx.CodeErrorResponse"
}
}
}
}
},
"/user/account": { "/user/account": {
"get": { "get": {
"security": [ "security": [

View File

@ -584,6 +584,36 @@ paths:
summary: waf 访问频率限制 测试 summary: waf 访问频率限制 测试
tags: tags:
- Test - Test
/test/wol:
get:
consumes:
- application/json
description: wol 测试
parameters:
- description: mac
in: query
name: mac
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.Response'
- properties:
data:
type: string
type: object
default:
description: ""
schema:
$ref: '#/definitions/errorx.CodeErrorResponse'
summary: wol 测试
tags:
- Test
/user/account: /user/account:
get: get:
consumes: consumes:

View File

@ -4,10 +4,12 @@ import (
"gofiber.study.skcks.cn/services/auth" "gofiber.study.skcks.cn/services/auth"
"gofiber.study.skcks.cn/services/user" "gofiber.study.skcks.cn/services/user"
"gofiber.study.skcks.cn/services/waf" "gofiber.study.skcks.cn/services/waf"
"gofiber.study.skcks.cn/services/wol"
) )
func Init() { func Init() {
auth.InitService() auth.InitService()
user.InitService() user.InitService()
waf.InitService() waf.InitService()
wol.InitService()
} }