mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
[域名服务]实现基本的线路配置
This commit is contained in:
@@ -368,6 +368,10 @@ func (this *RPCClient) NSRecordRPC() pb.NSRecordServiceClient {
|
||||
return pb.NewNSRecordServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
func (this *RPCClient) NSRouteRPC() pb.NSRouteServiceClient {
|
||||
return pb.NewNSRouteServiceClient(this.pickConn())
|
||||
}
|
||||
|
||||
// Context 构造Admin上下文
|
||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -34,7 +35,7 @@ func (this *AuthorityTask) Start() {
|
||||
}
|
||||
|
||||
// 初始化的时候先获取一次
|
||||
timeout := time.NewTimer(5 * time.Second)
|
||||
timeout := time.NewTimer(3 * time.Second)
|
||||
<-timeout.C
|
||||
err := this.Loop()
|
||||
if err != nil {
|
||||
@@ -51,6 +52,11 @@ func (this *AuthorityTask) Start() {
|
||||
}
|
||||
|
||||
func (this *AuthorityTask) Loop() error {
|
||||
// 如果还没有安装直接返回
|
||||
if !setup.IsConfigured() {
|
||||
return nil
|
||||
}
|
||||
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/events"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/setup"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
@@ -42,6 +43,11 @@ func (this *SyncAPINodesTask) Start() {
|
||||
}
|
||||
|
||||
func (this *SyncAPINodesTask) Loop() error {
|
||||
// 如果还没有安装直接返回
|
||||
if !setup.IsConfigured() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取所有可用的节点
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 自动同步集群任务
|
||||
// SyncClusterTask 自动同步集群任务
|
||||
type SyncClusterTask struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,18 @@ func (this *CreateNodeAction) RunPost(params struct {
|
||||
this.Fail("请至少添加一个IP地址")
|
||||
}
|
||||
|
||||
// TODO 检查cluster
|
||||
// 检查cluster
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择所在集群")
|
||||
}
|
||||
clusterResp, err := this.RPC().NSClusterRPC().FindEnabledNSCluster(this.AdminContext(), &pb.FindEnabledNSClusterRequest{NsClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if clusterResp.NsCluster == nil {
|
||||
this.Fail("选择的集群不存在")
|
||||
}
|
||||
|
||||
// IP地址
|
||||
ipAddresses := []maps.Map{}
|
||||
|
||||
@@ -113,10 +113,18 @@ func (this *UpdateAction) RunPost(params struct {
|
||||
Field("name", params.Name).
|
||||
Require("请输入节点名称")
|
||||
|
||||
// TODO 检查cluster
|
||||
// 检查cluster
|
||||
if params.ClusterId <= 0 {
|
||||
this.Fail("请选择所在集群")
|
||||
}
|
||||
clusterResp, err := this.RPC().NSClusterRPC().FindEnabledNSCluster(this.AdminContext(), &pb.FindEnabledNSClusterRequest{NsClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if clusterResp.NsCluster == nil {
|
||||
this.Fail("选择的集群不存在")
|
||||
}
|
||||
|
||||
// IP地址
|
||||
ipAddresses := []maps.Map{}
|
||||
@@ -132,7 +140,7 @@ func (this *UpdateAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
// 保存
|
||||
_, err := this.RPC().NSNodeRPC().UpdateNSNode(this.AdminContext(), &pb.UpdateNSNodeRequest{
|
||||
_, err = this.RPC().NSNodeRPC().UpdateNSNode(this.AdminContext(), &pb.UpdateNSNodeRequest{
|
||||
NsNodeId: params.NodeId,
|
||||
Name: params.Name,
|
||||
NsClusterId: params.ClusterId,
|
||||
|
||||
@@ -53,6 +53,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Value string
|
||||
Ttl int32
|
||||
Description string
|
||||
RouteIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
@@ -69,7 +70,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Type: params.Type,
|
||||
Value: params.Value,
|
||||
Ttl: params.Ttl,
|
||||
NsRouteIds: nil, // TODO 等待实现
|
||||
NsRouteIds: params.RouteIds,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -4,6 +4,7 @@ package records
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
@@ -20,7 +21,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
DomainId int64
|
||||
Type string
|
||||
Keyword string
|
||||
RouteId int64 // TODO
|
||||
RouteId int64
|
||||
}) {
|
||||
this.Data["type"] = params.Type
|
||||
this.Data["keyword"] = params.Keyword
|
||||
@@ -92,5 +93,8 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
this.Data["records"] = recordMaps
|
||||
|
||||
// 所有记录类型
|
||||
this.Data["types"] = dnsconfigs.FindAllRecordTypeDefinitions()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
routeIds := []int64{}
|
||||
for _, route := range record.NsRoutes {
|
||||
routeIds = append(routeIds, route.Id)
|
||||
}
|
||||
|
||||
this.Data["record"] = maps.Map{
|
||||
"id": record.Id,
|
||||
"name": record.Name,
|
||||
@@ -40,6 +45,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
"ttl": record.Ttl,
|
||||
"weight": record.Weight,
|
||||
"description": record.Description,
|
||||
"routeIds": routeIds,
|
||||
}
|
||||
|
||||
// 域名信息
|
||||
@@ -74,6 +80,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Value string
|
||||
Ttl int32
|
||||
Description string
|
||||
RouteIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
@@ -87,7 +94,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Type: params.Type,
|
||||
Value: params.Value,
|
||||
Ttl: params.Ttl,
|
||||
NsRouteIds: nil, // TODO 等待实现
|
||||
NsRouteIds: params.RouteIds,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
63
internal/web/actions/default/ns/routes/createPopup.go
Normal file
63
internal/web/actions/default/ns/routes/createPopup.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
}) {
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["domainId"] = params.DomainId
|
||||
this.Data["userId"] = params.UserId
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
|
||||
Name string
|
||||
RangesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
var routeId = int64(0)
|
||||
defer func() {
|
||||
this.CreateLogInfo("创建域名服务线路 %d", routeId)
|
||||
}()
|
||||
|
||||
params.Must.Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
createResp, err := this.RPC().NSRouteRPC().CreateNSRoute(this.AdminContext(), &pb.CreateNSRouteRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
NsDomainId: params.DomainId,
|
||||
UserId: params.UserId,
|
||||
Name: params.Name,
|
||||
RangesJSON: params.RangesJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
routeId = createResp.NsRouteId
|
||||
|
||||
this.Success()
|
||||
}
|
||||
26
internal/web/actions/default/ns/routes/delete.go
Normal file
26
internal/web/actions/default/ns/routes/delete.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
RouteId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("删除域名服务线路 %d", params.RouteId)
|
||||
|
||||
_, err := this.RPC().NSRouteRPC().DeleteNSRoute(this.AdminContext(), &pb.DeleteNSRouteRequest{NsRouteId: params.RouteId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
41
internal/web/actions/default/ns/routes/index.go
Normal file
41
internal/web/actions/default/ns/routes/index.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{
|
||||
NsClusterId: 0,
|
||||
NsDomainId: 0,
|
||||
UserId: 0,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
routeMaps := []maps.Map{}
|
||||
for _, route := range routesResp.NsRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"id": route.Id,
|
||||
"name": route.Name,
|
||||
"isOn": route.IsOn,
|
||||
})
|
||||
}
|
||||
this.Data["routes"] = routeMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
25
internal/web/actions/default/ns/routes/init.go
Normal file
25
internal/web/actions/default/ns/routes/init.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNS)).
|
||||
Data("teaMenu", "ns").
|
||||
Data("teaSubMenu", "route").
|
||||
Prefix("/ns/routes").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/route", new(RouteAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/updatePopup", new(UpdatePopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Post("/sort", new(SortAction)).
|
||||
Post("/options", new(OptionsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
40
internal/web/actions/default/ns/routes/options.go
Normal file
40
internal/web/actions/default/ns/routes/options.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type OptionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *OptionsAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
DomainId int64
|
||||
UserId int64
|
||||
}) {
|
||||
routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{
|
||||
NsClusterId: params.ClusterId,
|
||||
NsDomainId: params.DomainId,
|
||||
UserId: params.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
routeMaps := []maps.Map{}
|
||||
for _, route := range routesResp.NsRoutes {
|
||||
routeMaps = append(routeMaps, maps.Map{
|
||||
"id": route.Id,
|
||||
"name": route.Name,
|
||||
})
|
||||
}
|
||||
this.Data["routes"] = routeMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
17
internal/web/actions/default/ns/routes/route.go
Normal file
17
internal/web/actions/default/ns/routes/route.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
|
||||
type RouteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RouteAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *RouteAction) RunGet(params struct{}) {
|
||||
this.Show()
|
||||
}
|
||||
26
internal/web/actions/default/ns/routes/sort.go
Normal file
26
internal/web/actions/default/ns/routes/sort.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type SortAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SortAction) RunPost(params struct {
|
||||
RouteIds []int64
|
||||
}) {
|
||||
defer this.CreateLogInfo("对线路进行排序")
|
||||
|
||||
_, err := this.RPC().NSRouteRPC().UpdateNSRouteOrders(this.AdminContext(), &pb.UpdateNSRouteOrdersRequest{NsRouteIds: params.RouteIds})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
78
internal/web/actions/default/ns/routes/updatePopup.go
Normal file
78
internal/web/actions/default/ns/routes/updatePopup.go
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package clusters
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
RouteId int64
|
||||
}) {
|
||||
routeResp, err := this.RPC().NSRouteRPC().FindEnabledNSRoute(this.AdminContext(), &pb.FindEnabledNSRouteRequest{NsRouteId: params.RouteId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
route := routeResp.NsRoute
|
||||
if route == nil {
|
||||
this.NotFound("nsRoute", params.RouteId)
|
||||
return
|
||||
}
|
||||
|
||||
rangeMaps := []maps.Map{}
|
||||
if len(route.RangesJSON) > 0 {
|
||||
err = json.Unmarshal([]byte(route.RangesJSON), &rangeMaps)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["route"] = maps.Map{
|
||||
"id": route.Id,
|
||||
"name": route.Name,
|
||||
"isOn": route.IsOn,
|
||||
"ranges": rangeMaps,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
RouteId int64
|
||||
Name string
|
||||
RangesJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改域名线路 %d", params.RouteId)
|
||||
|
||||
params.Must.Field("name", params.Name).
|
||||
Require("请输入线路名称")
|
||||
|
||||
_, err := this.RPC().NSRouteRPC().UpdateNSRoute(this.AdminContext(), &pb.UpdateNSRouteRequest{
|
||||
NsRouteId: params.RouteId,
|
||||
Name: params.Name,
|
||||
RangesJSON: params.RangesJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -230,6 +230,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
|
||||
"url": "/ns/clusters",
|
||||
"code": "cluster",
|
||||
},
|
||||
{
|
||||
"name": "线路管理",
|
||||
"url": "/ns/routes",
|
||||
"code": "route",
|
||||
},
|
||||
{
|
||||
"name": "节点日志",
|
||||
"url": "/ns/clusters/logs",
|
||||
|
||||
@@ -38,8 +38,10 @@ import (
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/cluster"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/cluster/settings"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/logs"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/routes"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/users"
|
||||
|
||||
// 服务相关
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/certs"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components"
|
||||
@@ -95,6 +97,8 @@ import (
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/web"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/websocket"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/stat"
|
||||
|
||||
// 设置相关
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/authority"
|
||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/authority/nodes"
|
||||
|
||||
103
web/public/js/components/ns/ns-route-ranges-box.js
Normal file
103
web/public/js/components/ns/ns-route-ranges-box.js
Normal file
@@ -0,0 +1,103 @@
|
||||
Vue.component("ns-route-ranges-box", {
|
||||
props: ["v-ranges"],
|
||||
data: function () {
|
||||
let ranges = this.vRanges
|
||||
if (ranges == null) {
|
||||
ranges = []
|
||||
}
|
||||
return {
|
||||
ranges: ranges,
|
||||
isAdding: false,
|
||||
|
||||
// IP范围
|
||||
ipRangeFrom: "",
|
||||
ipRangeTo: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
let that = this
|
||||
setTimeout(function () {
|
||||
that.$refs.ipRangeFrom.focus()
|
||||
}, 100)
|
||||
},
|
||||
remove: function (index) {
|
||||
this.ranges.$remove(index)
|
||||
},
|
||||
cancelIPRange: function () {
|
||||
this.isAdding = false
|
||||
this.ipRangeFrom = ""
|
||||
this.ipRangeTo = ""
|
||||
},
|
||||
confirmIPRange: function () {
|
||||
// 校验IP
|
||||
let that = this
|
||||
this.ipRangeFrom = this.ipRangeFrom.trim()
|
||||
if (!this.validateIP(this.ipRangeFrom)) {
|
||||
teaweb.warn("开始IP填写错误", function () {
|
||||
that.$refs.ipRangeFrom.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.ipRangeTo = this.ipRangeTo.trim()
|
||||
if (!this.validateIP(this.ipRangeTo)) {
|
||||
teaweb.warn("结束IP填写错误", function () {
|
||||
that.$refs.ipRangeTo.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.ranges.push({
|
||||
type: "ipRange",
|
||||
ipFrom: this.ipRangeFrom,
|
||||
ipTo: this.ipRangeTo
|
||||
})
|
||||
this.cancelIPRange()
|
||||
},
|
||||
validateIP: function (ip) {
|
||||
if (!ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) {
|
||||
return false
|
||||
}
|
||||
let pieces = ip.split(".")
|
||||
let isOk = true
|
||||
pieces.forEach(function (v) {
|
||||
let v1 = parseInt(v)
|
||||
if (v1 > 255) {
|
||||
isOk = false
|
||||
}
|
||||
})
|
||||
return isOk
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<input type="hidden" name="rangesJSON" :value="JSON.stringify(ranges)"/>
|
||||
<div v-if="ranges.length > 0">
|
||||
<div class="ui label tiny basic" v-for="(range, index) in ranges">
|
||||
<span v-if="range.type == 'ipRange'">IP范围:</span>
|
||||
{{range.ipFrom}} - {{range.ipTo}} <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
|
||||
<!-- IP 范围 -->
|
||||
<div style="margin-bottom: 1em" v-show="isAdding">
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<input type="text" placeholder="开始IP" maxlength="15" size="15" v-model="ipRangeFrom" ref="ipRangeFrom" @keyup.enter="confirmIPRange" @keypress.enter.prevent="1"/>
|
||||
</div>
|
||||
<div class="ui field">-</div>
|
||||
<div class="ui field">
|
||||
<input type="text" placeholder="结束IP" maxlength="15" size="15" v-model="ipRangeTo" ref="ipRangeTo" @keyup.enter="confirmIPRange" @keypress.enter.prevent="1"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button class="ui button tiny" type="button" @click.prevent="confirmIPRange">确定</button>
|
||||
<a href="" @click.prevent="cancelIPRange" title="取消"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
|
||||
</div>`
|
||||
})
|
||||
30
web/public/js/components/ns/ns-route-selector.js
Normal file
30
web/public/js/components/ns/ns-route-selector.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// 选择单一线路
|
||||
Vue.component("ns-route-selector", {
|
||||
props: ["v-route-id"],
|
||||
mounted: function () {
|
||||
let that = this
|
||||
Tea.action("/ns/routes/options")
|
||||
.post()
|
||||
.success(function (resp) {
|
||||
that.routes = resp.data.routes
|
||||
})
|
||||
},
|
||||
data: function () {
|
||||
let routeId = this.vRouteId
|
||||
if (routeId == null) {
|
||||
routeId = 0
|
||||
}
|
||||
return {
|
||||
routeId: routeId,
|
||||
routes: []
|
||||
}
|
||||
},
|
||||
template: `<div>
|
||||
<div v-if="routes.length > 0">
|
||||
<select class="ui dropdown" name="routeId" v-model="routeId">
|
||||
<option value="0">[线路]</option>
|
||||
<option v-for="route in routes" :value="route.id">{{route.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
84
web/public/js/components/ns/ns-routes-selector.js
Normal file
84
web/public/js/components/ns/ns-routes-selector.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// 选择多个线路
|
||||
Vue.component("ns-routes-selector", {
|
||||
props: ["v-route-ids"],
|
||||
mounted: function () {
|
||||
let that = this
|
||||
|
||||
let routeIds = this.vRouteIds
|
||||
if (routeIds == null) {
|
||||
routeIds = []
|
||||
}
|
||||
|
||||
Tea.action("/ns/routes/options")
|
||||
.post()
|
||||
.success(function (resp) {
|
||||
that.allRoutes = resp.data.routes
|
||||
that.allRoutes.forEach(function (v) {
|
||||
v.isChecked = (routeIds.$contains(v.id))
|
||||
})
|
||||
})
|
||||
},
|
||||
data: function () {
|
||||
return {
|
||||
routeId: 0,
|
||||
allRoutes: [],
|
||||
routes: [],
|
||||
isAdding: false
|
||||
}
|
||||
}
|
||||
,
|
||||
methods: {
|
||||
add: function () {
|
||||
this.isAdding = true
|
||||
this.routes = this.allRoutes.$findAll(function (k, v) {
|
||||
return !v.isChecked
|
||||
})
|
||||
this.routeId = 0
|
||||
},
|
||||
cancel: function () {
|
||||
this.isAdding = false
|
||||
},
|
||||
confirm: function () {
|
||||
if (this.routeId == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
let that = this
|
||||
this.routes.forEach(function (v) {
|
||||
if (v.id == that.routeId) {
|
||||
v.isChecked = true
|
||||
}
|
||||
})
|
||||
this.cancel()
|
||||
},
|
||||
remove: function (index) {
|
||||
this.allRoutes[index].isChecked = false
|
||||
Vue.set(this.allRoutes, index, this.allRoutes[index])
|
||||
}
|
||||
}
|
||||
,
|
||||
template: `<div>
|
||||
<div>
|
||||
<div class="ui label basic text small" v-for="(route, index) in allRoutes" v-if="route.isChecked">
|
||||
<input type="hidden" name="routeIds" :value="route.id"/>
|
||||
{{route.name}} <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
<div class="ui divider"></div>
|
||||
</div>
|
||||
<div v-if="isAdding" style="margin-bottom: 1em">
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<select class="ui dropdown" name="routeId" v-model="routeId">
|
||||
<option value="0">[线路]</option>
|
||||
<option v-for="route in routes" :value="route.id">{{route.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
|
||||
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
|
||||
</div>`
|
||||
})
|
||||
@@ -37,6 +37,12 @@
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>线路</td>
|
||||
<td>
|
||||
<ns-routes-selector></ns-routes-selector>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>备注</td>
|
||||
<td>
|
||||
|
||||
@@ -5,6 +5,27 @@
|
||||
<menu-item @click.prevent="createRecord">[创建记录]</menu-item>
|
||||
</second-menu>
|
||||
|
||||
<form class="ui form" method="get" action="/ns/domains/records">
|
||||
<input type="hidden" name="domainId" :value="domain.id"/>
|
||||
<div class="ui fields inline">
|
||||
<div class="ui field">
|
||||
<select class="ui dropdown" name="type" v-model="type">
|
||||
<option value="">[记录类型]</option>
|
||||
<option v-for="t in types" :value="t.type">{{t.type}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<ns-route-selector :v-route-id="routeId"></ns-route-selector>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<input type="text" placeholder="记录名、备注..." name="keyword" v-model="keyword"/>
|
||||
</div>
|
||||
<div class="ui field">
|
||||
<button type="submit" class="ui button">搜索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p class="comment" v-if="records.length == 0">暂时还没有记录。</p>
|
||||
<table class="ui table selectable celled" v-if="records.length > 0">
|
||||
<thead>
|
||||
@@ -24,7 +45,9 @@
|
||||
<td>{{record.value}}</td>
|
||||
<td>{{formatTTL(record.ttl)}}</td>
|
||||
<td>
|
||||
<span class="ui label basic text tiny" v-for="route in record.routes">{{route.name}}</span>
|
||||
<div v-for="route in record.routes" style="margin-top: 0.3em; margin-bottom: 0.3em">
|
||||
<span class="ui label basic text tiny">{{route.name}}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{record.description}}</td>
|
||||
<td>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>创建记录</h3>
|
||||
<h3>修改记录</h3>
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="recordId" :value="record.id"/>
|
||||
@@ -37,6 +37,12 @@
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>线路</td>
|
||||
<td>
|
||||
<ns-routes-selector :v-route-ids="record.routeIds"></ns-routes-selector>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>备注</td>
|
||||
<td>
|
||||
|
||||
4
web/views/@default/ns/routes/@menu.html
Normal file
4
web/views/@default/ns/routes/@menu.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<first-menu>
|
||||
<menu-item href="" @click.prevent="createRoute()">[创建线路]</menu-item>
|
||||
</first-menu>
|
||||
<div class="margin"></div>
|
||||
26
web/views/@default/ns/routes/createPopup.html
Normal file
26
web/views/@default/ns/routes/createPopup.html
Normal file
@@ -0,0 +1,26 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>创建线路</h3>
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="clusterId" :value="clusterId"/>
|
||||
<input type="hidden" name="domainId" :value="domainId"/>
|
||||
<input type="hidden" name="userId" :value="userId"/>
|
||||
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">线路名称 *</td>
|
||||
<td>
|
||||
<input type="text" name="name" maxlength="100" ref="focus"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP范围</td>
|
||||
<td>
|
||||
<ns-route-ranges-box></ns-route-ranges-box>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
34
web/views/@default/ns/routes/index.html
Normal file
34
web/views/@default/ns/routes/index.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{$layout}
|
||||
{$template "menu"}
|
||||
|
||||
<div v-if="routes.length == 0">
|
||||
<p class="comment">暂时还没有线路。</p>
|
||||
</div>
|
||||
|
||||
<div v-show="routes.length > 0">
|
||||
<table class="ui table selectable celled" id="sortable-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 3em"></th>
|
||||
<th>线路名称</th>
|
||||
<th class="two wide">状态</th>
|
||||
<th class="two op">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-for="route in routes" :v-id="route.id">
|
||||
<tr>
|
||||
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
|
||||
<td>{{route.name}}</td>
|
||||
<td>
|
||||
<label-on :v-is-on="route.isOn"></label-on>
|
||||
</td>
|
||||
<td>
|
||||
<a href="" @click.prevent="updateRoute(route.id)">修改</a>
|
||||
<a href="" @click.prevent="deleteRoute(route.id)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="comment" v-if="routes.length > 0">可以拖动左侧的<i class="icon bars"></i>排序。</p>
|
||||
</div>
|
||||
49
web/views/@default/ns/routes/index.js
Normal file
49
web/views/@default/ns/routes/index.js
Normal file
@@ -0,0 +1,49 @@
|
||||
Tea.context(function () {
|
||||
this.$delay(function () {
|
||||
let that = this
|
||||
sortTable(function (ids) {
|
||||
that.$post(".sort")
|
||||
.params({
|
||||
routeIds: ids
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.successToast("排序保存成功")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
this.createRoute = function () {
|
||||
teaweb.popup("/ns/routes/createPopup", {
|
||||
width: "42em",
|
||||
callback: function () {
|
||||
teaweb.success("保存成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.updateRoute = function (routeId) {
|
||||
teaweb.popup("/ns/routes/updatePopup?routeId=" + routeId, {
|
||||
width: "42em",
|
||||
callback: function () {
|
||||
teaweb.success("保存成功", function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.deleteRoute = function (routeId) {
|
||||
let that = this
|
||||
teaweb.confirm("确定要删除此线路吗?", function () {
|
||||
that.$post(".delete")
|
||||
.params({
|
||||
routeId: routeId
|
||||
})
|
||||
.success(function () {
|
||||
teaweb.reload()
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
34
web/views/@default/ns/routes/updatePopup.html
Normal file
34
web/views/@default/ns/routes/updatePopup.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{$layout "layout_popup"}
|
||||
|
||||
<h3>修改线路</h3>
|
||||
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||
<csrf-token></csrf-token>
|
||||
<input type="hidden" name="routeId" :value="route.id"/>
|
||||
<table class="ui table definition selectable">
|
||||
<tr>
|
||||
<td class="title">线路名称 *</td>
|
||||
<td>
|
||||
<input type="text" name="name" maxlength="100" ref="focus" v-model="route.name"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>IP范围</td>
|
||||
<td>
|
||||
<ns-route-ranges-box :v-ranges="route.ranges"></ns-route-ranges-box>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><more-options-indicator></more-options-indicator></td>
|
||||
</tr>
|
||||
<tbody v-show="moreOptionsVisible">
|
||||
<tr>
|
||||
<td>是否启用</td>
|
||||
<td>
|
||||
<checkbox name="isOn" value="1" v-model="route.isOn"></checkbox>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<submit-btn></submit-btn>
|
||||
</form>
|
||||
Reference in New Issue
Block a user