Skip to content
Permalink
Browse files

Started work on new formatting

  • Loading branch information
antoniomika committed Nov 23, 2019
1 parent a68ab2d commit f2334f81e42ead0560a2b41fd50fcd459a919dd1
Showing with 37 additions and 14 deletions.
  1. +2 −1 .gitignore
  2. BIN __debug_bin
  3. +3 −2 channels.go
  4. +1 −0 go.mod
  5. +2 −0 go.sum
  6. +10 −3 main.go
  7. +19 −8 requests.go
@@ -7,4 +7,5 @@ ssl/*
sish
deploy/*
!deploy/docker-compose.yml
dist/
dist/
__debug_bin
BIN -16.4 MB __debug_bin
Binary file not shown.
@@ -7,6 +7,7 @@ import (
"net"
"strings"

"github.com/logrusorgru/aurora"
"golang.org/x/crypto/ssh"
)

@@ -28,7 +29,7 @@ func handleSession(newChannel ssh.NewChannel, sshConn *SSHConnection, state *Sta
select {
case c := <-sshConn.Messages:
_, err := connection.Write(append([]byte(c), []byte{'\r', '\n'}...))
if err != nil {
if err != nil && *debug {
log.Println("Error trying to write message to socket:", err)
}
case <-sshConn.Close:
@@ -37,7 +38,7 @@ func handleSession(newChannel ssh.NewChannel, sshConn *SSHConnection, state *Sta
}
}()

sshConn.Messages <- "Press Ctrl-C to close the session."
sshConn.Messages <- aurora.BgRed("Press Ctrl-C to close the session.").String()

go func() {
for {
1 go.mod
@@ -9,6 +9,7 @@ require (
github.com/jpillora/ipfilter v1.0.0
github.com/json-iterator/go v1.1.8 // indirect
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/oschwald/maxminddb-golang v1.5.0 // indirect
github.com/pires/go-proxyproto v0.0.0-20190615163442-2c19fd512994
2 go.sum
@@ -22,6 +22,8 @@ github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46O
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c h1:N7A4JCA2G+j5fuFxCsJqjFU/sZe0mj8H0sSoSwbaikw=
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c/go.mod h1:Nn5wlyECw3iJrzi0AhIWg+AJUb4PlRQVW4/3XHH1LZA=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23 h1:Wp7NjqGKGN9te9N/rvXYRhlVcrulGdxnz8zadXWs7fc=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
13 main.go
@@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"runtime"
"strconv"
"strings"
"sync"
"time"
@@ -40,11 +41,11 @@ var (
version = "dev"
commit = "none"
date = "unknown"
httpPort int
httpsPort int
serverAddr = flag.String("sish.addr", "localhost:2222", "The address to listen for SSH connections")
httpAddr = flag.String("sish.http", "localhost:80", "The address to listen for HTTP connections")
httpPort = flag.Int("sish.httpport", 80, "The port for HTTP connections. This is only for output messages")
httpsAddr = flag.String("sish.https", "localhost:443", "The address to listen for HTTPS connections")
httpsPort = flag.Int("sish.httpsport", 443, "The port for HTTPS connections. This is only for output messages")
verifyOrigin = flag.Bool("sish.verifyorigin", true, "Whether or not to verify origin on websocket connection")
verifySSL = flag.Bool("sish.verifyssl", true, "Whether or not to verify SSL on proxy connection")
httpsEnabled = flag.Bool("sish.httpsenabled", false, "Whether or not to listen for HTTPS connections")
@@ -80,8 +81,14 @@ var (
func main() {
flag.Parse()

_, httpPortString, err := net.SplitHostPort(*httpAddr)
_, httpsPortString, err := net.SplitHostPort(*httpsAddr)

httpPort, err = strconv.Atoi(httpPortString)
httpsPort, err = strconv.Atoi(httpsPortString)

if *versionCheck {
log.Printf("Version: %v\nCommit: %v\nDate: %v\n", version, commit, date)
log.Printf("\nVersion: %v\nCommit: %v\nDate: %v\n", version, commit, date)
os.Exit(0)
}

@@ -11,6 +11,7 @@ import (
"sync"
"time"

"github.com/logrusorgru/aurora"
"github.com/pires/go-proxyproto"
"golang.org/x/crypto/ssh"
)
@@ -107,7 +108,7 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
connType = "https"
}

requestMessages := fmt.Sprintf("\nStarting SSH Fowarding service for %s:%s. Forwarded connections can be accessed via the following methods:\r\n", connType, stringPort)
requestMessages := fmt.Sprintf("\nStarting SSH Fowarding service for %s. Forwarded connections can be accessed via the following methods:\r\n", aurora.Sprintf(aurora.Green("%s:%s"), connType, stringPort))

if stringPort == "80" || stringPort == "443" {
scheme := "http"
@@ -126,10 +127,20 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
state.HTTPListeners.Store(host, pH)
defer state.HTTPListeners.Delete(host)

requestMessages += fmt.Sprintf("HTTP: http://%s:%d\r\n", host, *httpPort)
httpPortString := ""
if httpPort == 80 {
httpPortString = fmt.Sprintf(":%d", httpPort)
}

requestMessages += fmt.Sprintf("%s: http://%s%s\r\n", aurora.BgBlue("HTTP"), host, httpPortString)

if *httpsEnabled {
requestMessages += fmt.Sprintf("HTTPS: https://%s:%d", host, *httpsPort)
httpsPortString := ""
if httpsPort == 443 {
httpsPortString = fmt.Sprintf(":%d", httpsPort)
}

requestMessages += fmt.Sprintf("%s: https://%s%s", aurora.BgBlue("HTTPS"), host, httpsPortString)
}
} else {
if handleTCPAliasing {
@@ -138,9 +149,9 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
state.TCPListeners.Store(validAlias, chanListener.Addr().String())
defer state.TCPListeners.Delete(validAlias)

requestMessages += fmt.Sprintf("TCP Alias: %s", validAlias)
requestMessages += fmt.Sprintf("%s: %s", aurora.BgBlue("TCP Alias"), validAlias)
} else {
requestMessages += fmt.Sprintf("TCP: %s:%d", *rootDomain, chanListener.Addr().(*net.TCPAddr).Port)
requestMessages += fmt.Sprintf("%s: %s:%d", aurora.BgBlue("TCP"), *rootDomain, chanListener.Addr().(*net.TCPAddr).Port)
}
}

@@ -197,7 +208,7 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
}

_, err := proxyProtoHeader.WriteTo(newChan)
if err != nil {
if err != nil && *debug {
log.Println("Error writing to channel:", err)
}
}
@@ -225,7 +236,7 @@ func copyBoth(writer net.Conn, reader ssh.Channel, wait bool) {
}

_, err := io.Copy(writer, reader)
if err != nil {
if err != nil && *debug {
log.Println("Error writing to reader:", err)
}
}()
@@ -237,7 +248,7 @@ func copyBoth(writer net.Conn, reader ssh.Channel, wait bool) {
}

_, err := io.Copy(reader, writer)
if err != nil {
if err != nil && *debug {
log.Println("Error writing to writer:", err)
}
if wait {

0 comments on commit f2334f8

Please sign in to comment.
You can’t perform that action at this time.