new privacy features
This commit is contained in:
parent
ddf7817d5c
commit
c90b6c5c39
4 changed files with 1248 additions and 24 deletions
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
)
|
||||
|
||||
//go:embed dashboard.html
|
||||
//go:embed dashboard.html dashboard_public.html
|
||||
var dashboardHTML embed.FS
|
||||
|
||||
type dashboardServer struct {
|
||||
|
|
@ -91,6 +91,7 @@ func startDashboard(n *node, logger *log.Logger, listenAddr, username, password
|
|||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", d.handleIndex)
|
||||
mux.HandleFunc("/api/status", d.handleStatus)
|
||||
mux.HandleFunc("/api/status/admin", d.handleStatusAdmin)
|
||||
mux.HandleFunc("/api/peer/traffic", d.handlePeerTraffic)
|
||||
mux.HandleFunc("/api/peer/ban", d.handlePeerBan)
|
||||
|
||||
|
|
@ -144,7 +145,11 @@ func (d *dashboardServer) withAuth(next http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
func (d *dashboardServer) handleIndex(w http.ResponseWriter, _ *http.Request) {
|
||||
bs, err := dashboardHTML.ReadFile("dashboard.html")
|
||||
page := "dashboard.html"
|
||||
if d.readOnly {
|
||||
page = "dashboard_public.html"
|
||||
}
|
||||
bs, err := dashboardHTML.ReadFile(page)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -154,6 +159,22 @@ func (d *dashboardServer) handleIndex(w http.ResponseWriter, _ *http.Request) {
|
|||
}
|
||||
|
||||
func (d *dashboardServer) handleStatus(w http.ResponseWriter, _ *http.Request) {
|
||||
status := d.buildStatus(!d.readOnly)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(status)
|
||||
}
|
||||
|
||||
func (d *dashboardServer) handleStatusAdmin(w http.ResponseWriter, _ *http.Request) {
|
||||
if d.readOnly {
|
||||
http.Error(w, "admin status is unavailable on the public dashboard", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
status := d.buildStatus(true)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(status)
|
||||
}
|
||||
|
||||
func (d *dashboardServer) buildStatus(showAdditional bool) dashboardStatus {
|
||||
status := dashboardStatus{Now: time.Now()}
|
||||
self := d.node.core.GetSelf()
|
||||
subnet := d.node.core.Subnet()
|
||||
|
|
@ -184,23 +205,24 @@ func (d *dashboardServer) handleStatus(w http.ResponseWriter, _ *http.Request) {
|
|||
})
|
||||
}
|
||||
sort.Slice(status.Peers, func(i, j int) bool { return status.Peers[i].URI < status.Peers[j].URI })
|
||||
for _, s := range d.node.core.GetSessions() {
|
||||
status.Sessions = append(status.Sessions, dashboardFlow{
|
||||
IP: keyToIP(s.Key),
|
||||
RX: s.RXBytes,
|
||||
TX: s.TXBytes,
|
||||
Uptime: s.Uptime.String(),
|
||||
})
|
||||
}
|
||||
for _, p := range d.node.core.GetPaths() {
|
||||
status.Paths = append(status.Paths, dashboardPath{IP: keyToIP(p.Key), Path: p.Path})
|
||||
}
|
||||
for _, t := range d.node.core.GetTree() {
|
||||
status.Tree = append(status.Tree, dashboardTree{IP: keyToIP(t.Key), Parent: keyToIP(t.Parent)})
|
||||
if showAdditional {
|
||||
for _, s := range d.node.core.GetSessions() {
|
||||
status.Sessions = append(status.Sessions, dashboardFlow{
|
||||
IP: keyToIP(s.Key),
|
||||
RX: s.RXBytes,
|
||||
TX: s.TXBytes,
|
||||
Uptime: s.Uptime.String(),
|
||||
})
|
||||
}
|
||||
for _, p := range d.node.core.GetPaths() {
|
||||
status.Paths = append(status.Paths, dashboardPath{IP: keyToIP(p.Key), Path: p.Path})
|
||||
}
|
||||
for _, t := range d.node.core.GetTree() {
|
||||
status.Tree = append(status.Tree, dashboardTree{IP: keyToIP(t.Key), Parent: keyToIP(t.Parent)})
|
||||
}
|
||||
}
|
||||
status.Banned = d.bannedList()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(status)
|
||||
return status
|
||||
}
|
||||
|
||||
func (d *dashboardServer) handlePeerTraffic(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ svg.port-icon { width: 24px; height: 24px; }
|
|||
svg.signal-icon { width: 16px; height: 16px; }
|
||||
.signal-bar { fill: #ddd; transition: fill 0.2s; }
|
||||
.signal-bar.active { fill: var(--network-green); }
|
||||
.signal-icon.offline .signal-bar.active { fill: #9ca3af; }
|
||||
|
||||
.graph-container { width: 100%; height: 220px; background: #fafafa; border: 1px solid var(--border-color); border-radius: 4px; overflow: hidden; }
|
||||
canvas#trafficGraph { width: 100%; height: 100%; display: block; }
|
||||
|
|
@ -360,6 +361,24 @@ canvas#trafficGraph { width: 100%; height: 100%; display: block; }
|
|||
body { padding: 12px; }
|
||||
.grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
.project-board {
|
||||
margin-top: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
background: #fff;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.project-board a {
|
||||
color: var(--text-main);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
.project-board a:hover { text-decoration: underline; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -413,6 +432,14 @@ canvas#trafficGraph { width: 100%; height: 100%; display: block; }
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="project-board">
|
||||
<span aria-hidden="true"><strong>Git</strong></span>
|
||||
<span>
|
||||
Kaya source:
|
||||
<a href="https://git.protogen.engineering/racks/kaya-go" target="_blank" rel="noopener noreferrer">https://git.protogen.engineering/racks/kaya-go</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Tooltip Element -->
|
||||
<div id="tooltipEl" class="tooltip"></div>
|
||||
|
||||
|
|
@ -701,7 +728,10 @@ function buildPeersTable(peers) {
|
|||
// Calculate signal strength (0-4, where 4 is best/lowest cost)
|
||||
const cost = safeNum(p.cost);
|
||||
let signalStrength = 0;
|
||||
if (maxCost !== minCost) {
|
||||
const isDownWithZeroCost = !p.up && cost === 0;
|
||||
if (isDownWithZeroCost) {
|
||||
signalStrength = 4;
|
||||
} else if (maxCost !== minCost) {
|
||||
const normalized = (maxCost - cost) / (maxCost - minCost); // 0 (worst/highest cost) to 1 (best/lowest cost)
|
||||
signalStrength = Math.round(normalized * 4); // 0-4
|
||||
} else {
|
||||
|
|
@ -709,11 +739,12 @@ function buildPeersTable(peers) {
|
|||
}
|
||||
if (signalStrength < 0) signalStrength = 0;
|
||||
if (signalStrength > 4) signalStrength = 4;
|
||||
const signalStateClass = isDownWithZeroCost ? ' offline' : '';
|
||||
|
||||
// Generate cell phone signal icon SVG based on signal strength (0-4)
|
||||
const signalIconHtml =
|
||||
'<div class="signal-icon-wrapper">' +
|
||||
'<svg class="signal-icon" viewBox="0 0 16 16" aria-hidden="true">' +
|
||||
'<svg class="signal-icon' + signalStateClass + '" viewBox="0 0 16 16" aria-hidden="true">' +
|
||||
// Bar 1 (smallest) - shown when signalStrength >= 1
|
||||
'<rect class="signal-bar' + (signalStrength >= 1 ? ' active' : '') + '" x="1" y="11" width="2.5" height="4" rx="0.5" />' +
|
||||
// Bar 2 - shown when signalStrength >= 2
|
||||
|
|
|
|||
1097
cmd/yggdrasil/dashboard_public.html
Normal file
1097
cmd/yggdrasil/dashboard_public.html
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue