2023-11-02 23:35:05 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2023-11-03 00:01:00 +08:00
|
|
|
"github.com/shirou/gopsutil/net"
|
2023-11-02 23:35:05 +08:00
|
|
|
response "iptables-helper/pkg/resp"
|
|
|
|
"iptables-helper/pkg/utils/command"
|
|
|
|
"iptables-helper/pkg/utils/iptables"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetupController(r fiber.Router) {
|
|
|
|
api := r.Group("/")
|
|
|
|
getRuleInfo(api)
|
2023-11-03 00:01:00 +08:00
|
|
|
getIfInfo(api)
|
2023-11-02 23:35:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// getRuleInfo
|
|
|
|
// @Summary 获取 iptables 规则 信息
|
|
|
|
// @Description 获取 iptables 规则 信息
|
|
|
|
// @Tags Info
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} response.Response{data=iptables.Info}
|
|
|
|
// @Failure default {object} errorx.CodeErrorResponse
|
|
|
|
// @Router /info [get]
|
|
|
|
func getRuleInfo(api fiber.Router) {
|
|
|
|
api.Get("/info", func(ctx *fiber.Ctx) error {
|
|
|
|
cmder := command.Commander{}
|
|
|
|
result := cmder.ExecuteWithResult("sudo iptables -S")
|
|
|
|
return ctx.JSON(response.NewResponse(iptables.Parse(result)))
|
|
|
|
})
|
|
|
|
}
|
2023-11-03 00:01:00 +08:00
|
|
|
|
|
|
|
// getIfInfo
|
|
|
|
// @Summary 获取 网卡 信息
|
|
|
|
// @Description 获取 网卡 信息
|
|
|
|
// @Tags Info
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} response.Response{data=[]net.InterfaceStat}
|
|
|
|
// @Failure default {object} errorx.CodeErrorResponse
|
|
|
|
// @Router /if/info [get]
|
|
|
|
func getIfInfo(api fiber.Router) {
|
|
|
|
api.Get("/if/info", func(ctx *fiber.Ctx) error {
|
|
|
|
stat, _ := net.Interfaces()
|
|
|
|
return ctx.JSON(response.NewResponse(stat))
|
|
|
|
})
|
|
|
|
}
|