增加独立的IP地址管理功能

This commit is contained in:
GoEdgeLab
2021-08-31 17:24:30 +08:00
parent 06d7f8d754
commit 31aa942c0f
31 changed files with 822 additions and 50 deletions

View File

@@ -99,6 +99,10 @@ func (this *RPCClient) NodeIPAddressRPC() pb.NodeIPAddressServiceClient {
return pb.NewNodeIPAddressServiceClient(this.pickConn())
}
func (this *RPCClient) NodeIPAddressLogRPC() pb.NodeIPAddressLogServiceClient {
return pb.NewNodeIPAddressLogServiceClient(this.pickConn())
}
func (this *RPCClient) NodeValueRPC() pb.NodeValueServiceClient {
return pb.NewNodeValueServiceClient(this.pickConn())
}

View File

@@ -171,7 +171,7 @@ func (this *CreateNodeAction) RunPost(params struct {
addressId := address.GetInt64("id")
if addressId > 0 {
_, err = this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressNodeId(this.AdminContext(), &pb.UpdateNodeIPAddressNodeIdRequest{
AddressId: addressId,
NodeIPAddressId: addressId,
NodeId: nodeId,
})
} else {

View File

@@ -0,0 +1,26 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package addr
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 {
AddrId int64
}) {
defer this.CreateLogInfo("删除IP地址 %d", params.AddrId)
_, err := this.RPC().NodeIPAddressRPC().DisableNodeIPAddress(this.AdminContext(), &pb.DisableNodeIPAddressRequest{NodeIPAddressId: params.AddrId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,66 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package addr
import (
"encoding/json"
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "addr")
}
func (this *IndexAction) RunGet(params struct {
AddrId int64
}) {
addr, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
if err != nil {
this.ErrorPage(err)
return
}
var thresholds = []*nodeconfigs.NodeValueThresholdConfig{}
if len(addr.ThresholdsJSON) > 0 {
err = json.Unmarshal(addr.ThresholdsJSON, &thresholds)
if err != nil {
this.ErrorPage(err)
return
}
}
nodeResp, err := this.RPC().NodeRPC().FindEnabledBasicNode(this.AdminContext(), &pb.FindEnabledBasicNodeRequest{NodeId: addr.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
var node = nodeResp.Node
if node == nil || node.NodeCluster == nil {
this.ErrorPage(errors.New("node or cluster is not available"))
return
}
this.Data["addr"] = maps.Map{
"id": addr.Id,
"name": addr.Name,
"description": addr.Description,
"ip": addr.Ip,
"canAccess": addr.CanAccess,
"isOn": addr.IsOn,
"isUp": addr.IsUp,
"thresholds": thresholds,
"node": maps.Map{"id": node.Id, "name": node.Name},
"cluster": maps.Map{"id": node.NodeCluster.Id, "name": node.NodeCluster.Name},
}
this.Show()
}

View File

@@ -0,0 +1,75 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package addr
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type LogsAction struct {
actionutils.ParentAction
}
func (this *LogsAction) Init() {
this.Nav("", "", "log")
}
func (this *LogsAction) RunGet(params struct {
AddrId int64
}) {
_, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
if err != nil {
this.ErrorPage(err)
return
}
countResp, err := this.RPC().NodeIPAddressLogRPC().CountAllNodeIPAddressLogs(this.AdminContext(), &pb.CountAllNodeIPAddressLogsRequest{NodeIPAddressId: params.AddrId})
if err != nil {
this.ErrorPage(err)
return
}
var page = this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
logsResp, err := this.RPC().NodeIPAddressLogRPC().ListNodeIPAddressLogs(this.AdminContext(), &pb.ListNodeIPAddressLogsRequest{
NodeIPAddressId: params.AddrId,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var logMaps = []maps.Map{}
for _, log := range logsResp.NodeIPAddressLogs {
var adminMap maps.Map
if log.Admin != nil {
adminMap = maps.Map{
"id": log.Admin.Id,
"name": log.Admin.Fullname,
}
} else {
adminMap = maps.Map{
"id": 0,
"name": "[系统]",
}
}
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"description": log.Description,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"isUp": log.IsUp,
"isOn": log.IsOn,
"canAccess": log.CanAccess,
"admin": adminMap,
})
}
this.Data["logs"] = logMaps
this.Show()
}

View File

@@ -0,0 +1,92 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package addr
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net"
)
type UpdateAction struct {
actionutils.ParentAction
}
func (this *UpdateAction) Init() {
this.Nav("", "", "update")
}
func (this *UpdateAction) RunGet(params struct {
AddrId int64
}) {
addr, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
if err != nil {
this.ErrorPage(err)
return
}
var thresholds = []*nodeconfigs.NodeValueThresholdConfig{}
if len(addr.ThresholdsJSON) > 0 {
err = json.Unmarshal(addr.ThresholdsJSON, &thresholds)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["supportThresholds"] = true
this.Data["addr"] = maps.Map{
"id": addr.Id,
"name": addr.Name,
"description": addr.Description,
"ip": addr.Ip,
"canAccess": addr.CanAccess,
"isOn": addr.IsOn,
"isUp": addr.IsUp,
"thresholds": thresholds,
}
this.Show()
}
func (this *UpdateAction) RunPost(params struct {
AddrId int64
IP string `alias:"ip"`
Name string
CanAccess bool
IsOn bool
ThresholdsJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
}) {
params.Must.
Field("ip", params.IP).
Require("请输入IP地址")
ip := net.ParseIP(params.IP)
if len(ip) == 0 {
this.Fail("请输入正确的IP")
}
_, err := this.RPC().NodeIPAddressRPC().UpdateNodeIPAddress(this.AdminContext(), &pb.UpdateNodeIPAddressRequest{
NodeIPAddressId: params.AddrId,
Name: params.Name,
Ip: params.IP,
CanAccess: params.CanAccess,
IsOn: params.IsOn,
ThresholdsJSON: params.ThresholdsJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,94 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package ipaddrs
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"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 {
ClusterId int64
UpState int8
Keyword string
}) {
this.Data["clusterId"] = params.ClusterId
this.Data["upState"] = params.UpState
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().NodeIPAddressRPC().CountAllEnabledIPAddresses(this.AdminContext(), &pb.CountAllEnabledIPAddressesRequest{
NodeClusterId: params.ClusterId,
Role: nodeconfigs.NodeRoleNode,
UpState: int32(params.UpState),
Keyword: params.Keyword,
})
if err != nil {
this.ErrorPage(err)
return
}
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
addrsResp, err := this.RPC().NodeIPAddressRPC().ListEnabledIPAddresses(this.AdminContext(), &pb.ListEnabledIPAddressesRequest{
NodeClusterId: params.ClusterId,
Role: nodeconfigs.NodeRoleNode,
UpState: int32(params.UpState),
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var addrMaps = []maps.Map{}
for _, addr := range addrsResp.NodeIPAddresses {
var thresholds = []*nodeconfigs.NodeValueThresholdConfig{}
if len(addr.ThresholdsJSON) > 0 {
err = json.Unmarshal(addr.ThresholdsJSON, &thresholds)
if err != nil {
this.ErrorPage(err)
return
}
}
nodeResp, err := this.RPC().NodeRPC().FindEnabledBasicNode(this.AdminContext(), &pb.FindEnabledBasicNodeRequest{NodeId: addr.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
var node = nodeResp.Node
if node == nil || node.NodeCluster == nil {
continue
}
addrMaps = append(addrMaps, maps.Map{
"id": addr.Id,
"name": addr.Name,
"description": addr.Description,
"ip": addr.Ip,
"canAccess": addr.CanAccess,
"isOn": addr.IsOn,
"isUp": addr.IsUp,
"hasThresholds": len(thresholds) > 0,
"node": maps.Map{"id": node.Id, "name": node.Name},
"cluster": maps.Map{"id": node.NodeCluster.Id, "name": node.NodeCluster.Name},
})
}
this.Data["addrs"] = addrMaps
this.Show()
}

View File

@@ -0,0 +1,28 @@
package ipaddrs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/addr"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
Helper(clusterutils.NewClustersHelper()).
Data("teaSubMenu", "ipAddr").
Prefix("/clusters/ip-addrs").
Get("", new(IndexAction)).
Get("/logs", new(LogsAction)).
// 单个地址操作
Post("/addr/delete", new(addr.DeleteAction)).
Get("/addr", new(addr.IndexAction)).
GetPost("/addr/update", new(addr.UpdateAction)).
Get("/addr/logs", new(addr.LogsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,30 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package ipaddrutils
import (
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
func InitIPAddr(parent *actionutils.ParentAction, addrId int64) (*pb.NodeIPAddress, error) {
addrResp, err := parent.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(parent.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{NodeIPAddressId: addrId})
if err != nil {
return nil, err
}
var addr = addrResp.NodeIPAddress
if addr == nil {
return nil, errors.New("nodeIPAddress with id '" + types.String(addrId) + "' not found")
}
parent.Data["addr"] = maps.Map{
"id": addr.Id,
"name": addr.Name,
"ip": addr.Ip,
}
return addr, nil
}

View File

@@ -0,0 +1,78 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package ipaddrs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type LogsAction struct {
actionutils.ParentAction
}
func (this *LogsAction) Init() {
this.Nav("", "", "log")
}
func (this *LogsAction) RunGet(params struct {
}) {
countResp, err := this.RPC().NodeIPAddressLogRPC().CountAllNodeIPAddressLogs(this.AdminContext(), &pb.CountAllNodeIPAddressLogsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var page = this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
logsResp, err := this.RPC().NodeIPAddressLogRPC().ListNodeIPAddressLogs(this.AdminContext(), &pb.ListNodeIPAddressLogsRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var logMaps = []maps.Map{}
for _, log := range logsResp.NodeIPAddressLogs {
var adminMap maps.Map
if log.Admin != nil {
adminMap = maps.Map{
"id": log.Admin.Id,
"name": log.Admin.Fullname,
}
} else {
adminMap = maps.Map{
"id": 0,
"name": "[系统]",
}
}
var addrMap maps.Map
if log.NodeIPAddress != nil {
var addr = log.NodeIPAddress
if addr != nil {
addrMap = maps.Map{
"id": addr.Id,
"ip": addr.Ip,
}
}
}
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"description": log.Description,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"isUp": log.IsUp,
"isOn": log.IsOn,
"canAccess": log.CanAccess,
"admin": adminMap,
"addr": addrMap,
})
}
this.Data["logs"] = logMaps
this.Show()
}

View File

@@ -18,7 +18,10 @@ func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
func (this *CreatePopupAction) RunGet(params struct {
SupportThresholds bool
}) {
this.Data["supportThresholds"] = params.SupportThresholds
this.Show()
}

View File

@@ -32,7 +32,7 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64,
}
_, err = parentAction.RPC().NodeIPAddressRPC().UpdateNodeIPAddress(parentAction.AdminContext(), &pb.UpdateNodeIPAddressRequest{
AddressId: addrId,
NodeIPAddressId: addrId,
Ip: addr.GetString("ip"),
Name: addr.GetString("name"),
CanAccess: addr.GetBool("canAccess"),

View File

@@ -21,7 +21,10 @@ func (this *UpdatePopupAction) Init() {
func (this *UpdatePopupAction) RunGet(params struct {
AddressId int64
SupportThresholds bool
}) {
this.Data["supportThresholds"] = params.SupportThresholds
this.Show()
}
@@ -42,12 +45,12 @@ func (this *UpdatePopupAction) RunPost(params struct {
// 获取IP地址信息
var isUp = true
if params.AddressId > 0 {
addressResp, err := this.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(this.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{AddressId: params.AddressId})
addressResp, err := this.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(this.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{NodeIPAddressId: params.AddressId})
if err != nil {
this.ErrorPage(err)
return
}
var address = addressResp.IpAddress
var address = addressResp.NodeIPAddress
if address == nil {
this.Fail("找不到要修改的地址")
}

View File

@@ -83,7 +83,7 @@ func (this *CreateNodeAction) RunPost(params struct {
addressId := address.GetInt64("id")
if addressId > 0 {
_, err = this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressNodeId(this.AdminContext(), &pb.UpdateNodeIPAddressNodeIdRequest{
AddressId: addressId,
NodeIPAddressId: addressId,
NodeId: nodeId,
})
} else {

View File

@@ -240,13 +240,13 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map {
"url": "/clusters/logs",
"code": "log",
},
/**{
"name": "IP资源",
{
"name": "IP地址",
"url": "/clusters/ip-addrs",
"code": "ipAddr",
"isOn": teaconst.IsPlus,
},
{
/**{
"name": "监控",
"url": "/clusters/monitors",
"code": "monitor",

View File

@@ -6,11 +6,6 @@ import (
// 系统用户
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins/recipients"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins/recipients/groups"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins/recipients/instances"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins/recipients/logs"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/admins/recipients/tasks"
// API节点
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/api"
@@ -41,23 +36,8 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ui"
// 域名服务
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/accessLogs"
_ "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/cluster/settings/accessLog"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/clusters/cluster/settings/recursion"
_ "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/settings/accesslogs"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/ns/test"
_ "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/accesslogs"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/certs"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache"
@@ -68,7 +48,6 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/metrics/charts"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/boards"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/delete"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/log"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings"

View File

@@ -1,5 +1,6 @@
// 单个集群选择
Vue.component("cluster-selector", {
props: ["v-cluster-id"],
mounted: function () {
let that = this
@@ -9,7 +10,6 @@ Vue.component("cluster-selector", {
that.clusters = resp.data.clusters
})
},
props: ["v-cluster-id"],
data: function () {
let clusterId = this.vClusterId
if (clusterId == null) {
@@ -21,7 +21,7 @@ Vue.component("cluster-selector", {
}
},
template: `<div>
<select class="ui dropdown auto-width" name="clusterId" v-model="clusterId">
<select class="ui dropdown" style="max-width: 10em" name="clusterId" v-model="clusterId">
<option value="0">[选择集群]</option>
<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
</select>

View File

@@ -1,9 +1,10 @@
// 节点IP地址管理标签形式
Vue.component("node-ip-addresses-box", {
props: ["vIpAddresses"],
props: ["v-ip-addresses", "role"],
data: function () {
return {
ipAddresses: (this.vIpAddresses == null) ? [] : this.vIpAddresses
ipAddresses: (this.vIpAddresses == null) ? [] : this.vIpAddresses,
supportThresholds: this.role != "ns"
}
},
methods: {
@@ -12,7 +13,7 @@ Vue.component("node-ip-addresses-box", {
window.UPDATING_NODE_IP_ADDRESS = null
let that = this;
teaweb.popup("/nodes/ipAddresses/createPopup", {
teaweb.popup("/nodes/ipAddresses/createPopup?supportThresholds=" + (this.supportThresholds ? 1 : 0), {
callback: function (resp) {
that.ipAddresses.push(resp.data.ipAddress);
},
@@ -26,7 +27,7 @@ Vue.component("node-ip-addresses-box", {
window.UPDATING_NODE_IP_ADDRESS = address
let that = this;
teaweb.popup("/nodes/ipAddresses/updatePopup", {
teaweb.popup("/nodes/ipAddresses/updatePopup?supportThresholds=" + (this.supportThresholds ? 1 : 0), {
callback: function (resp) {
Vue.set(that.ipAddresses, index, resp.data.ipAddress);
},

View File

@@ -0,0 +1,4 @@
<first-menu>
<menu-item href="." code="index">IP地址</menu-item>
<menu-item href=".logs" code="log">变更日志</menu-item>
</first-menu>

View File

@@ -0,0 +1,7 @@
<first-menu>
<menu-item href="/clusters/ip-addrs">全部地址</menu-item>
<span class="item disabled">|</span>
<menu-item :href="'.?addrId=' + addr.id" code="addr">"{{addr.ip}}"详情</menu-item>
<menu-item :href="'.logs?addrId=' + addr.id" code="log">日志</menu-item>
<menu-item :href="'.update?addrId=' + addr.id" code="update">修改</menu-item>
</first-menu>

View File

@@ -0,0 +1,54 @@
{$layout}
{$template "menu"}
<table class="ui table definition selectable">
<tr>
<td class="title">IP地址</td>
<td>
{{addr.ip}}
</td>
</tr>
<tr>
<td>状态</td>
<td>
<label-on :v-is-on="addr.isOn" v-if="!addr.isOn"></label-on>
<span v-else-if="addr.isUp" class="green">在线</span>
<span v-else class="red">离线</span>
</td>
</tr>
<tr>
<td>所属集群</td>
<td><link-icon :href="'/clusters/cluster?clusterId=' + addr.cluster.id">{{addr.cluster.name}}</link-icon></td>
</tr>
<tr>
<td>所属节点</td>
<td>
<link-icon :href="'/clusters/cluster/node?clusterId=' + addr.cluster.id + '&nodeId=' + addr.node.id">{{addr.node.name}}</link-icon>
</td>
</tr>
<tr>
<td>名称</td>
<td>
<span v-if="addr.name.length > 0">{{addr.name}}</span>
<span v-else class="disabled">-</span>
</td>
</tr>
<tr>
<td>是否可以访问</td>
<td>
<span v-if="addr.canAccess" class="green">Y</span>
<span v-else class="disabled">N</span>
</td>
</tr>
<tr>
<td>阈值</td>
<td>
<div v-if="addr.thresholds.length > 0">
<span v-for="threshold in addr.thresholds" class="ui basic tiny label">
{{threshold.item}} {{threshold.operator}} {{threshold.value}}
</span>
</div>
<span v-else class="disabled">没有设置阈值。</span>
</td>
</tr>
</table>

View File

@@ -0,0 +1,34 @@
{$layout}
{$template "menu"}
<p class="comment" v-if="logs.length == 0">暂时还没有日志。</p>
<div v-if="logs.length > 0">
<div class="margin"></div>
<table class="ui table selectable celled">
<thead>
<tr>
<th class="two wide">操作人</th>
<th class="two wide">状态</th>
<th>描述</th>
<th style="width: 12em">时间</th>
</tr>
</thead>
<tr v-for="log in logs">
<td>
<span v-if="log.admin.id > 0">{{log.admin.name}}</span>
<span v-else class="grey">{{log.admin.name}}</span>
</td>
<td>
<span v-if="!log.isOn" class="red">停用</span>
<span v-else-if="!log.canAccess" class="red">不可访问</span>
<span v-else-if="log.isUp" class="green">上线</span>
<span v-else class="red">离线</span>
</td>
<td>{{log.description}}</td>
<td>{{log.createdTime}}</td>
</tr>
</table>
</div>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,53 @@
{$layout}
{$template "menu"}
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="addrId" :value="addr.id"/>
<table class="ui table definition selectable">
<tr>
<td class="title">IP地址 *</td>
<td>
<input type="text" name="ip" maxlength="128" ref="focus" v-model="addr.ip"/>
</td>
</tr>
<tr>
<td>是否可以访问</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="canAccess" value="1" v-model="addr.canAccess"/>
<label></label>
</div>
<p class="comment">是否为可以公开访问的IP如果选中也会作为DNS解析记录的值使用。</p>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>是否启用</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="isOn" value="1" v-model="addr.isOn"/>
<label></label>
</div>
<p class="comment">选中表示当前IP有效。</p>
</td>
</tr>
<tr>
<td class="title">名称</td>
<td>
<input type="text" name="name" maxlength="50" v-model="addr.name"/>
</td>
</tr>
<tr v-if="teaIsPlus && supportThresholds">
<td>上线阈值</td>
<td>
<node-ip-address-thresholds-box :v-thresholds="addr.thresholds"></node-ip-address-thresholds-box>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,3 @@
Tea.context(function () {
this.success = NotifySuccess("保存成功", Tea.url(".addr", { addrId: this.addr.id }))
})

View File

@@ -0,0 +1,86 @@
{$layout}
{$template "menu"}
<div class="margin"></div>
<form class="ui form" method="get" action="/clusters/ip-addrs">
<div class="ui fields inline">
<div class="ui field">
集群:
</div>
<div class="ui field">
<cluster-selector :v-cluster-id="clusterId"></cluster-selector>
</div>
<div class="ui field">
状态:
</div>
<div class="ui field">
<select class="ui dropdown" name="upState" v-model="upState">
<option value="0">[全部]</option>
<option value="1">在线</option>
<option value="2">离线</option>
</select>
</div>
<div class="ui field">
<input type="text" placeholder="IP、名称..." name="keyword" v-model="keyword"/>
</div>
<div class="ui field">
<button class="ui button" type="submit">搜索</button>
&nbsp;
<a href="/clusters/ip-addrs" v-if="clusterId > 0 || upState > 0 || keyword.length > 0">[清除条件]</a>
</div>
</div>
</form>
<p class="comment" v-if="addrs.length == 0">暂时还没有IP地址。</p>
<div v-if="addrs.length > 0">
<div class="margin"></div>
<table class="ui table selectable celled">
<thead>
<tr>
<th>IP</th>
<th>所属集群</th>
<th>所属节点</th>
<th>名称</th>
<th>可访问</th>
<th>阈值</th>
<th>状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="addr in addrs">
<td>
<a :href="'/clusters/ip-addrs/addr?addrId=' + addr.id"><keyword :v-word="keyword">{{addr.ip}}</keyword></a>
</td>
<td>
<link-icon :href="'/clusters/cluster?clusterId=' + addr.cluster.id">{{addr.cluster.name}}</link-icon>
</td>
<td>
<link-icon :href="'/clusters/cluster/node?clusterId=' + addr.cluster.id + '&nodeId=' + addr.node.id"><keyword :v-word="keyword">{{addr.node.name}}</keyword></link-icon>
</td>
<td>
<span v-if="addr.name.length > 0"><keyword :v-word="keyword">{{addr.name}}</keyword></span>
<span v-else class="disabled">-</span>
</td>
<td>
<span v-if="addr.canAccess" class="green">Y</span>
<span v-else class="disabled">N</span>
</td>
<td>
<span v-if="addr.hasThresholds" class="green">Y</span>
<span v-else class="disabled">N</span>
</td>
<td>
<label-on :v-is-on="addr.isOn" v-if="!addr.isOn"></label-on>
<span v-else-if="addr.isUp" class="green">在线</span>
<span v-else class="red">离线</span>
</td>
<td>
<a :href="'/clusters/ip-addrs/addr?addrId=' + addr.id">详情</a> &nbsp;
<a href="" @click.prevent="deleteAddr(addr.id)">删除</a>
</td>
</tr>
</table>
</div>
<div class="page" v-html="page"></div>

View File

@@ -0,0 +1,13 @@
Tea.context(function () {
this.deleteAddr = function (addrId) {
teaweb.confirm("确定要删除这个IP地址吗", function () {
this.$post(".addr.delete")
.params({
addrId: addrId
})
.success(function () {
teaweb.reload()
})
})
}
})

View File

@@ -0,0 +1,39 @@
{$layout}
{$template "menu"}
<p class="comment" v-if="logs.length == 0">暂时还没有日志。</p>
<div v-if="logs.length > 0">
<div class="margin"></div>
<table class="ui table selectable celled">
<thead>
<tr>
<th class="two wide">操作人</th>
<th>IP</th>
<th class="two wide">状态</th>
<th>描述</th>
<th style="width: 12em">时间</th>
</tr>
</thead>
<tr v-for="log in logs">
<td>
<span v-if="log.admin.id > 0">{{log.admin.name}}</span>
<span v-else class="grey">{{log.admin.name}}</span>
</td>
<td>
<span v-if="log.addr != null"><a :href="'/clusters/ip-addrs/addr?addrId=' + log.addr.id">{{log.addr.ip}}</a></span>
<span v-else class="disabled">已删除</span>
</td>
<td>
<span v-if="!log.isOn" class="red">停用</span>
<span v-else-if="!log.canAccess" class="red">不可访问</span>
<span v-else-if="log.isUp" class="green">上线</span>
<span v-else class="red">离线</span>
</td>
<td>{{log.description}}</td>
<td>{{log.createdTime}}</td>
</tr>
</table>
</div>
<div class="page" v-html="page"></div>

View File

@@ -25,12 +25,12 @@
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td class="title">备注</td>
<td class="title">名称</td>
<td>
<input type="text" name="name" maxlength="50"/>
</td>
</tr>
<tr v-if="teaIsPlus">
<tr v-if="teaIsPlus && supportThresholds">
<td>上线阈值</td>
<td>
<node-ip-address-thresholds-box></node-ip-address-thresholds-box>

View File

@@ -36,12 +36,12 @@
</td>
</tr>
<tr>
<td class="title">备注</td>
<td class="title">名称</td>
<td>
<input type="text" name="name" maxlength="50" v-model="address.name"/>
</td>
</tr>
<tr v-if="teaIsPlus">
<tr v-if="teaIsPlus && supportThresholds">
<td>上线阈值</td>
<td>
<node-ip-address-thresholds-box :v-thresholds="address.thresholds"></node-ip-address-thresholds-box>

View File

@@ -13,7 +13,7 @@
<tr>
<td>IP地址 *</td>
<td>
<node-ip-addresses-box role="dns"></node-ip-addresses-box>
<node-ip-addresses-box role="ns"></node-ip-addresses-box>
<p class="comment">用于访问节点和域名解析等。</p>
</td>
</tr>

View File

@@ -16,7 +16,7 @@
<tr>
<td>IP地址 *</td>
<td>
<node-ip-addresses-box :v-ip-addresses="node.ipAddresses"></node-ip-addresses-box>
<node-ip-addresses-box role="ns" :v-ip-addresses="node.ipAddresses"></node-ip-addresses-box>
<p class="comment">用于访问节点和域名解析等。</p>
</td>
</tr>