From 9a723da6d49bc7b3bdfd4a8da8dc5a42b9739b38 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 3 May 2024 09:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E2=80=9C=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=87=AA=E5=AE=9A=E4=B9=89=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E2=80=9D=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/configs/db.template.yaml | 2 +- internal/db/models/http_web_dao.go | 18 ++++++++++++++++ internal/db/models/http_web_model.go | 3 +++ internal/rpc/services/service_http_web.go | 25 +++++++++++++++++++++++ internal/setup/sql.json | 6 +++++- 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/build/configs/db.template.yaml b/build/configs/db.template.yaml index 5466c621..6be852d9 100644 --- a/build/configs/db.template.yaml +++ b/build/configs/db.template.yaml @@ -12,5 +12,5 @@ dbs: fields: - bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "retry40X", "autoSystemTuning", "disableDefaultDB", "autoTrimDisks" ] + bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "retry40X", "autoSystemTuning", "disableDefaultDB", "autoTrimDisks","enableGlobalPages" ] diff --git a/internal/db/models/http_web_dao.go b/internal/db/models/http_web_dao.go index e771978c..066d9441 100644 --- a/internal/db/models/http_web_dao.go +++ b/internal/db/models/http_web_dao.go @@ -231,6 +231,8 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, isLocationOrGr } // pages + config.EnableGlobalPages = web.EnableGlobalPages + // TODO 检查forNode参数 if IsNotNull(web.Pages) { var pages = []*serverconfigs.HTTPPageConfig{} @@ -758,6 +760,22 @@ func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte return this.NotifyUpdate(tx, webId) } +// UpdateGlobalPagesEnabled 设置是否启用系统配置的自定义页面 +func (this *HTTPWebDAO) UpdateGlobalPagesEnabled(tx *dbs.Tx, webId int64, isEnabled bool) error { + if webId <= 0 { + return errors.New("invalid webId") + } + err := this.Query(tx). + Pk(webId). + Set(HTTPWebField_EnableGlobalPages, isEnabled). + UpdateQuickly() + if err != nil { + return err + } + + return this.NotifyUpdate(tx, webId) +} + // UpdateWebShutdown 更改Shutdown配置 func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON []byte) error { if webId <= 0 { diff --git a/internal/db/models/http_web_model.go b/internal/db/models/http_web_model.go index 79c1d36a..c4532df3 100644 --- a/internal/db/models/http_web_model.go +++ b/internal/db/models/http_web_model.go @@ -14,6 +14,7 @@ const ( HTTPWebField_Charset dbs.FieldName = "charset" // 字符集 HTTPWebField_Shutdown dbs.FieldName = "shutdown" // 临时关闭页面配置 HTTPWebField_Pages dbs.FieldName = "pages" // 特殊页面 + HTTPWebField_EnableGlobalPages dbs.FieldName = "enableGlobalPages" // 是否启用系统配置的自定义页面 HTTPWebField_RedirectToHttps dbs.FieldName = "redirectToHttps" // 跳转到HTTPS设置 HTTPWebField_Indexes dbs.FieldName = "indexes" // 首页文件列表 HTTPWebField_MaxRequestBodySize dbs.FieldName = "maxRequestBodySize" // 最大允许的请求内容尺寸 @@ -57,6 +58,7 @@ type HTTPWeb struct { Charset dbs.JSON `field:"charset"` // 字符集 Shutdown dbs.JSON `field:"shutdown"` // 临时关闭页面配置 Pages dbs.JSON `field:"pages"` // 特殊页面 + EnableGlobalPages bool `field:"enableGlobalPages"` // 是否启用系统配置的自定义页面 RedirectToHttps dbs.JSON `field:"redirectToHttps"` // 跳转到HTTPS设置 Indexes dbs.JSON `field:"indexes"` // 首页文件列表 MaxRequestBodySize dbs.JSON `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸 @@ -99,6 +101,7 @@ type HTTPWebOperator struct { Charset any // 字符集 Shutdown any // 临时关闭页面配置 Pages any // 特殊页面 + EnableGlobalPages any // 是否启用系统配置的自定义页面 RedirectToHttps any // 跳转到HTTPS设置 Indexes any // 首页文件列表 MaxRequestBodySize any // 最大允许的请求内容尺寸 diff --git a/internal/rpc/services/service_http_web.go b/internal/rpc/services/service_http_web.go index 776af45a..e7e87f95 100644 --- a/internal/rpc/services/service_http_web.go +++ b/internal/rpc/services/service_http_web.go @@ -468,6 +468,31 @@ func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.Upda return this.Success() } +// UpdateHTTPWebGlobalPagesEnabled 更改系统自定义页面启用状态 +func (this *HTTPWebService) UpdateHTTPWebGlobalPagesEnabled(ctx context.Context, req *pb.UpdateHTTPWebGlobalPagesEnabledRequest) (*pb.RPCSuccess, error) { + // 校验请求 + _, userId, err := this.ValidateAdminAndUser(ctx, true) + if err != nil { + return nil, err + } + + if userId > 0 { + // 检查用户权限 + err = models.SharedHTTPWebDAO.CheckUserWeb(nil, userId, req.HttpWebId) + if err != nil { + return nil, err + } + } + + var tx = this.NullTx() + err = models.SharedHTTPWebDAO.UpdateGlobalPagesEnabled(tx, req.HttpWebId, req.IsEnabled) + if err != nil { + return nil, err + } + + return this.Success() +} + // UpdateHTTPWebAccessLog 更改访问日志配置 func (this *HTTPWebService) UpdateHTTPWebAccessLog(ctx context.Context, req *pb.UpdateHTTPWebAccessLogRequest) (*pb.RPCSuccess, error) { // 校验请求 diff --git a/internal/setup/sql.json b/internal/setup/sql.json index aa9d7302..ad28e036 100644 --- a/internal/setup/sql.json +++ b/internal/setup/sql.json @@ -103496,7 +103496,7 @@ "name": "edgeHTTPWebs", "engine": "InnoDB", "charset": "utf8mb4_general_ci", - "definition": "CREATE TABLE `edgeHTTPWebs` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `root` json DEFAULT NULL COMMENT '根目录',\n `charset` json DEFAULT NULL COMMENT '字符集',\n `shutdown` json DEFAULT NULL COMMENT '临时关闭页面配置',\n `pages` json DEFAULT NULL COMMENT '特殊页面',\n `redirectToHttps` json DEFAULT NULL COMMENT '跳转到HTTPS设置',\n `indexes` json DEFAULT NULL COMMENT '首页文件列表',\n `maxRequestBodySize` json DEFAULT NULL COMMENT '最大允许的请求内容尺寸',\n `requestHeader` json DEFAULT NULL COMMENT '请求Header配置',\n `responseHeader` json DEFAULT NULL COMMENT '响应Header配置',\n `accessLog` json DEFAULT NULL COMMENT '访问日志配置',\n `stat` json DEFAULT NULL COMMENT '统计配置',\n `gzip` json DEFAULT NULL COMMENT 'Gzip配置(v0.3.2弃用)',\n `compression` json DEFAULT NULL COMMENT '压缩配置',\n `cache` json DEFAULT NULL COMMENT '缓存配置',\n `firewall` json DEFAULT NULL COMMENT '防火墙设置',\n `locations` json DEFAULT NULL COMMENT '路由规则配置',\n `websocket` json DEFAULT NULL COMMENT 'Websocket设置',\n `rewriteRules` json DEFAULT NULL COMMENT '重写规则配置',\n `hostRedirects` json DEFAULT NULL COMMENT '域名跳转',\n `fastcgi` json DEFAULT NULL COMMENT 'Fastcgi配置',\n `auth` json DEFAULT NULL COMMENT '认证策略配置',\n `webp` json DEFAULT NULL COMMENT 'WebP配置',\n `remoteAddr` json DEFAULT NULL COMMENT '客户端IP配置',\n `mergeSlashes` tinyint(1) unsigned DEFAULT '0' COMMENT '是否合并路径中的斜杠',\n `requestLimit` json DEFAULT NULL COMMENT '请求限制',\n `requestScripts` json DEFAULT NULL COMMENT '请求脚本',\n `uam` json DEFAULT NULL COMMENT 'UAM设置',\n `cc` json DEFAULT NULL COMMENT 'CC设置',\n `referers` json DEFAULT NULL COMMENT '防盗链设置',\n `userAgent` json DEFAULT NULL COMMENT 'UserAgent设置',\n `optimization` json DEFAULT NULL COMMENT '页面优化配置',\n `hls` json DEFAULT NULL COMMENT 'HLS设置',\n PRIMARY KEY (`id`),\n KEY `userId` (`userId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='HTTP Web'", + "definition": "CREATE TABLE `edgeHTTPWebs` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `isOn` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用',\n `templateId` int(11) unsigned DEFAULT '0' COMMENT '模版ID',\n `adminId` int(11) unsigned DEFAULT '0' COMMENT '管理员ID',\n `userId` int(11) unsigned DEFAULT '0' COMMENT '用户ID',\n `state` tinyint(1) unsigned DEFAULT '1' COMMENT '状态',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n `root` json DEFAULT NULL COMMENT '根目录',\n `charset` json DEFAULT NULL COMMENT '字符集',\n `shutdown` json DEFAULT NULL COMMENT '临时关闭页面配置',\n `pages` json DEFAULT NULL COMMENT '特殊页面',\n `enableGlobalPages` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用系统配置的自定义页面',\n `redirectToHttps` json DEFAULT NULL COMMENT '跳转到HTTPS设置',\n `indexes` json DEFAULT NULL COMMENT '首页文件列表',\n `maxRequestBodySize` json DEFAULT NULL COMMENT '最大允许的请求内容尺寸',\n `requestHeader` json DEFAULT NULL COMMENT '请求Header配置',\n `responseHeader` json DEFAULT NULL COMMENT '响应Header配置',\n `accessLog` json DEFAULT NULL COMMENT '访问日志配置',\n `stat` json DEFAULT NULL COMMENT '统计配置',\n `gzip` json DEFAULT NULL COMMENT 'Gzip配置(v0.3.2弃用)',\n `compression` json DEFAULT NULL COMMENT '压缩配置',\n `cache` json DEFAULT NULL COMMENT '缓存配置',\n `firewall` json DEFAULT NULL COMMENT '防火墙设置',\n `locations` json DEFAULT NULL COMMENT '路由规则配置',\n `websocket` json DEFAULT NULL COMMENT 'Websocket设置',\n `rewriteRules` json DEFAULT NULL COMMENT '重写规则配置',\n `hostRedirects` json DEFAULT NULL COMMENT '域名跳转',\n `fastcgi` json DEFAULT NULL COMMENT 'Fastcgi配置',\n `auth` json DEFAULT NULL COMMENT '认证策略配置',\n `webp` json DEFAULT NULL COMMENT 'WebP配置',\n `remoteAddr` json DEFAULT NULL COMMENT '客户端IP配置',\n `mergeSlashes` tinyint(1) unsigned DEFAULT '0' COMMENT '是否合并路径中的斜杠',\n `requestLimit` json DEFAULT NULL COMMENT '请求限制',\n `requestScripts` json DEFAULT NULL COMMENT '请求脚本',\n `uam` json DEFAULT NULL COMMENT 'UAM设置',\n `cc` json DEFAULT NULL COMMENT 'CC设置',\n `referers` json DEFAULT NULL COMMENT '防盗链设置',\n `userAgent` json DEFAULT NULL COMMENT 'UserAgent设置',\n `optimization` json DEFAULT NULL COMMENT '页面优化配置',\n `hls` json DEFAULT NULL COMMENT 'HLS设置',\n PRIMARY KEY (`id`),\n KEY `userId` (`userId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='HTTP Web'", "fields": [ { "name": "id", @@ -103542,6 +103542,10 @@ "name": "pages", "definition": "json COMMENT '特殊页面'" }, + { + "name": "enableGlobalPages", + "definition": "tinyint(1) unsigned DEFAULT '1' COMMENT '是否启用系统配置的自定义页面'" + }, { "name": "redirectToHttps", "definition": "json COMMENT '跳转到HTTPS设置'"