-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathclients.templ
More file actions
137 lines (133 loc) · 5.21 KB
/
clients.templ
File metadata and controls
137 lines (133 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"fmt"
"fiatjaf.com/nostr"
"github.com/fiatjaf/pyramid/global"
"github.com/fiatjaf/pyramid/layout"
)
templ clientDetailsPage(loggedUser nostr.PubKey, clients []relayClientInfo) {
@layout.Layout(loggedUser, "settings") {
<div class="max-w-6xl mx-auto space-y-6">
<div class="flex items-center justify-between gap-4">
@layout.SubSectionTitle("list of connected clients")
</div>
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-stone-500 dark:text-stone-400 border-b border-stone-200 dark:border-stone-700">
<th class="px-4 py-3">relay</th>
<th class="px-4 py-3">client</th>
<th class="px-4 py-3">ip</th>
<th class="px-4 py-3">user</th>
<th class="px-4 py-3">origin</th>
<th class="px-4 py-3 text-right">subs</th>
</tr>
</thead>
<tbody>
if len(clients) == 0 {
<tr>
<td colspan="6" class="px-4 py-6 text-center text-stone-500 dark:text-stone-400">no clients connected</td>
</tr>
} else {
for _, client := range clients {
<tr class="border-b border-stone-100 dark:border-stone-700 last:border-b-0">
<td class="px-4 py-3 font-mono">{ client.RelayID.String() }</td>
<td class="px-4 py-3 font-mono"><a href={ templ.SafeURL("/clients/" + client.ID + "?r=" + client.RelayID.String()) } class="hover:underline">{ client.ID }</a></td>
<td class="px-4 py-3 font-mono">{ client.IP }</td>
<td class="px-4 py-3">
for _, pk := range client.Authenticated {
<a
class="mr-1 block text-sm font-medium light:text-stone-600 dark:text-stone-400 hover:underline underline-offset-4"
target="_blank"
href={ templ.SafeURL(global.Settings.GetExternalLink(nostr.ProfilePointer{PublicKey: pk})) }
>
<nostr-name pubkey={ pk.Hex() }>{ pk.Hex() }</nostr-name>
</a>
}
</td>
<td class="px-4 py-3 break-all">
<div class="font-semibold text-gray-600">{ client.Origin }</div>
<div
if client.Origin != "" {
class="mt-1 text-xs"
} else {
class="mt-1"
}
>{ client.UserAgent }</div>
</td>
<td class="px-4 py-3 text-right">{ client.SubscriptionCount }</td>
</tr>
}
}
</tbody>
</table>
</div>
</div>
}
}
templ singleClientDetailsPage(loggedUser nostr.PubKey, client relayClientSnapshot) {
{{
totalCost := 0
for _, sub := range client.Subscriptions {
totalCost += global.GetFilterCost(sub.Filter)
}
}}
@layout.Layout(loggedUser, "settings") {
<div class="max-w-6xl mx-auto space-y-6">
<div class="flex items-center justify-between gap-4">
<div>
@layout.SubSectionTitle("client " + client.ID)
<div class="text-sm text-stone-600 dark:text-stone-400 mt-2">relay: <span class="font-mono">{ client.RelayID.String() }</span></div>
<div class="text-sm text-stone-600 dark:text-stone-400">ip: <span class="font-mono">{ client.IP }</span></div>
<div class="text-sm text-stone-600 dark:text-stone-400">total cost: { fmt.Sprint(totalCost) }</div>
<div class="text-sm text-stone-600 dark:text-stone-400">user-agent: { client.UserAgent }</div>
if client.Origin != "" {
<div class="text-sm text-stone-600 dark:text-stone-400">origin: { client.Origin }</div>
}
if len(client.Authenticated) > 0 {
<div class="text-sm text-stone-600 dark:text-stone-400 flex gap-2">
<div>authenticated:</div>
<div>
for _, pk := range client.Authenticated {
<a
class="mr-1 block text-sm font-medium light:text-stone-600 dark:text-stone-400 hover:underline underline-offset-4"
target="_blank"
href={ templ.SafeURL(global.Settings.GetExternalLink(nostr.ProfilePointer{PublicKey: pk})) }
>
<nostr-name pubkey={ pk.Hex() }>{ pk.Hex() }</nostr-name>
</a>
}
</div>
</div>
}
</div>
</div>
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-stone-500 dark:text-stone-400 border-b border-stone-200 dark:border-stone-700">
<th class="px-4 py-3">subscription id</th>
<th class="px-4 py-3">cost</th>
<th class="px-4 py-3">filter</th>
</tr>
</thead>
<tbody>
if len(client.Subscriptions) == 0 {
<tr>
<td colspan="3" class="px-4 py-6 text-center text-stone-500 dark:text-stone-400">no open subscriptions</td>
</tr>
} else {
for _, sub := range client.Subscriptions {
<tr class="border-b border-stone-100 dark:border-stone-700 last:border-b-0 align-top">
<td class="px-4 py-3 font-mono whitespace-nowrap">{ sub.ID }</td>
<td class="px-4 py-3">{ fmt.Sprint(global.GetFilterCost(sub.Filter)) }</td>
<td class="px-4 py-3"><code class="text-xs break-all whitespace-pre-wrap">{ sub.Filter.String() }</code></td>
</tr>
}
}
</tbody>
</table>
</div>
</div>
}
}