summaryrefslogtreecommitdiff
path: root/termshare/internal/forwarder.go_
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2022-03-05 12:53:15 -0700
committerCody Hiar <cody@hiar.ca>2022-03-05 12:53:15 -0700
commit90e2e053d25feabd2dcf384dfc262a8bcdbe3ab8 (patch)
tree8e2799822b4de29014b86ca708123c1dfc8f45f5 /termshare/internal/forwarder.go_
Initial CommitHEADmaster
Diffstat (limited to 'termshare/internal/forwarder.go_')
-rw-r--r--termshare/internal/forwarder.go_37
1 files changed, 37 insertions, 0 deletions
diff --git a/termshare/internal/forwarder.go_ b/termshare/internal/forwarder.go_
new file mode 100644
index 0000000..2ce866f
--- /dev/null
+++ b/termshare/internal/forwarder.go_
@@ -0,0 +1,37 @@
+package main
+
+import (
+ "io"
+ "log"
+
+ "github.com/gliderlabs/ssh"
+)
+
+func main() {
+
+ log.Println("starting ssh server on port 2222...")
+
+ forwardHandler := &ssh.ForwardedTCPHandler{}
+
+ server := ssh.Server{
+ LocalPortForwardingCallback: ssh.LocalPortForwardingCallback(func(ctx ssh.Context, dhost string, dport uint32) bool {
+ log.Println("Accepted forward", dhost, dport)
+ return true
+ }),
+ Addr: ":2222",
+ Handler: ssh.Handler(func(s ssh.Session) {
+ io.WriteString(s, "Remote forwarding available...\n")
+ select {}
+ }),
+ ReversePortForwardingCallback: ssh.ReversePortForwardingCallback(func(ctx ssh.Context, host string, port uint32) bool {
+ log.Println("attempt to bind", host, port, "granted")
+ return true
+ }),
+ RequestHandlers: map[string]ssh.RequestHandler{
+ "tcpip-forward": forwardHandler.HandleSSHRequest,
+ "cancel-tcpip-forward": forwardHandler.HandleSSHRequest,
+ },
+ }
+
+ log.Fatal(server.ListenAndServe())
+}