🐛导入配置时,获取当前系统的公网IP,避免手动去更改
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
13e4006592
commit
72b8473591
@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
slog "gitee.ltd/lxh/logger/log"
|
slog "gitee.ltd/lxh/logger/log"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
@ -10,6 +11,7 @@ import (
|
|||||||
"wireguard-ui/http/vo"
|
"wireguard-ui/http/vo"
|
||||||
"wireguard-ui/model"
|
"wireguard-ui/model"
|
||||||
"wireguard-ui/template/render_data"
|
"wireguard-ui/template/render_data"
|
||||||
|
"wireguard-ui/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type setting struct{ *gorm.DB }
|
type setting struct{ *gorm.DB }
|
||||||
@ -151,6 +153,9 @@ func (s setting) Export() (data vo.Export, err error) {
|
|||||||
// @param data
|
// @param data
|
||||||
// @return err
|
// @return err
|
||||||
func (s setting) Import(data *vo.Export, loginUser *vo.User) (err error) {
|
func (s setting) Import(data *vo.Export, loginUser *vo.User) (err error) {
|
||||||
|
// 获取导入系统的公网IP地址
|
||||||
|
pubAddr := utils.Network().GetHostPublicIP()
|
||||||
|
data.Global.EndpointAddress = pubAddr
|
||||||
// 先更新global配置
|
// 先更新global配置
|
||||||
gst, _ := json.Marshal(data.Global)
|
gst, _ := json.Marshal(data.Global)
|
||||||
gs := &model.Setting{
|
gs := &model.Setting{
|
||||||
@ -179,20 +184,24 @@ func (s setting) Import(data *vo.Export, loginUser *vo.User) (err error) {
|
|||||||
PublicKey: v.Keys.PublicKey,
|
PublicKey: v.Keys.PublicKey,
|
||||||
PresharedKey: v.Keys.PresharedKey,
|
PresharedKey: v.Keys.PresharedKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
cc := param.SaveClient{
|
cc := param.SaveClient{
|
||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
Email: v.Email,
|
Email: v.Email,
|
||||||
IpAllocation: v.IpAllocation,
|
IpAllocation: v.IpAllocation,
|
||||||
AllowedIps: v.AllowedIps,
|
AllowedIps: v.AllowedIps,
|
||||||
ExtraAllowedIps: v.ExtraAllowedIps,
|
ExtraAllowedIps: v.ExtraAllowedIps,
|
||||||
Endpoint: v.Endpoint,
|
|
||||||
UseServerDns: v.UseServerDns,
|
UseServerDns: v.UseServerDns,
|
||||||
Keys: keys,
|
Keys: keys,
|
||||||
Enabled: v.Enabled,
|
Enabled: v.Enabled,
|
||||||
OfflineMonitoring: v.OfflineMonitoring,
|
OfflineMonitoring: v.OfflineMonitoring,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.Endpoint != "" {
|
||||||
|
port := strings.Split(v.Endpoint, ":")[1]
|
||||||
|
endpoint := fmt.Sprintf("%s:%s", pubAddr, port)
|
||||||
|
cc.Endpoint = endpoint
|
||||||
|
}
|
||||||
|
|
||||||
if err := Client().SaveClient(cc, loginUser); err != nil {
|
if err := Client().SaveClient(cc, loginUser); err != nil {
|
||||||
slog.Errorf("客户端[%s]导入失败: %v", v.Name, err)
|
slog.Errorf("客户端[%s]导入失败: %v", v.Name, err)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user