diff --git a/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go b/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go index f2ac2a3d..6cd6fd85 100644 --- a/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go +++ b/internal/web/actions/default/servers/groups/group/servergrouputils/utils.go @@ -107,6 +107,12 @@ func InitGroup(parent *actionutils.ParentAction, groupId int64, menuItem string) "isActive": menuItem == "compression", "isOn": configInfoResp.HasCompressionConfig, }, + { + "name": "特殊页面", + "url": urlPrefix + "/pages?groupId=" + types.String(groupId), + "isActive": menuItem == "pages", + "isOn": configInfoResp.HasPagesConfig, + }, { "name": "HTTP Header", "url": urlPrefix + "/headers?groupId=" + types.String(groupId), diff --git a/internal/web/actions/default/servers/groups/group/settings/pages/index.go b/internal/web/actions/default/servers/groups/group/settings/pages/index.go new file mode 100644 index 00000000..5d3541e5 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/pages/index.go @@ -0,0 +1,73 @@ +package pages + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/actions" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "setting", "index") + this.SecondMenu("pages") +} + +func (this *IndexAction) RunGet(params struct { + GroupId int64 +}) { + _, err := servergrouputils.InitGroup(this.Parent(), params.GroupId, "pages") + if err != nil { + this.ErrorPage(err) + return + } + + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerGroupId(this.AdminContext(), params.GroupId) + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["webId"] = webConfig.Id + this.Data["pages"] = webConfig.Pages + this.Data["shutdownConfig"] = webConfig.Shutdown + + this.Show() +} + +func (this *IndexAction) RunPost(params struct { + WebId int64 + PagesJSON string + ShutdownJSON string + Must *actions.Must +}) { + // 日志 + defer this.CreateLog(oplogs.LevelInfo, "修改Web %d 的设置", params.WebId) + + // TODO 检查配置 + + _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{ + WebId: params.WebId, + PagesJSON: []byte(params.PagesJSON), + }) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{ + WebId: params.WebId, + ShutdownJSON: []byte(params.ShutdownJSON), + }) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/groups/group/settings/pages/init.go b/internal/web/actions/default/servers/groups/group/settings/pages/init.go new file mode 100644 index 00000000..0efcdfb1 --- /dev/null +++ b/internal/web/actions/default/servers/groups/group/settings/pages/init.go @@ -0,0 +1,19 @@ +package pages + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)). + Data("teaMenu", "servers"). + Data("teaSubMenu", "group"). + Prefix("/servers/groups/group/settings/pages"). + GetPost("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/actions/default/servers/server/settings/pages/index.go b/internal/web/actions/default/servers/server/settings/pages/index.go index 5e957866..0ff31b72 100644 --- a/internal/web/actions/default/servers/server/settings/pages/index.go +++ b/internal/web/actions/default/servers/server/settings/pages/index.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/types" ) type IndexAction struct { @@ -20,6 +21,17 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { ServerId int64 }) { + // 分组设置 + groupResp, err := this.RPC().ServerGroupRPC().FindEnabledServerGroupConfigInfo(this.AdminContext(), &pb.FindEnabledServerGroupConfigInfoRequest{ + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["hasGroupConfig"] = groupResp.HasPagesConfig + this.Data["groupSettingURL"] = "/servers/groups/group/settings/pages?groupId=" + types.String(groupResp.ServerGroupId) + webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithServerId(this.AdminContext(), params.ServerId) if err != nil { this.ErrorPage(err) diff --git a/web/views/@default/servers/groups/group/settings/pages/index.html b/web/views/@default/servers/groups/group/settings/pages/index.html new file mode 100644 index 00000000..b7aa814e --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/pages/index.html @@ -0,0 +1,11 @@ +{$layout} +{$template "/servers/groups/group/menu"} +{$template "/left_menu_without_menu"} + +
\ No newline at end of file diff --git a/web/views/@default/servers/groups/group/settings/pages/index.js b/web/views/@default/servers/groups/group/settings/pages/index.js new file mode 100644 index 00000000..295a9aaf --- /dev/null +++ b/web/views/@default/servers/groups/group/settings/pages/index.js @@ -0,0 +1,3 @@ +Tea.context(function () { + this.success = NotifyReloadSuccess("保存成功") +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/pages/index.html b/web/views/@default/servers/server/settings/pages/index.html index ac3c7d7b..2373ef7c 100644 --- a/web/views/@default/servers/server/settings/pages/index.html +++ b/web/views/@default/servers/server/settings/pages/index.html @@ -3,9 +3,16 @@ {$template "/left_menu"}