diff --git a/README.md b/README.md index 45a2080..99d224b 100644 --- a/README.md +++ b/README.md @@ -381,4 +381,4 @@ glider -config CONFIGPATH -listen :8080 -verbose - [conflag](https://github.com/nadoo/conflag): command line and config file parse support - [ArchLinux](https://www.archlinux.org/packages/community/x86_64/glider): a great linux distribution with glider pre-built package -- [urlEncode](https://www.w3schools.com/tags/ref_urlencode.asp): you should encode special characters in your sechme. e.g: `@`->`%40` +- [urlencode](https://www.w3schools.com/tags/ref_urlencode.asp): you should encode special characters in scheme url. e.g: `@`->`%40` diff --git a/proxy/ssh/ssh.go b/proxy/ssh/ssh.go index c2a806d..3c1753d 100644 --- a/proxy/ssh/ssh.go +++ b/proxy/ssh/ssh.go @@ -49,8 +49,13 @@ func NewSSH(s string, d proxy.Dialer, p proxy.Proxy) (*SSH, error) { config.Auth = []ssh.AuthMethod{ssh.Password(pass)} } - if key := privateKeyFile(u.Query().Get("key")); key != nil { - config.Auth = append(config.Auth, key) + if key := u.Query().Get("key"); key != "" { + keyAuth, err := privateKeyAuth(key) + if err != nil { + log.F("[ssh] read key file error: %s", err) + return nil, err + } + config.Auth = append(config.Auth, keyAuth) } ssh := &SSH{ @@ -98,16 +103,16 @@ func (s *SSH) DialUDP(network, addr string) (pc net.PacketConn, writeTo net.Addr return nil, nil, errors.New("ssh client does not support udp") } -func privateKeyFile(file string) ssh.AuthMethod { +func privateKeyAuth(file string) (ssh.AuthMethod, error) { buffer, err := ioutil.ReadFile(file) if err != nil { - return nil + return nil, err } key, err := ssh.ParsePrivateKey(buffer) if err != nil { - return nil + return nil, err } - return ssh.PublicKeys(key) + return ssh.PublicKeys(key), nil } diff --git a/strategy/strategy.go b/strategy/strategy.go index 68a8914..c8a54d5 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -252,6 +252,8 @@ func checkWebSite(fwdr *Forwarder, website string, timeout time.Duration, buf [] } defer rc.Close() + rc.SetDeadline(time.Now().Add(timeout)) + _, err = rc.Write([]byte("GET / HTTP/1.0\r\n\r\n")) if err != nil { fwdr.Disable()