mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-11 18:30:25 +08:00
优化自定义页面设置,页面URL不再支持填写本地文件
This commit is contained in:
@@ -45,7 +45,8 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
case shared.BodyTypeURL:
|
case shared.BodyTypeURL:
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("url", params.URL).
|
Field("url", params.URL).
|
||||||
Require("请输入要显示的URL")
|
Require("请输入要显示的URL").
|
||||||
|
Match( `^(?i)(http|https)://`, "请输入正确的URL")
|
||||||
case shared.BodyTypeHTML:
|
case shared.BodyTypeHTML:
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("body", params.Body).
|
Field("body", params.Body).
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package pages
|
package pages
|
||||||
|
|
||||||
import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -46,18 +51,75 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
|
|
||||||
func (this *IndexAction) RunPost(params struct {
|
func (this *IndexAction) RunPost(params struct {
|
||||||
WebId int64
|
WebId int64
|
||||||
PagesJSON string
|
PagesJSON []byte
|
||||||
ShutdownJSON string
|
ShutdownJSON []byte
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
}) {
|
}) {
|
||||||
// 日志
|
// 日志
|
||||||
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
|
defer this.CreateLogInfo(codes.ServerPage_LogUpdatePages, params.WebId)
|
||||||
|
|
||||||
// TODO 检查配置
|
// 检查配置
|
||||||
|
var urlReg = regexp.MustCompile(`^(?i)(http|https)://`)
|
||||||
|
|
||||||
|
// validate pages
|
||||||
|
if len(params.PagesJSON) > 0 {
|
||||||
|
var pages = []*serverconfigs.HTTPPageConfig{}
|
||||||
|
err := json.Unmarshal(params.PagesJSON, &pages)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, page := range pages {
|
||||||
|
err = page.Init()
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("配置校验失败:" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// check url
|
||||||
|
if page.BodyType == shared.BodyTypeURL && !urlReg.MatchString(page.URL) {
|
||||||
|
this.Fail("自定义页面中 '" + page.URL + "' 不是一个正确的URL,请进行修改")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate shutdown page
|
||||||
|
if len(params.ShutdownJSON) > 0 {
|
||||||
|
var shutdownConfig = &serverconfigs.HTTPShutdownConfig{}
|
||||||
|
err := json.Unmarshal(params.ShutdownJSON, shutdownConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = shutdownConfig.Init()
|
||||||
|
if err != nil {
|
||||||
|
this.Fail("配置校验失败:" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if shutdownConfig.BodyType == shared.BodyTypeURL {
|
||||||
|
if len(shutdownConfig.URL) > 512 {
|
||||||
|
this.Fail("临时关闭页面中URL过长,不能超过512字节")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !urlReg.MatchString(shutdownConfig.URL) {
|
||||||
|
this.Fail("临时关闭页面中 '" + shutdownConfig.URL + "' 不是一个正确的URL,请进行修改")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if shutdownConfig.Body == shared.BodyTypeHTML {
|
||||||
|
if len(shutdownConfig.Body) > 32*1024 {
|
||||||
|
this.Fail("临时关闭页面中HTML内容长度不能超过32K")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebPages(this.AdminContext(), &pb.UpdateHTTPWebPagesRequest{
|
||||||
HttpWebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
PagesJSON: []byte(params.PagesJSON),
|
PagesJSON: params.PagesJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -66,7 +128,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebShutdown(this.AdminContext(), &pb.UpdateHTTPWebShutdownRequest{
|
||||||
HttpWebId: params.WebId,
|
HttpWebId: params.WebId,
|
||||||
ShutdownJSON: []byte(params.ShutdownJSON),
|
ShutdownJSON: params.ShutdownJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
case shared.BodyTypeURL:
|
case shared.BodyTypeURL:
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("url", params.URL).
|
Field("url", params.URL).
|
||||||
Require("请输入要显示的URL")
|
Require("请输入要显示的URL").
|
||||||
|
Match( `^(?i)(http|https)://`, "请输入正确的URL")
|
||||||
case shared.BodyTypeHTML:
|
case shared.BodyTypeHTML:
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("body", params.Body).
|
Field("body", params.Body).
|
||||||
|
|||||||
@@ -114,18 +114,19 @@ Vue.component("http-pages-and-shutdown-box", {
|
|||||||
<prior-checkbox :v-config="shutdownConfig" v-if="vIsLocation"></prior-checkbox>
|
<prior-checkbox :v-config="shutdownConfig" v-if="vIsLocation"></prior-checkbox>
|
||||||
<tbody v-show="!vIsLocation || shutdownConfig.isPrior">
|
<tbody v-show="!vIsLocation || shutdownConfig.isPrior">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="title">开启</td>
|
<td class="title">临时关闭网站</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="ui checkbox">
|
<div class="ui checkbox">
|
||||||
<input type="checkbox" value="1" v-model="shutdownConfig.isOn" />
|
<input type="checkbox" value="1" v-model="shutdownConfig.isOn" />
|
||||||
<label></label>
|
<label></label>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="comment">选中后,表示临时关闭当前网站,并显示自定义内容。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tbody v-show="(!vIsLocation || shutdownConfig.isPrior) && shutdownConfig.isOn">
|
<tbody v-show="(!vIsLocation || shutdownConfig.isPrior) && shutdownConfig.isOn">
|
||||||
<tr>
|
<tr>
|
||||||
<td>内容类型 *</td>
|
<td>显示内容类型 *</td>
|
||||||
<td>
|
<td>
|
||||||
<select class="ui dropdown auto-width" v-model="shutdownConfig.bodyType">
|
<select class="ui dropdown auto-width" v-model="shutdownConfig.bodyType">
|
||||||
<option value="url">读取URL</option>
|
<option value="url">读取URL</option>
|
||||||
@@ -134,14 +135,14 @@ Vue.component("http-pages-and-shutdown-box", {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="shutdownConfig.bodyType == 'url'">
|
<tr v-show="shutdownConfig.bodyType == 'url'">
|
||||||
<td class="title">页面URL *</td>
|
<td class="title">显示页面URL *</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" v-model="shutdownConfig.url" placeholder="页面文件路径或一个完整URL"/>
|
<input type="text" v-model="shutdownConfig.url" placeholder="类似于 https://example.com/page.html"/>
|
||||||
<p class="comment">页面文件是相对于节点安装目录的页面文件比如pages/40x.html,或者一个完整的URL。</p>
|
<p class="comment">将从此URL中读取内容。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="shutdownConfig.bodyType == 'html'">
|
<tr v-show="shutdownConfig.bodyType == 'html'">
|
||||||
<td>HTML *</td>
|
<td>显示页面HTML *</td>
|
||||||
<td>
|
<td>
|
||||||
<textarea name="body" ref="shutdownHTMLBody" v-model="shutdownConfig.body"></textarea>
|
<textarea name="body" ref="shutdownHTMLBody" v-model="shutdownConfig.body"></textarea>
|
||||||
<p class="comment"><a href="" @click.prevent="addShutdownHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
|
<p class="comment"><a href="" @click.prevent="addShutdownHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<td class="title">响应状态码 *</td>
|
<td class="title">响应状态码 *</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="status" size="3" placeholder="状态码" maxlength="3" style="width:5.2em" ref="focus"/>
|
<input type="text" name="status" size="3" placeholder="状态码" maxlength="3" style="width:5.2em" ref="focus"/>
|
||||||
<p class="comment">比如404,或者50x。</p>
|
<p class="comment">匹配的响应状态码,比如404,或者50x。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -18,14 +18,14 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="bodyType == 'url'">
|
<tr v-show="bodyType == 'url'">
|
||||||
<td>URL *</td>
|
<td>显示页面URL *</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="url" maxlength="500" placeholder="页面文件路径或者完整的URL"/>
|
<input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html"/>
|
||||||
<p class="comment">页面文件是相对于节点安装目录的页面文件比如web/pages/40x.html,或者一个完整的URL。</p>
|
<p class="comment">将从此URL中读取内容。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="bodyType == 'html'">
|
<tr v-show="bodyType == 'html'">
|
||||||
<td>HTML *</td>
|
<td>显示页面HTML *</td>
|
||||||
<td>
|
<td>
|
||||||
<textarea name="body" ref="htmlBody"></textarea>
|
<textarea name="body" ref="htmlBody"></textarea>
|
||||||
<p class="comment"><a href="" @click.prevent="addHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
|
<p class="comment"><a href="" @click.prevent="addHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<td class="title">响应状态码 *</td>
|
<td class="title">响应状态码 *</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="status" size="3" placeholder="状态码" maxlength="3" style="width:5.2em" ref="focus" v-model="pageConfig.status"/>
|
<input type="text" name="status" size="3" placeholder="状态码" maxlength="3" style="width:5.2em" ref="focus" v-model="pageConfig.status"/>
|
||||||
<p class="comment">比如404,或者50x。</p>
|
<p class="comment">匹配的响应状态码,比如404,或者50x。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="bodyType == 'url'">
|
<tr v-show="bodyType == 'url'">
|
||||||
<td>URL *</td>
|
<td>显示页面URL *</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="url" maxlength="500" placeholder="页面文件路径或者完整的URL" v-model="pageConfig.url"/>
|
<input type="text" name="url" maxlength="500" placeholder="类似于 https://example.com/page.html" v-model="pageConfig.url"/>
|
||||||
<p class="comment">页面文件是相对于节点安装目录的页面文件比如web/pages/40x.html,或者一个完整的URL。</p>
|
<p class="comment">将从此URL中读取内容。</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-show="bodyType == 'html'">
|
<tr v-show="bodyType == 'html'">
|
||||||
<td>HTML *</td>
|
<td>显示页面HTML *</td>
|
||||||
<td>
|
<td>
|
||||||
<textarea name="body" ref="htmlBody" v-model="pageConfig.body"></textarea>
|
<textarea name="body" ref="htmlBody" v-model="pageConfig.body"></textarea>
|
||||||
<p class="comment"><a href="" @click.prevent="addHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
|
<p class="comment"><a href="" @click.prevent="addHTMLTemplate">[使用模板]</a>。填写页面的HTML内容,支持请求变量。</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user