管理端全部功能跑通
This commit is contained in:
@@ -5,8 +5,9 @@ import (
|
||||
|
||||
"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/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type AppSettingsAction struct {
|
||||
@@ -22,33 +23,45 @@ func (this *AppSettingsAction) RunGet(params struct {
|
||||
Section string
|
||||
}) {
|
||||
httpdnsutils.AddLeftMenu(this.Parent())
|
||||
app := pickApp(params.AppId)
|
||||
|
||||
// 顶部 tabbar
|
||||
httpdnsutils.AddAppTabbar(this.Parent(), app.GetString("name"), params.AppId, "settings")
|
||||
app, err := findAppMap(this.Parent(), params.AppId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
httpdnsutils.AddAppTabbar(this.Parent(), app.GetString("name"), app.GetInt64("id"), "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{}{
|
||||
|
||||
appIDStr := strconv.FormatInt(app.GetInt64("id"), 10)
|
||||
this.Data["leftMenuItems"] = []maps.Map{
|
||||
{
|
||||
"name": "基础配置",
|
||||
"url": "/httpdns/apps/app/settings?appId=" + appIdStr + "§ion=basic",
|
||||
"url": "/httpdns/apps/app/settings?appId=" + appIDStr + "§ion=basic",
|
||||
"isActive": section == "basic",
|
||||
},
|
||||
{
|
||||
"name": "认证与密钥",
|
||||
"url": "/httpdns/apps/app/settings?appId=" + appIdStr + "§ion=auth",
|
||||
"url": "/httpdns/apps/app/settings?appId=" + appIDStr + "§ion=auth",
|
||||
"isActive": section == "auth",
|
||||
},
|
||||
}
|
||||
|
||||
settings := loadAppSettings(app)
|
||||
this.Data["clusters"] = policies.LoadAvailableDeployClusters()
|
||||
settings := maps.Map{
|
||||
"appId": app.GetString("appId"),
|
||||
"appStatus": app.GetBool("isOn"),
|
||||
"primaryClusterId": app.GetInt64("primaryClusterId"),
|
||||
"backupClusterId": app.GetInt64("backupClusterId"),
|
||||
"signEnabled": app.GetBool("signEnabled"),
|
||||
"signSecretPlain": app.GetString("signSecretPlain"),
|
||||
"signSecretMasked": app.GetString("signSecretMasked"),
|
||||
"signSecretUpdatedAt": app.GetString("signSecretUpdated"),
|
||||
}
|
||||
this.Data["app"] = app
|
||||
this.Data["settings"] = settings
|
||||
this.Show()
|
||||
@@ -57,36 +70,37 @@ func (this *AppSettingsAction) RunGet(params struct {
|
||||
func (this *AppSettingsAction) RunPost(params struct {
|
||||
AppId int64
|
||||
|
||||
AppStatus bool
|
||||
PrimaryClusterId int64
|
||||
BackupClusterId int64
|
||||
AppStatus bool
|
||||
|
||||
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")
|
||||
params.Must.Field("appId", params.AppId).Gt(0, "请选择应用")
|
||||
|
||||
appResp, err := this.RPC().HTTPDNSAppRPC().FindHTTPDNSApp(this.AdminContext(), &pb.FindHTTPDNSAppRequest{
|
||||
AppDbId: params.AppId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if appResp.GetApp() == nil {
|
||||
this.Fail("找不到对应的应用")
|
||||
return
|
||||
}
|
||||
|
||||
app := pickApp(params.AppId)
|
||||
settings := loadAppSettings(app)
|
||||
settings["appStatus"] = params.AppStatus
|
||||
settings["primaryClusterId"] = params.PrimaryClusterId
|
||||
settings["backupClusterId"] = params.BackupClusterId
|
||||
_, err = this.RPC().HTTPDNSAppRPC().UpdateHTTPDNSApp(this.AdminContext(), &pb.UpdateHTTPDNSAppRequest{
|
||||
AppDbId: params.AppId,
|
||||
Name: appResp.GetApp().GetName(),
|
||||
PrimaryClusterId: appResp.GetApp().GetPrimaryClusterId(),
|
||||
BackupClusterId: appResp.GetApp().GetBackupClusterId(),
|
||||
IsOn: params.AppStatus,
|
||||
UserId: appResp.GetApp().GetUserId(),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user