feat: tunnel host and port in the panel settings, ufw kept in sync
The direct tunnel port (8446 by default) and the host agents dial for it can be set in Settings. The server moves its listeners at once and agents pick the address up from the panel: on connect and with every poll, unless TUNNEL_ADDR / TUNNEL_PORT pin it locally. ufw: run with a C locale (the output is translated), do not adopt rules that existed before the panel, skip loopback-only listeners, re-open what saved forwards need on start and when the integration is turned on, move the shared tunnel rule with the port and drop it when no direct forward is left. The last ufw error is shown in Settings. The forwards page shows the real tunnel and panel ports.
This commit is contained in:
1 parent
08fc2d79a8
commit
bcfe909aaa
15 files changed
+540
-97
No files matched your search
@@ -39,6 +39,7 @@ func readLine(r io.Reader, max int) (string, error) {
|
||||
type tunnelHub struct {
|
||||
db *DB
|
||||
mu sync.Mutex
|
||||
ln net.Listener
|
||||
agents map[string]*agentTunnel
|
||||
}
|
||||
|
||||
@@ -57,12 +58,30 @@ type agentTunnel struct {
|
||||
streams map[uint32]net.Conn
|
||||
}
|
||||
|
||||
// listen runs the 8446 TCP tunnel acceptor until the listener closes.
|
||||
// listen runs the TCP tunnel acceptor until the listener closes. Listening
|
||||
// again moves the tunnel: the previous listener is closed and its agents are
|
||||
// dropped, so they redial the new address.
|
||||
func (h *tunnelHub) listen(addr string) error {
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.mu.Lock()
|
||||
old := h.ln
|
||||
h.ln = ln
|
||||
var stale []*agentTunnel
|
||||
if old != nil {
|
||||
for _, at := range h.agents {
|
||||
stale = append(stale, at)
|
||||
}
|
||||
}
|
||||
h.mu.Unlock()
|
||||
if old != nil {
|
||||
old.Close()
|
||||
}
|
||||
for _, at := range stale {
|
||||
at.conn.Close()
|
||||
}
|
||||
log.Printf("tunnel: listening on %s (direct TCP forwarding)", addr)
|
||||
go func() {
|
||||
for {
|
||||
|
||||
Reference in new issue
Block a user