check: stop current check process when timeout (#159)

This commit is contained in:
nadoo 2020-05-04 15:33:26 +08:00
parent 061b3da42e
commit 3392db41de
3 changed files with 14 additions and 7 deletions

View File

@ -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`

View File

@ -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
}

View File

@ -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()