Skip to content

Commit

Permalink
Remove obsolete dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Jan 18, 2023
1 parent 9151f2d commit e5a28b1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 67 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module git.sr.ht/~rumpelsepp/webcat
go 1.15

require (
git.sr.ht/~rumpelsepp/helpers v0.0.0-20210107155038-e696fad094b7
git.sr.ht/~sircmpwn/getopt v1.0.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
golang.org/x/crypto v0.5.0 // indirect
github.com/spf13/pflag v1.0.5
)
47 changes: 2 additions & 45 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
git.sr.ht/~rumpelsepp/helpers v0.0.0-20210107155038-e696fad094b7 h1:jgf2q+9kG6I3PsMJ+5niEnWxT3n1SChGbnvdpIdi2W8=
git.sr.ht/~rumpelsepp/helpers v0.0.0-20210107155038-e696fad094b7/go.mod h1:Xu4ywdHjvI4npqLSosaHH2dDBueUBrd23XgeQLxWPLA=
git.sr.ht/~sircmpwn/getopt v1.0.0 h1:/pRHjO6/OCbBF4puqD98n6xtPEgE//oq5U8NXjP7ROc=
git.sr.ht/~sircmpwn/getopt v1.0.0/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
56 changes: 56 additions & 0 deletions io.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"fmt"
"io"
"sync"
)

func bidirectCopy(left io.ReadWriteCloser, right io.ReadWriteCloser) (int, int, error) {
var (
n1 = 0
n2 = 0
err error
err1 error
err2 error
wg sync.WaitGroup
)

wg.Add(2)

go func() {
if n, err := io.Copy(right, left); err != nil {
err1 = err
} else {
n1 = int(n)
}

right.Close()
wg.Done()
}()

go func() {
if n, err := io.Copy(left, right); err != nil {
err2 = err
} else {
n2 = int(n)
}

left.Close()
wg.Done()
}()

wg.Wait()

if err1 != nil && err2 != nil {
err = fmt.Errorf("both copier failed; left: %s; right: %s", err1, err2)
} else {
if err1 != nil {
err = err1
} else if err2 != nil {
err = err2
}
}

return n1, n2, err
}
29 changes: 10 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"strings"
"time"

"git.sr.ht/~rumpelsepp/helpers"
"git.sr.ht/~sircmpwn/getopt"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/spf13/pflag"
)

type stdioWrapper struct {
Expand Down Expand Up @@ -75,7 +74,7 @@ func (p *proxy) handleWS(w http.ResponseWriter, r *http.Request) {
}
c2 = c
}
helpers.BidirectCopy(c1, c2)
bidirectCopy(c1, c2)
}

type runtimeOptions struct {
Expand All @@ -90,21 +89,13 @@ type runtimeOptions struct {

func main() {
opts := runtimeOptions{}
getopt.StringVar(&opts.header, "H", "", "Specify request header")
getopt.IntVar(&opts.keepalive, "k", 0, "Set ping interval in seconds")
getopt.StringVar(&opts.fingerprint, "f", "", "Set SHA-256 fingerprint of certificate")
getopt.StringVar(&opts.listen, "l", "", "Set listen address")
getopt.StringVar(&opts.listenPath, "p", "/ws", "Set uri path")
getopt.StringVar(&opts.target, "t", "-", "Set target to proxy or connect to")
h := getopt.Bool("h", false, "Show this page and exit")
if err := getopt.Parse(); err != nil {
panic(err)
}

if *h {
getopt.Usage()
os.Exit(0)
}
pflag.StringVarP(&opts.header, "header", "H", "", "Specify request header")
pflag.IntVarP(&opts.keepalive, "keepalive", "k", 0, "Set ping interval in seconds")
pflag.StringVarP(&opts.fingerprint, "fingerprint", "f", "", "Set SHA-256 fingerprint of certificate")
pflag.StringVarP(&opts.listen, "listen", "l", "", "Set listen address")
pflag.StringVarP(&opts.listenPath, "path", "p", "/ws", "Set uri path")
pflag.StringVarP(&opts.target, "target", "t", "-", "Set target to proxy or connect to")
pflag.Parse()

if opts.listen != "" {
p := proxy{
Expand Down Expand Up @@ -169,6 +160,6 @@ func main() {
if opts.keepalive > 0 {
go c.SetKeepAlive(time.Duration(opts.keepalive) * time.Second)
}
helpers.BidirectCopy(c, s)
bidirectCopy(c, s)
}
}

0 comments on commit e5a28b1

Please sign in to comment.