Skip to content

Commit aef8418

Browse files
committed
优化代码/自动去除域名中的http://和https://等,防止误填
1 parent 04f8bfc commit aef8418

File tree

10 files changed

+65
-30
lines changed

10 files changed

+65
-30
lines changed

internal/web/actions/default/clusters/clusterutils/cluster_helper.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ func (this *ClusterHelper) createSettingMenu(cluster *pb.NodeCluster, info *pb.F
132132
"isActive": false,
133133
})
134134

135-
items = append(items, maps.Map{
136-
"name": "健康检查",
137-
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
138-
"isActive": selectedItem == "health",
139-
"isOn": info != nil && info.HealthCheckIsOn,
140-
})
141-
142135
items = append(items, maps.Map{
143136
"name": "DNS设置",
144137
"url": "/clusters/cluster/settings/dns?clusterId=" + clusterId,
145138
"isActive": selectedItem == "dns",
146139
"isOn": cluster.DnsDomainId > 0 || len(cluster.DnsName) > 0,
147140
})
148141

142+
items = append(items, maps.Map{
143+
"name": "健康检查",
144+
"url": "/clusters/cluster/settings/health?clusterId=" + clusterId,
145+
"isActive": selectedItem == "health",
146+
"isOn": info != nil && info.HealthCheckIsOn,
147+
})
148+
149149
items = append(items, maps.Map{
150150
"name": "DDoS防护",
151151
"url": "/clusters/cluster/settings/ddos-protection?clusterId=" + clusterId,

internal/web/actions/default/servers/addServerNamePopup.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
55
"github.com/iwind/TeaGo/actions"
66
"github.com/iwind/TeaGo/maps"
7+
"net/url"
78
"regexp"
89
"strings"
910
)
@@ -29,26 +30,49 @@ func (this *AddServerNamePopupAction) RunPost(params struct {
2930
Must *actions.Must
3031
}) {
3132
if params.Mode == "single" {
33+
var serverName = params.ServerName
34+
35+
// 去除空格
36+
serverName = regexp.MustCompile(`\s+`).ReplaceAllString(serverName, "")
37+
38+
// 处理URL
39+
if regexp.MustCompile(`^(?i)(http|https|ftp)://`).MatchString(serverName) {
40+
u, err := url.Parse(serverName)
41+
if err == nil && len(u.Host) > 0 {
42+
serverName = u.Host
43+
}
44+
}
45+
3246
params.Must.
33-
Field("serverName", params.ServerName).
47+
Field("serverName", serverName).
3448
Require("请输入域名")
49+
3550
this.Data["serverName"] = maps.Map{
36-
"name": params.ServerName,
51+
"name": serverName,
3752
"type": "full",
3853
}
3954
} else if params.Mode == "multiple" {
4055
if len(params.ServerNames) == 0 {
4156
this.FailField("serverNames", "请输入至少域名")
4257
}
4358

44-
serverNames := []string{}
59+
var serverNames = []string{}
4560
for _, line := range strings.Split(params.ServerNames, "\n") {
46-
line := strings.TrimSpace(line)
47-
line = regexp.MustCompile(`\s+`).ReplaceAllString(line, "")
48-
if len(line) == 0 {
61+
var serverName = strings.TrimSpace(line)
62+
serverName = regexp.MustCompile(`\s+`).ReplaceAllString(serverName, "")
63+
if len(serverName) == 0 {
4964
continue
5065
}
51-
serverNames = append(serverNames, line)
66+
67+
// 处理URL
68+
if regexp.MustCompile(`^(?i)(http|https|ftp)://`).MatchString(serverName) {
69+
u, err := url.Parse(serverName)
70+
if err == nil && len(u.Host) > 0 {
71+
serverName = u.Host
72+
}
73+
}
74+
75+
serverNames = append(serverNames, serverName)
5276
}
5377
this.Data["serverName"] = maps.Map{
5478
"name": "",

internal/web/actions/default/servers/components/cache/batch/index.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ func (this *IndexAction) Init() {
2121
this.Nav("", "", "purge")
2222
}
2323

24-
func (this *IndexAction) RunGet(params struct{}) {
24+
func (this *IndexAction) RunGet(params struct {
25+
KeyType string
26+
}) {
2527
// 初始化菜单数据
2628
err := InitMenu(this.Parent())
2729
if err != nil {
2830
this.ErrorPage(err)
2931
return
3032
}
3133

34+
this.Data["keyType"] = params.KeyType
35+
3236
this.Show()
3337
}
3438

web/public/js/components/plans/plan-bandwidth-ranges.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Vue.component("plan-bandwidth-ranges", {
4444
return -1
4545
}
4646
if (v1.minMB == v2.minMB) {
47+
if (v2.maxMB == 0 || v1.maxMB < v2.maxMB) {
48+
return -1
49+
}
4750
return 0
4851
}
4952
return 1

web/public/js/components/server/reverse-proxy-box.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Vue.component("reverse-proxy-box", {
183183
</td>
184184
</tr>
185185
<tr v-show="family == null || family == 'http'">
186-
<td>回源主机名不包含端口</td>
186+
<td>回源主机名移除端口</td>
187187
<td><checkbox v-model="reverseProxyConfig.requestHostExcludingPort"></checkbox>
188188
<p class="comment">选中后表示移除回源主机名中的端口部分。</p>
189189
</td>

web/views/@default/clusters/cluster/settings/dns/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
<td colspan="2"><more-options-indicator></more-options-indicator></td>
4646
</tr>
4747
<tbody v-show="moreOptionsVisible">
48+
<tr>
49+
<td>允许通过CNAME访问网站服务</td>
50+
<td>
51+
<checkbox name="cnameAsDomain" v-model="cnameAsDomain"></checkbox>
52+
<p class="comment">选中后,表示允许使用CNAME直接访问网站服务;如果取消选中,则表示CNAME只作为DNS解析记录使用。</p>
53+
</td>
54+
</tr>
4855
<tr>
4956
<td>记录TTL</td>
5057
<td>
@@ -54,13 +61,6 @@
5461
</div>
5562
<p class="comment">每个DNS服务商或者账号的TTL限制各有不同,请注意取值范围。0表示使用默认。</p>
5663
</td>
57-
</tr>
58-
<tr>
59-
<td>允许通过CNAME访问网站服务</td>
60-
<td>
61-
<checkbox name="cnameAsDomain" v-model="cnameAsDomain"></checkbox>
62-
<p class="comment">选中后,表示允许使用CNAME直接访问网站服务;如果取消选中,则表示CNAME只作为DNS解析记录使用。</p>
63-
</td>
6464
</tr>
6565
<tr>
6666
<td>是否同步节点DNS状态</td>

web/views/@default/servers/addServerNamePopup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ <h3 v-if="isUpdating">修改域名绑定</h3>
99
<td class="title">单个域名 *</td>
1010
<td>
1111
<input type="text" name="serverName" ref="focus" maxlength="1024" v-model="serverName.name"/>
12-
<p class="comment">请输入单个域名。</p>
12+
<p class="comment">请输入单个域名,域名中<strong>不能</strong>包含<code-label>http</code-label><code-label>https</code-label></p>
1313
</td>
1414
</tr>
1515
<tr v-if="mode == 'multiple'">
1616
<td class="title">多个域名 *</td>
1717
<td>
1818
<textarea name="serverNames" ref="serverNames" v-model="multipleServerNames"></textarea>
19-
<p class="comment">每行一个域名。</p>
19+
<p class="comment">每行一个域名,域名中<strong>不能</strong>包含<code-label>http</code-label><code-label>https</code-label></p>
2020
</td>
2121
</tr>
2222
</table>

web/views/@default/servers/components/cache/batch/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ Tea.context(function () {
2020

2121
this.success = function () {
2222
this.isOk = true
23-
let f = NotifyReloadSuccess("任务提交成功")
24-
f()
23+
let that = this
24+
teaweb.success("任务提交成功", function () {
25+
window.location = window.location.pathname + "?keyType=" + that.keyType
26+
})
2527
}
2628

2729
this.fail = function (resp) {
@@ -39,5 +41,7 @@ Tea.context(function () {
3941
/**
4042
* 操作类型
4143
*/
42-
this.keyType = "key" // key | prefix
44+
if (this.keyType == null || this.keyType.length == 0) {
45+
this.keyType = "key" // key | prefix
46+
}
4347
})

web/views/@default/servers/components/cache/createPopup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h3>创建缓存策略</h3>
4343
<td class="color-border">缓存文件句柄缓存</td>
4444
<td>
4545
<input type="text" name="fileOpenFileCacheMax" maxlength="6" value="0" style="width: 10em"/>
46-
<p class="comment">保持缓存文件句柄,提升缓存文件打开速度,建议数量不超过缓存文件数量的10%</p>
46+
<p class="comment">保持在内存中的缓存文件句柄的数量,提升缓存文件打开速度,建议数量不超过缓存文件数量的十分之一</p>
4747
</td>
4848
</tr>
4949
<tr v-show="teaIsPlus">

web/views/@default/servers/components/cache/update.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<td class="color-border">缓存文件句柄缓存</td>
5353
<td>
5454
<input type="text" name="fileOpenFileCacheMax" v-model="fileOpenFileCacheMax" maxlength="6" value="0" style="width: 10em"/>
55-
<p class="comment">保持缓存文件句柄,提升缓存文件打开速度,建议数量是缓存文件数量的10%</p>
55+
<p class="comment">保持在内存中的缓存文件句柄的数量,提升缓存文件打开速度,建议数量不超过缓存文件数量的十分之一</p>
5656
</td>
5757
</tr>
5858
<tr v-show="teaIsPlus">

0 commit comments

Comments
 (0)