修改隧道列表,增加远端名称字段

This commit is contained in:
lwch
2021-10-13 18:28:11 +08:00
parent d4626ce3ec
commit 3e5cd71bf5
6 changed files with 26 additions and 5 deletions
+6 -4
View File
@@ -15,15 +15,17 @@ func (db *Dashboard) Tunnels(w http.ResponseWriter, r *http.Request) {
RecvPacket uint64 `json:"recv_packet"`
}
type item struct {
Name string `json:"name"`
Port uint16 `json:"port"`
Type string `json:"type"`
Links []link `json:"links"`
Name string `json:"name"`
Remote string `json:"remote"`
Port uint16 `json:"port"`
Type string `json:"type"`
Links []link `json:"links"`
}
var ret []item
db.mgr.Range(func(t tunnel.Tunnel) {
var it item
it.Name = t.GetName()
it.Remote = t.GetRemote()
it.Port = t.GetPort()
it.Type = t.GetTypeName()
for _, l := range t.GetLinks() {
+1
View File
@@ -13,6 +13,7 @@ type Link interface {
// Tunnel tunnel interface
type Tunnel interface {
GetName() string
GetRemote() string
GetPort() uint16
GetTypeName() string
GetTarget() string
+5
View File
@@ -54,6 +54,11 @@ func (t *Tunnel) GetLinks() []tunnel.Link {
return ret
}
// GetRemote get remote target name
func (t *Tunnel) GetRemote() string {
return t.cfg.Target
}
// GetPort get listen port
func (t *Tunnel) GetPort() uint16 {
return t.cfg.LocalPort
+5
View File
@@ -55,6 +55,11 @@ func (shell *Shell) GetLinks() []tunnel.Link {
return ret
}
// GetRemote get remote target name
func (shell *Shell) GetRemote() string {
return shell.cfg.Target
}
// GetPort get listen port
func (shell *Shell) GetPort() uint16 {
return shell.cfg.LocalPort
+2 -1
View File
@@ -30,7 +30,8 @@
<table id="tunnels" class="table table-hover">
<thead><tr>
<th>名称</th>
<th style="width:80px">类型</th>
<th style="width:200px">对端</th>
<th style="width:120px">类型</th>
<th style="width:120px">虚拟连接数</th>
<th style="width:200px">接收/发送(字节数)</th>
<th style="width:200px">接收/发送(数据包)</th>
+7
View File
@@ -1,10 +1,15 @@
var page = {
init: function() {
page.render();
setInterval(page.render, 5000);
},
render: function() {
page.render_cards();
page.render_tunnels();
},
render_cards: function() {
$.get('/api/info', function(ret) {
$('#cards').empty();
page.add_card('隧道总数', ret.tunnels);
page.add_card('物理连接数', ret.physical_links);
page.add_card('虚拟连接数', ret.virtual_links);
@@ -13,6 +18,7 @@ var page = {
},
render_tunnels: function() {
$.get('/api/tunnels', function(ret) {
$('#tunnels tbody').empty();
$.each(ret, function(_, tunnel) {
var send_bytes = 0;
var send_packet = 0;
@@ -33,6 +39,7 @@ var page = {
var str = `
<tr>
<td>${tunnel.name}</td>
<td>${tunnel.remote}</td>
<td>${tunnel.type}</td>
<td>${tunnel.links?tunnel.links.length:0}</td>
<td>${humanize.bytes(recv_bytes)}/${humanize.bytes(send_bytes)}</td>