93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package apps
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/policies"
|
|
"github.com/iwind/TeaGo/actions"
|
|
)
|
|
|
|
type AppSettingsAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *AppSettingsAction) Init() {
|
|
this.Nav("httpdns", "app", "settings")
|
|
}
|
|
|
|
func (this *AppSettingsAction) RunGet(params struct {
|
|
AppId int64
|
|
Section string
|
|
}) {
|
|
httpdnsutils.AddLeftMenu(this.Parent())
|
|
app := pickApp(params.AppId)
|
|
|
|
// 顶部 tabbar
|
|
httpdnsutils.AddAppTabbar(this.Parent(), app.GetString("name"), params.AppId, "settings")
|
|
|
|
// 当前选中的 section
|
|
section := params.Section
|
|
if len(section) == 0 {
|
|
section = "basic"
|
|
}
|
|
this.Data["activeSection"] = section
|
|
appIdStr := strconv.FormatInt(params.AppId, 10)
|
|
this.Data["leftMenuItems"] = []map[string]interface{}{
|
|
{
|
|
"name": "基础配置",
|
|
"url": "/httpdns/apps/app/settings?appId=" + appIdStr + "§ion=basic",
|
|
"isActive": section == "basic",
|
|
},
|
|
{
|
|
"name": "认证与密钥",
|
|
"url": "/httpdns/apps/app/settings?appId=" + appIdStr + "§ion=auth",
|
|
"isActive": section == "auth",
|
|
},
|
|
}
|
|
|
|
settings := loadAppSettings(app)
|
|
this.Data["clusters"] = policies.LoadAvailableDeployClusters()
|
|
this.Data["app"] = app
|
|
this.Data["settings"] = settings
|
|
this.Show()
|
|
}
|
|
|
|
func (this *AppSettingsAction) RunPost(params struct {
|
|
AppId int64
|
|
|
|
AppStatus bool
|
|
PrimaryClusterId int64
|
|
BackupClusterId int64
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
params.Must.Field("appId", params.AppId).Gt(0, "please select app")
|
|
params.Must.Field("primaryClusterId", params.PrimaryClusterId).Gt(0, "please select primary cluster")
|
|
if params.BackupClusterId > 0 && params.BackupClusterId == params.PrimaryClusterId {
|
|
this.FailField("backupClusterId", "backup cluster must be different from primary cluster")
|
|
}
|
|
|
|
app := pickApp(params.AppId)
|
|
settings := loadAppSettings(app)
|
|
settings["appStatus"] = params.AppStatus
|
|
settings["primaryClusterId"] = params.PrimaryClusterId
|
|
settings["backupClusterId"] = params.BackupClusterId
|
|
|
|
// SNI strategy is fixed to level2 empty.
|
|
settings["sniPolicy"] = "level2"
|
|
settings["level2Mode"] = "empty"
|
|
settings["publicSniDomain"] = ""
|
|
settings["echFallbackPolicy"] = "level2"
|
|
settings["ecsMode"] = "off"
|
|
settings["ecsIPv4Prefix"] = 24
|
|
settings["ecsIPv6Prefix"] = 56
|
|
settings["pinningMode"] = "off"
|
|
settings["sanMode"] = "off"
|
|
|
|
saveAppSettings(app.GetInt64("id"), settings)
|
|
this.Success()
|
|
}
|