From 759382bcfb75f68aa78646260382181c1761157e Mon Sep 17 00:00:00 2001
From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com>
Date: Wed, 5 Jul 2023 17:08:19 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=9B=E7=A8=8B=E7=AE=A1=E7=90=86?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=20tcp=20udp=20=E7=BD=91=E7=BB=9C=E5=88=97?=
=?UTF-8?q?=E8=A1=A8=20(#1548)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/utils/websocket/process_data.go | 56 ++++-
frontend/src/lang/modules/en.ts | 3 +-
frontend/src/lang/modules/tw.ts | 3 +-
frontend/src/lang/modules/zh.ts | 4 +-
frontend/src/routers/modules/host.ts | 10 +
frontend/src/views/host/process/index.vue | 4 +
.../src/views/host/process/network/index.vue | 230 ++++++++++++++++++
7 files changed, 306 insertions(+), 4 deletions(-)
create mode 100644 frontend/src/views/host/process/network/index.vue
diff --git a/backend/utils/websocket/process_data.go b/backend/utils/websocket/process_data.go
index 4a8d130c6..b71c5b98e 100644
--- a/backend/utils/websocket/process_data.go
+++ b/backend/utils/websocket/process_data.go
@@ -17,6 +17,7 @@ type WsInput struct {
DownloadProgress
PsProcessConfig
SSHSessionConfig
+ NetConfig
}
type DownloadProgress struct {
@@ -34,6 +35,12 @@ type SSHSessionConfig struct {
LoginIP string `json:"loginIP"`
}
+type NetConfig struct {
+ Port uint32 `json:"port"`
+ ProcessName string `json:"processName"`
+ ProcessID int32 `json:"processID"`
+}
+
type PsProcessData struct {
PID int32 `json:"PID"`
Name string `json:"name"`
@@ -71,7 +78,8 @@ type processConnect struct {
Status string `json:"status"`
Laddr net.Addr `json:"localaddr"`
Raddr net.Addr `json:"remoteaddr"`
- PID string `json:"PID"`
+ PID int32 `json:"PID"`
+ Name string `json:"name"`
}
type sshSession struct {
@@ -108,6 +116,12 @@ func ProcessData(c *Client, inputMsg []byte) {
return
}
c.Msg <- res
+ case "net":
+ res, err := getNetConnections(wsInput.NetConfig)
+ if err != nil {
+ return
+ }
+ c.Msg <- res
}
}
@@ -295,3 +309,43 @@ func getSSHSessions(config SSHSessionConfig) (res []byte, err error) {
res, err = json.Marshal(result)
return
}
+
+var netTypes = [...]string{"tcp", "udp"}
+
+func getNetConnections(config NetConfig) (res []byte, err error) {
+ var (
+ result []processConnect
+ proc *process.Process
+ )
+ for _, netType := range netTypes {
+ connections, _ := net.Connections(netType)
+ if err == nil {
+ for _, conn := range connections {
+ if config.ProcessID > 0 && config.ProcessID != conn.Pid {
+ continue
+ }
+ proc, err = process.NewProcess(conn.Pid)
+ if err == nil {
+ name, _ := proc.Name()
+ if name != "" && config.ProcessName != "" && !strings.Contains(name, config.ProcessName) {
+ continue
+ }
+ if config.Port > 0 && config.Port != conn.Laddr.Port && config.Port != conn.Raddr.Port {
+ continue
+ }
+ result = append(result, processConnect{
+ Type: netType,
+ Status: conn.Status,
+ Laddr: conn.Laddr,
+ Raddr: conn.Raddr,
+ PID: conn.Pid,
+ Name: name,
+ })
+ }
+
+ }
+ }
+ }
+ res, err = json.Marshal(result)
+ return
+}
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index 586ae5da8..48c4b59d2 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -249,6 +249,7 @@ const message = {
runtime: 'Runtime',
processManage: 'Process',
process: 'Process',
+ network: 'Network',
},
home: {
overview: 'Overview',
@@ -1417,7 +1418,7 @@ const message = {
ipv6: 'Listen IPV6',
leechReturnError: 'Please fill in the HTTP status code',
selectAcme: 'Select Acme account',
- imported: 'Imported',
+ imported: 'Manually Created',
importType: 'Import Type',
pasteSSL: 'Paste code',
localSSL: 'Select local file',
diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts
index 44c6fb78e..9d9d05969 100644
--- a/frontend/src/lang/modules/tw.ts
+++ b/frontend/src/lang/modules/tw.ts
@@ -247,6 +247,7 @@ const message = {
runtime: '運行環境',
processManage: '進程管理',
process: '進程',
+ network: '網絡',
},
home: {
overview: '概覽',
@@ -1348,7 +1349,7 @@ const message = {
ipv6: '監聽 IPV6 端口',
leechReturnError: '請填寫 HTTP 狀態碼',
selectAcme: '選擇 Acme 賬號',
- imported: '已導入',
+ imported: '手動創建',
importType: '導入方式',
pasteSSL: '粘貼代碼',
localSSL: '選擇本地文件',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index 92ba9e7be..5c0d5071e 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -247,6 +247,7 @@ const message = {
runtime: '运行环境',
processManage: '进程管理',
process: '进程',
+ network: '网络',
},
home: {
overview: '概览',
@@ -1354,7 +1355,7 @@ const message = {
ipv6: '监听 IPV6 端口',
leechReturnError: '请填写 HTTP 状态码',
selectAcme: '选择 acme 账号',
- imported: '已导入',
+ imported: '手动创建',
importType: '导入方式',
pasteSSL: '粘贴代码',
localSSL: '选择本地文件',
@@ -1527,6 +1528,7 @@ const message = {
raddr: '目标地址/端口',
stopProcess: '结束',
stopProcessWarn: '是否确定结束此进程 (PID:{0})?此操作不可回滚',
+ processName: '进程名称',
},
};
export default {
diff --git a/frontend/src/routers/modules/host.ts b/frontend/src/routers/modules/host.ts
index 2dc95c0f0..1ed85007a 100644
--- a/frontend/src/routers/modules/host.ts
+++ b/frontend/src/routers/modules/host.ts
@@ -80,6 +80,16 @@ const hostRouter = {
requiresAuth: false,
},
},
+ {
+ path: '/hosts/process/network',
+ name: 'ProcessNetwork',
+ hidden: true,
+ component: () => import('@/views/host/process/network/index.vue'),
+ meta: {
+ activeMenu: '/hosts/process/process',
+ requiresAuth: false,
+ },
+ },
{
path: '/hosts/ssh/ssh',
name: 'SSH',
diff --git a/frontend/src/views/host/process/index.vue b/frontend/src/views/host/process/index.vue
index 1a9eb16c8..dd5943e8b 100644
--- a/frontend/src/views/host/process/index.vue
+++ b/frontend/src/views/host/process/index.vue
@@ -16,5 +16,9 @@ const buttons = [
label: i18n.global.t('menu.process'),
path: '/hosts/process/process',
},
+ {
+ label: i18n.global.t('menu.network'),
+ path: '/hosts/process/network',
+ },
];
diff --git a/frontend/src/views/host/process/network/index.vue b/frontend/src/views/host/process/network/index.vue
new file mode 100644
index 000000000..655ab6ec5
--- /dev/null
+++ b/frontend/src/views/host/process/network/index.vue
@@ -0,0 +1,230 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ row.localaddr.ip }}
+ :{{ row.localaddr.port }}
+
+
+
+
+ {{ row.remoteaddr.ip }}
+ :{{ row.remoteaddr.port }}
+
+
+
+
+
+
+
+
+
+