Skip to content

Commit

Permalink
完善web端显示数据
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed Apr 4, 2024
1 parent 114233a commit 6531f6b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
12 changes: 8 additions & 4 deletions src/core/entity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::cipher::Aes256GcmCipher;
use chrono::{DateTime, Local};
use std::collections::HashMap;
use std::net::{Ipv4Addr, SocketAddr};
Expand Down Expand Up @@ -37,12 +36,14 @@ impl NetworkInfo {
pub struct ClientInfo {
// 设备ID
pub device_id: String,
// 版本
pub version: String,
// 名称
pub name: String,
// 客户端间是否加密
pub client_secret: bool,
// 和服务端的加密方式
pub server_secret: Option<Aes256GcmCipher>,
// 和服务端是否加密
pub server_secret: bool,
// 链接服务器的来源地址
pub address: SocketAddr,
// 是否在线
Expand All @@ -52,20 +53,23 @@ pub struct ClientInfo {
// 建立的tcp连接发送端
pub tcp_sender: Option<Sender<Vec<u8>>>,
pub client_status: Option<ClientStatusInfo>,
pub last_join_time: DateTime<Local>,
}

impl Default for ClientInfo {
fn default() -> Self {
Self {
device_id: "".to_string(),
version: "".to_string(),
name: "".to_string(),
client_secret: false,
server_secret: None,
server_secret: false,
address: "0.0.0.0:0".parse().unwrap(),
online: false,
virtual_ip: 0,
tcp_sender: None,
client_status: None,
last_join_time: Local::now(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub async fn start(
.service(group_info)
.service(Files::new("/", "./static/").index_file("index.html"))
})
.listen(lst)?
.run()
.await
.listen(lst)?
.run()
.await
}
4 changes: 3 additions & 1 deletion src/core/server/web/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ impl VntsWebService {

let client_info = ClientInfo {
device_id: into.device_id.clone(),
version: into.version.clone(),
name: into.name.clone(),
client_secret: into.client_secret,
server_secret: into.server_secret.is_some(),
server_secret: into.server_secret,
address,
online: into.online,
virtual_ip: into.virtual_ip.into(),
status_info,
last_join_time: into.last_join_time.format("%Y-%m-%d %H:%M:%S").to_string(),
};
network.clients.push(client_info);
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/web/vo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ impl ResponseMessage<Option<()>> {
pub struct ClientInfo {
// 设备ID
pub device_id: String,
// 客户端版本
pub version: String,
// 名称
pub name: String,
// 客户端间是否加密
Expand All @@ -56,6 +58,7 @@ pub struct ClientInfo {
// 分配的ip
pub virtual_ip: Ipv4Addr,
pub status_info: Option<ClientStatusInfo>,
pub last_join_time: String,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::io::Write;
use std::net::Ipv4Addr;
use std::path::PathBuf;

// use crate::service::{start_tcp, start_udp};
use clap::Parser;

use crate::cipher::RsaCipher;
Expand Down
5 changes: 4 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@
}
let node = {
clientName: client.name,
natType: status_info.is_cone ? '锥形' : '对称',
clientVersion: client.version,
deviceId: client.device_id,
lastJoinTime: client.last_join_time,
natType: status_info.is_cone == null ? '' : (status_info.is_cone ? '锥形' : '对称'),
upStream: formatBytes(status_info.up_stream),
downStream: formatBytes(status_info.down_stream),
clientSecret: client.client_secret,
Expand Down
18 changes: 13 additions & 5 deletions static/js/group-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ G6.registerNode('card-node', {
afterDraw: nodeBasicMethod.afterDraw,
setState: nodeBasicMethod.setState,
});

function toString(v) {
return v ? v : ''
}

const tooltip = new G6.Tooltip({
offsetX: 70,
offsetY: 20,
Expand All @@ -430,11 +435,14 @@ const tooltip = new G6.Tooltip({
// outDiv.style.width = '180px'
outDiv.innerHTML = `
<ul>
<li>名称: ${e.item.getModel().clientName}</li>
<li>IP: ${e.item.getModel().ip}</li>
<li>NAT类型: ${e.item.getModel().natType}</li>
<li>上传: ${e.item.getModel().upStream}</li>
<li>下载: ${e.item.getModel().downStream}</li>
<li>名称: ${toString(e.item.getModel().clientName)}</li>
<li>ID: ${toString(e.item.getModel().deviceId)}</li>
<li>版本: ${toString(e.item.getModel().clientVersion)}</li>
<li>IP: ${toString(e.item.getModel().ip)}</li>
<li>上传: ${toString(e.item.getModel().upStream)}</li>
<li>下载: ${toString(e.item.getModel().downStream)}</li>
<li>NAT类型: ${toString(e.item.getModel().natType)}</li>
<li>注册时间: ${toString(e.item.getModel().lastJoinTime)}</li>
</ul>`
return outDiv
},
Expand Down

0 comments on commit 6531f6b

Please sign in to comment.