实现单个服务的带宽限制(商业版)

This commit is contained in:
GoEdgeLab
2021-10-21 17:10:08 +08:00
parent a877a94899
commit 167fac42e3
5 changed files with 111 additions and 0 deletions

View File

@@ -348,6 +348,15 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
"isActive": secondMenuItem == "remoteAddr",
"isOn": serverConfig.Web != nil && serverConfig.Web.RemoteAddr != nil && serverConfig.Web.RemoteAddr.IsOn,
})
if teaconst.IsPlus {
menuItems = append(menuItems, maps.Map{
"name": "带宽限制",
"url": "/servers/server/settings/bandwidth?serverId=" + serverIdString,
"isActive": secondMenuItem == "bandwidth",
"isOn": serverConfig.BandwidthLimit != nil && serverConfig.BandwidthLimit.IsOn,
})
}
} else if serverConfig.IsTCPFamily() {
menuItems = append(menuItems, maps.Map{
"name": "TCP",

View File

@@ -60,6 +60,8 @@ Vue.component("size-capacity-box", {
<option value="kb">KB</option>
<option value="mb">MB</option>
<option value="gb">GB</option>
<option value="tb">TB</option>
<option value="pb">PB</option>
</select>
</div>
</div>`

View File

@@ -0,0 +1,84 @@
Vue.component("bandwidth-limit-config-box", {
props: ["v-bandwidth-limit"],
data: function () {
let config = this.vBandwidthLimit
if (config == null) {
config = {
isOn: false,
dailySize: {
count: -1,
unit: "gb"
},
monthlySize: {
count: -1,
unit: "gb"
},
totalSize: {
count: -1,
unit: "gb"
},
noticePageBody: ""
}
}
return {
config: config
}
},
methods: {
showBodyTemplate: function () {
this.config.noticePageBody = `<!DOCTYPE html>
<html>
<head>
<title>Bandwidth Limit Exceeded Warning</title>
<body>
The site bandwidth has exceeded the limit. Please contact with the site administrator.
</body>
</html>`
}
},
template: `<div>
<input type="hidden" name="bandwidthLimitJSON" :value="JSON.stringify(config)"/>
<table class="ui table selectable definition">
<tbody>
<tr>
<td class="title">是否启用</td>
<td>
<checkbox v-model="config.isOn"></checkbox>
<p class="comment">注意由于带宽统计是每5分钟统计一次所以超出带宽限制后对用户的提醒也会有所延迟。</p>
</td>
</tr>
</tbody>
<tbody v-show="config.isOn">
<tr>
<td>日带宽限制</td>
<td>
<size-capacity-box :v-value="config.dailySize"></size-capacity-box>
</td>
</tr>
<tr>
<td>月带宽限制</td>
<td>
<size-capacity-box :v-value="config.monthlySize"></size-capacity-box>
</td>
</tr>
<!--<tr>
<td>总体限制</td>
<td>
<size-capacity-box :v-value="config.totalSize"></size-capacity-box>
<p class="comment"></p>
</td>
</tr>-->
<tr>
<td>网页提示内容</td>
<td>
<textarea v-model="config.noticePageBody"></textarea>
<p class="comment"><a href="" @click.prevent="showBodyTemplate">[使用模板]</a>。当达到带宽限制时网页显示的HTML内容不填写则显示默认的提示内容。</p>
</td>
</tr>
</tbody>
</table>
<div class="margin"></div>
</div>`
})

View File

@@ -0,0 +1,13 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="serverId" :value="serverId"/>
<csrf-token></csrf-token>
<bandwidth-limit-config-box :v-bandwidth-limit="bandwidthLimitConfig"></bandwidth-limit-config-box>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功")
})