2020-11-22 15:34:13 +08:00
|
|
|
package server
|
2020-10-15 16:41:32 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
"net"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UpdateHTTPPopupAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *UpdateHTTPPopupAction) Init() {
|
|
|
|
|
this.Nav("", "", "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *UpdateHTTPPopupAction) RunGet(params struct{}) {
|
|
|
|
|
serverConfig, err := loadServerConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.Data["serverConfig"] = serverConfig
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *UpdateHTTPPopupAction) RunPost(params struct {
|
|
|
|
|
IsOn bool
|
|
|
|
|
Listens []string
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
}) {
|
2020-11-20 15:32:42 +08:00
|
|
|
defer this.CreateLogInfo("修改管理界面的HTTP设置")
|
|
|
|
|
|
2020-10-15 16:41:32 +08:00
|
|
|
if len(params.Listens) == 0 {
|
|
|
|
|
this.Fail("请输入绑定地址")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverConfig, err := loadServerConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("保存失败:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serverConfig.Http.On = params.IsOn
|
|
|
|
|
|
|
|
|
|
listen := []string{}
|
|
|
|
|
for _, addr := range params.Listens {
|
|
|
|
|
addr = utils.FormatAddress(addr)
|
|
|
|
|
if len(addr) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if _, _, err := net.SplitHostPort(addr); err != nil {
|
|
|
|
|
addr += ":80"
|
|
|
|
|
}
|
|
|
|
|
listen = append(listen, addr)
|
|
|
|
|
}
|
|
|
|
|
serverConfig.Http.Listen = listen
|
|
|
|
|
|
|
|
|
|
err = writeServerConfig(serverConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("保存失败:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|