mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 09:25:41 +08:00
check: stop current check process when timeout (#159)
This commit is contained in:
parent
061b3da42e
commit
3392db41de
@ -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`
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user