Esempio n. 1
0
func proxy(host *config.Host, conf *config.Config) error {
	if len(host.Gateways) > 0 {
		Logger.Debugf("Trying gateways: %s", host.Gateways)
		for _, gateway := range host.Gateways {
			if gateway == "direct" {
				err := proxyDirect(host)
				if err != nil {
					Logger.Errorf("Failed to use 'direct' connection")
				}
			} else {
				gatewayHost := conf.GetGatewaySafe(gateway)

				err := prepareHostControlPath(host, gatewayHost)
				if err != nil {
					return err
				}

				if host.ProxyCommand == "" {
					host.ProxyCommand = "nc %h %p"
				}
				// FIXME: dynamically add "-v" flags

				if err = hostPrepare(host); err != nil {
					return err
				}

				command := "ssh %name -- " + host.ExpandString(host.ProxyCommand)

				Logger.Debugf("Using gateway '%s': %s", gateway, command)
				err = proxyCommand(gatewayHost, command)
				if err == nil {
					return nil
				}
				Logger.Errorf("Cannot use gateway '%s': %v", gateway, err)
			}
		}
		return fmt.Errorf("No such available gateway")
	}

	Logger.Debugf("Connecting without gateway")
	return proxyDirect(host)
}
Esempio n. 2
0
func proxy(host *config.Host, conf *config.Config) error {
	if len(host.Gateways) > 0 {
		logrus.Debugf("Trying gateways: %s", host.Gateways)
		for _, gateway := range host.Gateways {
			if gateway == "direct" {
				err := proxyDirect(host)
				if err != nil {
					logrus.Errorf("Failed to use 'direct' connection")
				}
			} else {
				gatewayHost := conf.GetGatewaySafe(gateway)

				err := prepareHostControlPath(host, gatewayHost)
				if err != nil {
					return err
				}

				if host.ProxyCommand == "" {
					host.ProxyCommand = "nc %h %p"
				}
				command := "ssh %name -- " + commandApplyHost(host.ProxyCommand, host)

				logrus.Debugf("Using gateway '%s': %s", gateway, command)
				err = proxyCommand(gatewayHost, command)
				if err == nil {
					return nil
				}
				logrus.Errorf("Cannot use gateway '%s': %v", gateway, err)
			}
		}
		return fmt.Errorf("No such available gateway")
	}

	logrus.Debugf("Connecting without gateway")
	return proxyDirect(host)
}