Something went wrong. Try again.
honestly just guess what it does. You're probably right.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283package main
import ( "context" "flag" "fmt" "os" "os/signal" "path/filepath" "syscall" "time"
"tsbutt/tsbridge")
func main() { addr := flag.String("addr", "127.0.0.1:8484", "plain-HTTP listen address (non-tsnet mode)") intiface := flag.String("intiface", tsbridge.DefaultIntifaceTarget, "ws:// or wss:// URL of Intiface Central's WebSocket server (e.g. ws://localhost:12345)") useTsnet := flag.Bool("tsnet", false, "serve over tsnet instead of plain HTTP (requires tailnet auth)") stateDir := flag.String("state-dir", "", "tsnet state directory (default: ~/.local/state/tsbutt — keep it persistent: tsnet stores node identity AND the Let's Encrypt cert cache there; wiping it re-requests a cert on every start and burns ACME rate limits)") hostname := flag.String("hostname", "tsbutt-desktop", "tsnet hostname (becomes <hostname>.<tailnet>.ts.net)") authKey := flag.String("authkey", "", "tailnet auth key; a Tailscale OAuth client secret (tskey-client-...) also works and mints a key via OAuth — requires -advertise-tags. Empty = interactive login URL on stderr") tags := flag.String("advertise-tags", "", "comma-separated tailnet tags to apply (required when -authkey is an OAuth client secret, e.g. tag:server)") servePort := flag.Int("port", 443, "HTTPS port to serve on in tsnet mode; the same handler is also served over plain HTTP on :80 (443 works: userspace netstack needs no privileges)") cors := flag.Bool("cors", false, "allow cross-origin browser connections (CORS); off by default — enabling lets ANY web page open this server's WebSocket") webappDir := flag.String("webapp", "webapp", "directory whose files are served as the webapp (must contain index.html; e.g. the repo's webapp/ directory)") flag.Parse()
if *cors { if err := tsbridge.SetCORS(true); err != nil { fmt.Fprintln(os.Stderr, "cors:", err) os.Exit(1) } }
if *useTsnet { stateDir := *stateDir if stateDir == "" { // Must persist across runs: tsnet keeps both the node identity // and the Let's Encrypt cert cache (Dir/certs) here. Losing them // means a fresh node and re-issued certs on every start, which // burns ACME rate limits. base := os.Getenv("XDG_STATE_HOME") if base == "" { home, err := os.UserHomeDir() if err != nil { fmt.Fprintln(os.Stderr, "-state-dir required (cannot determine home dir):", err) os.Exit(1) } base = filepath.Join(home, ".local", "state") } stateDir = filepath.Join(base, "tsbutt") } if err := tsbridge.Start(stateDir, os.TempDir(), *hostname, *authKey, *tags, int32(*servePort), *intiface, *webappDir); err != nil { fmt.Fprintln(os.Stderr, "tsnet:", err) os.Exit(1) } // Block until interrupted, polling status so the operator can see // the login URL and the resulting ts.net address. ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() last := "" for { select { case <-ctx.Done(): tsbridge.Stop() return case <-time.After(2 * time.Second): if cur := tsbridge.Status(); cur != last { last = cur fmt.Fprintln(os.Stderr, cur) } } } }
if err := tsbridge.ServePlain(*addr, *intiface, *webappDir); err != nil { fmt.Fprintln(os.Stderr, "server:", err) os.Exit(1) }}