-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25ee960
commit 278d55f
Showing
5 changed files
with
109 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dashboard | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/almeidapaulopt/tsdproxy/internal/core" | ||
"github.com/almeidapaulopt/tsdproxy/internal/proxymanager" | ||
) | ||
|
||
type Dashboard struct { | ||
Log *core.Logger | ||
HTTP *core.HTTPServer | ||
Config *core.Config | ||
proxies proxymanager.ProxyList | ||
} | ||
|
||
func NewDashboard(http *core.HTTPServer, log *core.Logger, cfg *core.Config, pl proxymanager.ProxyList) *Dashboard { | ||
return &Dashboard{ | ||
Log: log, | ||
HTTP: http, | ||
Config: cfg, | ||
proxies: pl, | ||
} | ||
} | ||
|
||
func (dash *Dashboard) AddRoutes() { | ||
dash.HTTP.Handle("GET /", dash.index()) | ||
} | ||
|
||
func (dash *Dashboard) index() http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body>`)) | ||
for _, p := range dash.proxies { | ||
w.Write([]byte(p.URL.String() + "\n")) | ||
} | ||
w.Write([]byte(`</body></html>`)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,45 @@ | ||
package tailscale | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/almeidapaulopt/tsdproxy/internal/core" | ||
tsclient "tailscale.com/client/tailscale" | ||
"tailscale.com/tsnet" | ||
) | ||
|
||
type TsNetServer struct { | ||
TsServer *tsnet.Server | ||
TsServer *tsnet.Server | ||
LocalClient *tsclient.LocalClient | ||
} | ||
|
||
func NewTsNetServer(hostname string, config *core.Config, logger *core.Logger) *TsNetServer { | ||
return &TsNetServer{ | ||
&tsnet.Server{ | ||
Hostname: hostname, | ||
AuthKey: config.AuthKey, | ||
Dir: filepath.Join(config.DataDir, hostname), | ||
Ephemeral: true, | ||
Logf: func(format string, args ...any) { | ||
logger.Trace().Msgf(format, args...) | ||
}, | ||
UserLogf: func(format string, args ...any) { | ||
logger.Trace().Msgf(format, args...) | ||
}, | ||
func NewTsNetServer(hostname string, config *core.Config, logger *core.Logger) (*TsNetServer, error) { | ||
tserver := &tsnet.Server{ | ||
Hostname: hostname, | ||
AuthKey: config.AuthKey, | ||
Dir: filepath.Join(config.DataDir, hostname), | ||
Ephemeral: true, | ||
RunWebClient: true, | ||
Logf: func(format string, args ...any) { | ||
logger.Trace().Msgf(format, args...) | ||
}, | ||
UserLogf: func(format string, args ...any) { | ||
logger.Trace().Msgf(format, args...) | ||
}, | ||
} | ||
} | ||
|
||
func (tn *TsNetServer) Close() error { | ||
return tn.TsServer.Close() | ||
} | ||
|
||
func (tn *TsNetServer) Start(ctx context.Context) error { | ||
if err := tn.TsServer.Start(); err != nil { | ||
return fmt.Errorf("error starting server: %w", err) | ||
lc, err := tserver.LocalClient() | ||
if err != nil { | ||
return nil, fmt.Errorf("error starting tailscale server: %w", err) | ||
} | ||
|
||
// Wait for tailscale to come up... | ||
if _, err := tn.TsServer.Up(ctx); err != nil { | ||
return fmt.Errorf("error to come up server: %w", err) | ||
} | ||
return &TsNetServer{ | ||
tserver, | ||
lc, | ||
}, nil | ||
} | ||
|
||
return tn.TsServer.Start() | ||
func (tn *TsNetServer) Close() error { | ||
return tn.TsServer.Close() | ||
} |