Skip to content

Commit 1245f88

Browse files
authored
server: replace client metadata with IP address in registry (#5118)
1 parent 479e9f5 commit 1245f88

File tree

9 files changed

+48
-85
lines changed

9 files changed

+48
-85
lines changed
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/frps/static/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<head>
55
<meta charset="utf-8">
66
<title>frp server</title>
7-
<script type="module" crossorigin src="./index-BUrDiw1t.js"></script>
8-
<link rel="stylesheet" crossorigin href="./index-D4KRVvIu.css">
7+
<script type="module" crossorigin src="./index-r9B2t7lx.js"></script>
8+
<link rel="stylesheet" crossorigin href="./index-Cl4R6mJh.css">
99
</head>
1010

1111
<body>

server/client_registry.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package server
22

33
import (
44
"fmt"
5-
"maps"
65
"sync"
76
"time"
87
)
@@ -14,7 +13,7 @@ type ClientInfo struct {
1413
ClientID string
1514
RunID string
1615
Hostname string
17-
Metas map[string]string
16+
IP string
1817
FirstConnectedAt time.Time
1918
LastConnectedAt time.Time
2019
DisconnectedAt time.Time
@@ -37,7 +36,7 @@ func NewClientRegistry() *ClientRegistry {
3736
}
3837

3938
// Register stores/updates metadata for a client and returns the registry key plus whether it conflicts with an online client.
40-
func (cr *ClientRegistry) Register(user, clientID, runID, hostname string, metas map[string]string) (key string, conflict bool) {
39+
func (cr *ClientRegistry) Register(user, clientID, runID, hostname, remoteAddr string) (key string, conflict bool) {
4140
if runID == "" {
4241
return "", false
4342
}
@@ -72,7 +71,7 @@ func (cr *ClientRegistry) Register(user, clientID, runID, hostname string, metas
7271

7372
info.RunID = runID
7473
info.Hostname = hostname
75-
info.Metas = metas
74+
info.IP = remoteAddr
7675
if info.FirstConnectedAt.IsZero() {
7776
info.FirstConnectedAt = now
7877
}
@@ -113,9 +112,7 @@ func (cr *ClientRegistry) List() []ClientInfo {
113112

114113
result := make([]ClientInfo, 0, len(cr.clients))
115114
for _, info := range cr.clients {
116-
cp := *info
117-
cp.Metas = maps.Clone(info.Metas)
118-
result = append(result, cp)
115+
result = append(result, *info)
119116
}
120117
return result
121118
}
@@ -129,9 +126,7 @@ func (cr *ClientRegistry) GetByKey(key string) (ClientInfo, bool) {
129126
if !ok {
130127
return ClientInfo{}, false
131128
}
132-
cp := *info
133-
cp.Metas = maps.Clone(info.Metas)
134-
return cp, true
129+
return *info, true
135130
}
136131

137132
func (cr *ClientRegistry) composeClientKey(user, id string) string {

server/dashboard_api.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ type serverInfoResp struct {
9494
}
9595

9696
type clientInfoResp struct {
97-
Key string `json:"key"`
98-
User string `json:"user"`
99-
ClientID string `json:"clientId"`
100-
RunID string `json:"runId"`
101-
Hostname string `json:"hostname"`
102-
Metas map[string]string `json:"metas,omitempty"`
103-
FirstConnectedAt int64 `json:"firstConnectedAt"`
104-
LastConnectedAt int64 `json:"lastConnectedAt"`
105-
DisconnectedAt int64 `json:"disconnectedAt,omitempty"`
106-
Online bool `json:"online"`
97+
Key string `json:"key"`
98+
User string `json:"user"`
99+
ClientID string `json:"clientID"`
100+
RunID string `json:"runID"`
101+
Hostname string `json:"hostname"`
102+
ClientIP string `json:"clientIP,omitempty"`
103+
FirstConnectedAt int64 `json:"firstConnectedAt"`
104+
LastConnectedAt int64 `json:"lastConnectedAt"`
105+
DisconnectedAt int64 `json:"disconnectedAt,omitempty"`
106+
Online bool `json:"online"`
107107
}
108108

109109
// /healthz
@@ -531,7 +531,7 @@ func buildClientInfoResp(info ClientInfo) clientInfoResp {
531531
ClientID: info.ClientID,
532532
RunID: info.RunID,
533533
Hostname: info.Hostname,
534-
Metas: info.Metas,
534+
ClientIP: info.IP,
535535
FirstConnectedAt: toUnix(info.FirstConnectedAt),
536536
LastConnectedAt: toUnix(info.LastConnectedAt),
537537
Online: info.Online,

server/service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ func (svr *Service) RegisterControl(ctlConn net.Conn, loginMsg *msg.Login, inter
615615
oldCtl.WaitClosed()
616616
}
617617

618-
_, conflict := svr.clientRegistry.Register(loginMsg.User, loginMsg.ClientID, loginMsg.RunID, loginMsg.Hostname, loginMsg.Metas)
618+
remoteAddr := ctlConn.RemoteAddr().String()
619+
if host, _, err := net.SplitHostPort(remoteAddr); err == nil {
620+
remoteAddr = host
621+
}
622+
_, conflict := svr.clientRegistry.Register(loginMsg.User, loginMsg.ClientID, loginMsg.RunID, loginMsg.Hostname, remoteAddr)
619623
if conflict {
620624
svr.ctlManager.Del(loginMsg.RunID, ctl)
621625
ctl.Close()

web/frps/src/components/ClientCard.vue

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
<span class="info-value">{{ client.hostname || 'N/A' }}</span>
1818
</div>
1919

20+
<div class="info-row" v-if="client.ip">
21+
<el-icon class="info-icon"><Connection /></el-icon>
22+
<span class="info-label">IP:</span>
23+
<span class="info-value monospace">{{ client.ip }}</span>
24+
</div>
25+
2026
<div class="info-row" v-if="client.user">
2127
<el-icon class="info-icon"><User /></el-icon>
2228
<span class="info-label">User:</span>
@@ -26,7 +32,7 @@
2632
<div class="info-row">
2733
<el-icon class="info-icon"><Key /></el-icon>
2834
<span class="info-label">Run ID:</span>
29-
<span class="info-value monospace">{{ client.runId }}</span>
35+
<span class="info-value monospace">{{ client.runID }}</span>
3036
</div>
3137

3238
<div class="info-row" v-if="client.firstConnectedAt">
@@ -48,26 +54,12 @@
4854
</div>
4955
</div>
5056

51-
<div class="client-metas" v-if="client.metasArray.length > 0">
52-
<div class="metas-label">Metadata:</div>
53-
<div class="metas-tags">
54-
<el-tag
55-
v-for="meta in client.metasArray"
56-
:key="meta.key"
57-
size="small"
58-
type="info"
59-
class="meta-tag"
60-
>
61-
{{ meta.key }}: {{ meta.value }}
62-
</el-tag>
63-
</div>
64-
</div>
6557
</el-card>
6658
</template>
6759

6860
<script setup lang="ts">
6961
import { computed } from 'vue'
70-
import { Monitor, User, Key, Clock, CircleClose } from '@element-plus/icons-vue'
62+
import { Monitor, User, Key, Clock, CircleClose, Connection } from '@element-plus/icons-vue'
7163
import type { Client } from '../utils/client'
7264
7365
interface Props {
@@ -190,37 +182,6 @@ html.dark .info-value {
190182
color: #d1d5db;
191183
}
192184
193-
.client-metas {
194-
margin-bottom: 16px;
195-
padding-top: 12px;
196-
border-top: 1px solid #e4e7ed;
197-
}
198-
199-
html.dark .client-metas {
200-
border-top-color: #3a3d5c;
201-
}
202-
203-
.metas-label {
204-
font-size: 13px;
205-
color: #909399;
206-
font-weight: 500;
207-
margin-bottom: 8px;
208-
}
209-
210-
html.dark .metas-label {
211-
color: #9ca3af;
212-
}
213-
214-
.metas-tags {
215-
display: flex;
216-
flex-wrap: wrap;
217-
gap: 6px;
218-
}
219-
220-
.meta-tag {
221-
font-size: 12px;
222-
}
223-
224185
.monospace {
225186
font-family: 'Courier New', Courier, monospace;
226187
font-size: 12px;

web/frps/src/types/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export interface ClientInfoData {
22
key: string
33
user: string
4-
clientId: string
5-
runId: string
4+
clientID: string
5+
runID: string
66
hostname: string
7+
clientIP?: string
78
metas?: Record<string, string>
89
firstConnectedAt: number
910
lastConnectedAt: number

web/frps/src/utils/client.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import type { ClientInfoData } from '../types/client'
44
export class Client {
55
key: string
66
user: string
7-
clientId: string
8-
runId: string
7+
clientID: string
8+
runID: string
99
hostname: string
10+
ip: string
1011
metas: Map<string, string>
1112
firstConnectedAt: Date
1213
lastConnectedAt: Date
@@ -16,9 +17,10 @@ export class Client {
1617
constructor(data: ClientInfoData) {
1718
this.key = data.key
1819
this.user = data.user
19-
this.clientId = data.clientId
20-
this.runId = data.runId
20+
this.clientID = data.clientID
21+
this.runID = data.runID
2122
this.hostname = data.hostname
23+
this.ip = data.clientIP || ''
2224
this.metas = new Map<string, string>()
2325
if (data.metas) {
2426
for (const [key, value] of Object.entries(data.metas)) {
@@ -34,14 +36,14 @@ export class Client {
3436
}
3537

3638
get displayName(): string {
37-
if (this.clientId) {
38-
return this.user ? `${this.user}.${this.clientId}` : this.clientId
39+
if (this.clientID) {
40+
return this.user ? `${this.user}.${this.clientID}` : this.clientID
3941
}
40-
return this.runId
42+
return this.runID
4143
}
4244

4345
get shortRunId(): string {
44-
return this.runId.substring(0, 8)
46+
return this.runID.substring(0, 8)
4547
}
4648

4749
get firstConnectedAgo(): string {
@@ -74,8 +76,8 @@ export class Client {
7476
return (
7577
this.key.toLowerCase().includes(search) ||
7678
this.user.toLowerCase().includes(search) ||
77-
this.clientId.toLowerCase().includes(search) ||
78-
this.runId.toLowerCase().includes(search) ||
79+
this.clientID.toLowerCase().includes(search) ||
80+
this.runID.toLowerCase().includes(search) ||
7981
this.hostname.toLowerCase().includes(search)
8082
)
8183
}

0 commit comments

Comments
 (0)