🆕新增接口控制服务端、命令控制服务端

This commit is contained in:
coward
2024-03-22 10:42:36 +08:00
parent a988b66ccd
commit 86c76add17
10 changed files with 142 additions and 44 deletions

View File

@@ -91,6 +91,13 @@ func (clients) Delete(c *gin.Context) {
return
}
// 再同步一下配置文件
go func() {
if err := queues.PutAsyncWireguardConfigFile(""); err != nil {
log.Errorf("[下线客户端]同步配置文件失败: %v", err.Error())
}
}()
utils.GinResponse(c).OK()
}

View File

@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"strings"
"wireguard-dashboard/command"
"wireguard-dashboard/http/param"
"wireguard-dashboard/model/entity"
"wireguard-dashboard/queues"
@@ -89,3 +90,26 @@ func (server) GetServer(c *gin.Context) {
utils.GinResponse(c).OKWithData(data)
}
// ControlServer
// @description: 服务端控制器
// @receiver server
// @param c
func (server) ControlServer(c *gin.Context) {
var p param.ControlServer
if err := c.ShouldBind(&p); err != nil {
utils.GinResponse(c).FailedWithErr("参数错误", err)
return
}
switch p.Status {
case "START":
command.StartWireguard()
case "STOP":
command.StopWireguard()
case "RESTART":
command.RestartWireguard(false)
}
utils.GinResponse(c).OK()
}

View File

@@ -31,3 +31,9 @@ type SaveClient struct {
Keys *template_data.Keys `json:"keys" form:"keys" binding:"omitempty"`
Enabled int `json:"enabled" form:"enabled" binding:"required,oneof=1 0"`
}
// ControlServer
// @description: 服务端控制
type ControlServer struct {
Status string `json:"status" form:"status" binding:"required,oneof=START STOP RESTART"`
}