mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-03-09 21:15:36 +08:00
提供管理界面的HTTP/HTTPS修改功能
This commit is contained in:
65
internal/web/actions/default/settings/ui/updateHTTPPopup.go
Normal file
65
internal/web/actions/default/settings/ui/updateHTTPPopup.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package ui
|
||||
|
||||
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
|
||||
}) {
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user