🎨基本功能结束
This commit is contained in:
parent
763443bad2
commit
d50f17ed12
@ -1,9 +1,12 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"gitee.ltd/lxh/logger/log"
|
"gitee.ltd/lxh/logger/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"wireguard-dashboard/http/param"
|
"wireguard-dashboard/http/param"
|
||||||
|
"wireguard-dashboard/model/entity"
|
||||||
|
"wireguard-dashboard/queues"
|
||||||
"wireguard-dashboard/repository"
|
"wireguard-dashboard/repository"
|
||||||
"wireguard-dashboard/utils"
|
"wireguard-dashboard/utils"
|
||||||
)
|
)
|
||||||
@ -14,6 +17,59 @@ func Setting() setting {
|
|||||||
return setting{}
|
return setting{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSetting
|
||||||
|
// @description: 添加/更改设置
|
||||||
|
// @receiver setting
|
||||||
|
// @param c
|
||||||
|
func (setting) SetSetting(c *gin.Context) {
|
||||||
|
var p param.SetSetting
|
||||||
|
if err := c.ShouldBind(&p); err != nil {
|
||||||
|
utils.GinResponse(c).FailedWithErr("参数错误", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := repository.System().Save(&entity.Setting{
|
||||||
|
Code: p.Code,
|
||||||
|
Data: p.Data,
|
||||||
|
Describe: p.Describe,
|
||||||
|
}); err != nil {
|
||||||
|
utils.GinResponse(c).FailedWithErr("操作失败", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.GinResponse(c).OK()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetServerGlobal
|
||||||
|
// @description: 设置服务端的全局设定
|
||||||
|
// @receiver setting
|
||||||
|
// @param c
|
||||||
|
func (setting) SetServerGlobal(c *gin.Context) {
|
||||||
|
var p param.SetServerGlobal
|
||||||
|
if err := c.ShouldBind(&p); err != nil {
|
||||||
|
utils.GinResponse(c).FailedWithErr("参数错误", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, _ := json.Marshal(p.Data)
|
||||||
|
|
||||||
|
var ent entity.Setting
|
||||||
|
ent.Code = "SERVER_SETTING"
|
||||||
|
ent.Data = string(data)
|
||||||
|
if err := repository.System().Save(&ent); err != nil {
|
||||||
|
utils.GinResponse(c).FailedWithErr("操作失败", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := queues.PutAsyncWireguardConfigFile(""); err != nil {
|
||||||
|
log.Errorf("[设置服务端],发起同步配置文件失败: %v", err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
utils.GinResponse(c).OK()
|
||||||
|
}
|
||||||
|
|
||||||
// GetGlobalSetting
|
// GetGlobalSetting
|
||||||
// @description: 获取全局设置配置
|
// @description: 获取全局设置配置
|
||||||
// @receiver setting
|
// @receiver setting
|
||||||
@ -27,19 +83,6 @@ func (setting) GetGlobalSetting(c *gin.Context) {
|
|||||||
utils.GinResponse(c).OKWithData(data)
|
utils.GinResponse(c).OKWithData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetGlobalServerSetting
|
|
||||||
// @description: 设置全局服务配置
|
|
||||||
// @receiver setting
|
|
||||||
// @param c
|
|
||||||
func (setting) SetGlobalServerSetting(c *gin.Context) {
|
|
||||||
var p param.SetSetting
|
|
||||||
if err := c.ShouldBind(&p); err != nil {
|
|
||||||
utils.GinResponse(c).FailedWithErr("参数错误", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPublicNetworkIP
|
// GetPublicNetworkIP
|
||||||
// @description: 获取当前机器的公网IP
|
// @description: 获取当前机器的公网IP
|
||||||
// @receiver setting
|
// @receiver setting
|
||||||
|
@ -3,6 +3,21 @@ package param
|
|||||||
// SetSetting
|
// SetSetting
|
||||||
// @description: 设置
|
// @description: 设置
|
||||||
type SetSetting struct {
|
type SetSetting struct {
|
||||||
Code string `json:"code" form:"code" binding:"required"`
|
Code string `json:"code" form:"code" binding:"required"` // 设置的唯一编码
|
||||||
Data string `json:"data" form:"data" binding:"required"`
|
Data string `json:"data" form:"data" binding:"required"` // 数据
|
||||||
|
Describe string `json:"describe" form:"describe" binding:"omitempty"` // 描述
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetServerGlobal
|
||||||
|
// @description: 设置服务端全局配置
|
||||||
|
type SetServerGlobal struct {
|
||||||
|
Data struct {
|
||||||
|
EndpointAddress string `json:"endpointAddress" binding:"required"` // 服务公网IP
|
||||||
|
DnsServer []string `json:"dnsServer" binding:"required"` // DNS列表
|
||||||
|
MTU int `json:"MTU" binding:"required"`
|
||||||
|
PersistentKeepalive int `json:"persistentKeepalive" binding:"omitempty"`
|
||||||
|
FirewallMark string `json:"firewallMark" binding:"omitempty"`
|
||||||
|
Table string `json:"table" binding:"omitempty"`
|
||||||
|
ConfigFilePath string `json:"configFilePath" binding:"required"` // 配置文件对外输出目录
|
||||||
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@ func asyncWireguardConfigFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serverId := result[1]
|
serverId := result[1]
|
||||||
|
if serverId == "" {
|
||||||
|
serverInfo, err := repository.Server().GetServer()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("没有找到服务端: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
serverId = serverInfo.Id
|
||||||
|
}
|
||||||
|
|
||||||
// 使用serverId获取服务信息
|
// 使用serverId获取服务信息
|
||||||
serverEnt, err := repository.Server().GetServerWithClient(serverId)
|
serverEnt, err := repository.Server().GetServerWithClient(serverId)
|
||||||
|
@ -12,7 +12,9 @@ import (
|
|||||||
func SettingApi(r *gin.RouterGroup) {
|
func SettingApi(r *gin.RouterGroup) {
|
||||||
apiGroup := r.Group("setting", middleware.Authorization())
|
apiGroup := r.Group("setting", middleware.Authorization())
|
||||||
{
|
{
|
||||||
apiGroup.GET("server", api.Setting().GetGlobalSetting) // 获取全局服务端配置
|
apiGroup.POST("save", middleware.Permission(), api.Setting().SetSetting) // 添加/更改设置 - 设置其他的配置
|
||||||
apiGroup.GET("public-ip", api.Setting().GetPublicNetworkIP) // 获取公网IP
|
apiGroup.POST("server-global", middleware.Permission(), api.Setting().SetServerGlobal) // 设置服务端全局配置
|
||||||
|
apiGroup.GET("server", api.Setting().GetGlobalSetting) // 获取全局服务端配置
|
||||||
|
apiGroup.GET("public-ip", api.Setting().GetPublicNetworkIP) // 获取公网IP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user