mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 08:07:42 +00:00
ipn/ipnlocal/peerapi: add endpoint to list local interfaces
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
1aa75b1c9e
commit
637cc1b5fc
@ -567,6 +567,9 @@ func (h *peerAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case "/v0/wol":
|
case "/v0/wol":
|
||||||
h.handleWakeOnLAN(w, r)
|
h.handleWakeOnLAN(w, r)
|
||||||
return
|
return
|
||||||
|
case "/v0/interfaces":
|
||||||
|
h.handleServeInterfaces(w, r)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
who := h.peerUser.DisplayName
|
who := h.peerUser.DisplayName
|
||||||
fmt.Fprintf(w, `<html>
|
fmt.Fprintf(w, `<html>
|
||||||
@ -581,6 +584,40 @@ func (h *peerAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *peerAPIHandler) handleServeInterfaces(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !h.canDebug() {
|
||||||
|
http.Error(w, "denied; no debug access", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
i, err := interfaces.GetList()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
dr, err := interfaces.DefaultRoute()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
fmt.Fprintln(w, "<h1>Interfaces</h1>")
|
||||||
|
fmt.Fprintf(w, "<h3>Default route is %q(%d)</h3>\n", dr.InterfaceName, dr.InterfaceIndex)
|
||||||
|
|
||||||
|
fmt.Fprintln(w, "<table>")
|
||||||
|
fmt.Fprint(w, "<tr>")
|
||||||
|
for _, v := range []any{"Index", "Name", "MTU", "Flags", "Addrs"} {
|
||||||
|
fmt.Fprintf(w, "<th>%v</th> ", v)
|
||||||
|
}
|
||||||
|
fmt.Fprint(w, "</tr>\n")
|
||||||
|
i.ForeachInterface(func(iface interfaces.Interface, ipps []netaddr.IPPrefix) {
|
||||||
|
fmt.Fprint(w, "<tr>")
|
||||||
|
for _, v := range []any{iface.Index, iface.Name, iface.MTU, iface.Flags, ipps} {
|
||||||
|
fmt.Fprintf(w, "<td>%v</td> ", v)
|
||||||
|
}
|
||||||
|
fmt.Fprint(w, "</tr>\n")
|
||||||
|
})
|
||||||
|
fmt.Fprintln(w, "</table>")
|
||||||
|
}
|
||||||
|
|
||||||
type incomingFile struct {
|
type incomingFile struct {
|
||||||
name string // "foo.jpg"
|
name string // "foo.jpg"
|
||||||
started time.Time
|
started time.Time
|
||||||
|
Loading…
x
Reference in New Issue
Block a user