mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 23:30:26 +08:00
IP名单增加代号管理
This commit is contained in:
@@ -4,6 +4,7 @@ package iplists
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/iplists/iplistutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
@@ -28,6 +29,7 @@ func (this *CreatePopupAction) RunGet(params struct {
|
|||||||
|
|
||||||
func (this *CreatePopupAction) RunPost(params struct {
|
func (this *CreatePopupAction) RunPost(params struct {
|
||||||
Name string
|
Name string
|
||||||
|
Code string
|
||||||
Type string
|
Type string
|
||||||
Description string
|
Description string
|
||||||
IsGlobal bool
|
IsGlobal bool
|
||||||
@@ -44,10 +46,27 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入名称")
|
Require("请输入名称")
|
||||||
|
|
||||||
|
if len(params.Code) > 0 {
|
||||||
|
if !iplistutils.ValidateIPListCode(params.Code) {
|
||||||
|
this.FailField("code", "代号格式错误,只能是英文字母、数字、中划线、下划线的组合")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
listIdResp, err := this.RPC().IPListRPC().FindIPListIdWithCode(this.AdminContext(), &pb.FindIPListIdWithCodeRequest{Code: params.Code})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if listIdResp.IpListId > 0 {
|
||||||
|
this.FailField("code", "代号'"+params.Code+"'已经被别的名单占用,请更换一个")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
createResp, err := this.RPC().IPListRPC().CreateIPList(this.AdminContext(), &pb.CreateIPListRequest{
|
createResp, err := this.RPC().IPListRPC().CreateIPList(this.AdminContext(), &pb.CreateIPListRequest{
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Code: "",
|
Code: params.Code,
|
||||||
TimeoutJSON: nil,
|
TimeoutJSON: nil,
|
||||||
IsPublic: true,
|
IsPublic: true,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package iplistutils
|
||||||
|
|
||||||
|
import "regexp"
|
||||||
|
|
||||||
|
var ipListCodeRegexp = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
|
||||||
|
|
||||||
|
// ValidateIPListCode 校验IP名单代号格式
|
||||||
|
func ValidateIPListCode(code string) bool {
|
||||||
|
return ipListCodeRegexp.MatchString(code)
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ package iplists
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/iplists/iplistutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
@@ -32,6 +33,7 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
func (this *UpdateAction) RunPost(params struct {
|
func (this *UpdateAction) RunPost(params struct {
|
||||||
ListId int64
|
ListId int64
|
||||||
Name string
|
Name string
|
||||||
|
Code string
|
||||||
Type string
|
Type string
|
||||||
Description string
|
Description string
|
||||||
|
|
||||||
@@ -44,10 +46,27 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
Require("请输入名称")
|
Require("请输入名称")
|
||||||
|
|
||||||
|
if len(params.Code) > 0 {
|
||||||
|
if !iplistutils.ValidateIPListCode(params.Code) {
|
||||||
|
this.FailField("code", "代号格式错误,只能是英文字母、数字、中划线、下划线的组合")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
listIdResp, err := this.RPC().IPListRPC().FindIPListIdWithCode(this.AdminContext(), &pb.FindIPListIdWithCodeRequest{Code: params.Code})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if listIdResp.IpListId > 0 && listIdResp.IpListId != params.ListId {
|
||||||
|
this.FailField("code", "代号'"+params.Code+"'已经被别的名单占用,请更换一个")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err := this.RPC().IPListRPC().UpdateIPList(this.AdminContext(), &pb.UpdateIPListRequest{
|
_, err := this.RPC().IPListRPC().UpdateIPList(this.AdminContext(), &pb.UpdateIPListRequest{
|
||||||
IpListId: params.ListId,
|
IpListId: params.ListId,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Code: "",
|
Code: params.Code,
|
||||||
TimeoutJSON: nil,
|
TimeoutJSON: nil,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ func InitIPList(action *actionutils.ParentAction, listId int64) error {
|
|||||||
action.Data["list"] = maps.Map{
|
action.Data["list"] = maps.Map{
|
||||||
"id": list.Id,
|
"id": list.Id,
|
||||||
"name": list.Name,
|
"name": list.Name,
|
||||||
|
"code": list.Code,
|
||||||
"type": list.Type,
|
"type": list.Type,
|
||||||
"typeName": typeName,
|
"typeName": typeName,
|
||||||
"description": list.Description,
|
"description": list.Description,
|
||||||
|
|||||||
@@ -11,6 +11,13 @@
|
|||||||
<input type="text" name="name" maxlength="100" ref="focus"/>
|
<input type="text" name="name" maxlength="100" ref="focus"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>代号</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="code" maxlength="100"/>
|
||||||
|
<p class="comment">可选参数,只能是英文字母、数字、中划线、下划线的组合。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>类型</td>
|
<td>类型</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -8,6 +8,17 @@
|
|||||||
{{list.name}}
|
{{list.name}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>ID</td>
|
||||||
|
<td>{{list.id}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>代号</td>
|
||||||
|
<td>
|
||||||
|
<span v-if="list.code.length > 0">{{list.code}}</span>
|
||||||
|
<span v-else class="disabled">没有设置</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>类型</td>
|
<td>类型</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Tea.context(function () {
|
Tea.context(function () {
|
||||||
this.createList = function () {
|
this.createList = function () {
|
||||||
teaweb.popup(Tea.url(".createPopup", {type: this.type}), {
|
teaweb.popup(Tea.url(".createPopup", {type: this.type}), {
|
||||||
height: "24em",
|
height: "30em",
|
||||||
callback: function (resp) {
|
callback: function (resp) {
|
||||||
teaweb.success("保存成功", function () {
|
teaweb.success("保存成功", function () {
|
||||||
window.location = "/servers/iplists/lists?type=" + resp.data.list.type
|
window.location = "/servers/iplists/lists?type=" + resp.data.list.type
|
||||||
|
|||||||
@@ -11,6 +11,13 @@
|
|||||||
<input type="text" name="name" maxlength="100" ref="focus" v-model="list.name"/>
|
<input type="text" name="name" maxlength="100" ref="focus" v-model="list.name"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>代号</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="code" maxlength="100" v-model="list.code"/>
|
||||||
|
<p class="comment">可选参数,只能是英文字母、数字、中划线、下划线的组合。</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>类型</td>
|
<td>类型</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
Reference in New Issue
Block a user