2020-08-21 21:09:42 +08:00
|
|
|
package components
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-02 17:22:24 +08:00
|
|
|
"encoding/json"
|
2020-08-21 21:09:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2023-06-30 18:08:30 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
2020-10-02 17:22:24 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2020-10-31 17:44:48 +08:00
|
|
|
SettingCodeServerGlobalConfig = "serverGlobalConfig"
|
2020-08-21 21:09:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type IndexAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) Init() {
|
|
|
|
|
this.Nav("", "component", "index")
|
2020-09-13 20:37:07 +08:00
|
|
|
this.SecondMenu("global")
|
2020-08-21 21:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
2020-10-31 17:44:48 +08:00
|
|
|
valueJSONResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: SettingCodeServerGlobalConfig})
|
2020-10-02 17:22:24 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
valueJSON := valueJSONResp.ValueJSON
|
|
|
|
|
globalConfig := &serverconfigs.GlobalConfig{}
|
2020-12-18 21:18:35 +08:00
|
|
|
|
2020-10-02 17:22:24 +08:00
|
|
|
if len(valueJSON) > 0 {
|
|
|
|
|
err = json.Unmarshal(valueJSON, globalConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.Data["globalConfig"] = globalConfig
|
2020-08-21 21:09:42 +08:00
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
2020-10-02 17:22:24 +08:00
|
|
|
|
|
|
|
|
func (this *IndexAction) RunPost(params struct {
|
|
|
|
|
GlobalConfigJSON []byte
|
|
|
|
|
Must *actions.Must
|
2020-11-18 12:17:50 +08:00
|
|
|
|
|
|
|
|
// 不匹配域名相关
|
|
|
|
|
AllowMismatchDomains []string
|
|
|
|
|
DomainMismatchAction string
|
|
|
|
|
DomainMismatchActionPageStatusCode int
|
|
|
|
|
DomainMismatchActionPageContentHTML string
|
|
|
|
|
|
2021-01-14 16:35:25 +08:00
|
|
|
// TCP端口设置
|
|
|
|
|
TcpAllPortRangeMin int
|
|
|
|
|
TcpAllPortRangeMax int
|
|
|
|
|
TcpAllDenyPorts []int
|
|
|
|
|
|
2020-11-18 12:17:50 +08:00
|
|
|
DefaultDomain string
|
2020-10-02 17:22:24 +08:00
|
|
|
}) {
|
2020-11-10 21:37:48 +08:00
|
|
|
// 创建日志
|
2023-06-30 18:08:30 +08:00
|
|
|
defer this.CreateLogInfo(codes.Server_LogUpdateGlobalSettings)
|
2020-11-10 21:37:48 +08:00
|
|
|
|
2020-10-02 17:22:24 +08:00
|
|
|
if len(params.GlobalConfigJSON) == 0 {
|
|
|
|
|
this.Fail("错误的配置信息,请刷新当前页面后重试")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
globalConfig := &serverconfigs.GlobalConfig{}
|
|
|
|
|
err := json.Unmarshal(params.GlobalConfigJSON, globalConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("配置校验失败:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 16:35:25 +08:00
|
|
|
// TCP端口范围
|
|
|
|
|
if params.TcpAllPortRangeMin < 1024 {
|
|
|
|
|
params.TcpAllPortRangeMin = 1024
|
|
|
|
|
}
|
|
|
|
|
if params.TcpAllPortRangeMax > 65534 {
|
|
|
|
|
params.TcpAllPortRangeMax = 65534
|
|
|
|
|
} else if params.TcpAllPortRangeMax < 1024 {
|
|
|
|
|
params.TcpAllPortRangeMax = 1024
|
|
|
|
|
}
|
|
|
|
|
if params.TcpAllPortRangeMin > params.TcpAllPortRangeMax {
|
|
|
|
|
params.TcpAllPortRangeMin, params.TcpAllPortRangeMax = params.TcpAllPortRangeMax, params.TcpAllPortRangeMin
|
|
|
|
|
}
|
|
|
|
|
globalConfig.TCPAll.DenyPorts = params.TcpAllDenyPorts
|
|
|
|
|
globalConfig.TCPAll.PortRangeMin = params.TcpAllPortRangeMin
|
|
|
|
|
globalConfig.TCPAll.PortRangeMax = params.TcpAllPortRangeMax
|
|
|
|
|
|
2020-10-02 17:22:24 +08:00
|
|
|
// 修改配置
|
2020-11-18 12:17:50 +08:00
|
|
|
globalConfigJSON, err := json.Marshal(globalConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-10-02 17:22:24 +08:00
|
|
|
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
2020-10-31 17:44:48 +08:00
|
|
|
Code: SettingCodeServerGlobalConfig,
|
2020-11-18 12:17:50 +08:00
|
|
|
ValueJSON: globalConfigJSON,
|
2020-10-02 17:22:24 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 10:45:14 +08:00
|
|
|
// 通知更新
|
|
|
|
|
_, err = this.RPC().ServerRPC().NotifyServersChange(this.AdminContext(), &pb.NotifyServersChangeRequest{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 17:22:24 +08:00
|
|
|
this.Success()
|
|
|
|
|
}
|