Пример #1
0
func proxyGo(host *config.Host) error {
	if host.Host == "" {
		host.Host = host.Name
	}

	if len(host.ResolveNameservers) > 0 {
		logrus.Debugf("Resolving host: '%s' using nameservers %s", host.Host, host.ResolveNameservers)
		// FIXME: resolve using custom dns server
		results, err := net.LookupAddr(host.Host)
		if err != nil {
			return err
		}
		if len(results) > 0 {
			host.Host = results[0]
		}
		logrus.Debugf("Resolved host is: %s", host.Host)
	}
	if host.ResolveCommand != "" {
		command := commandApplyHost(host.ResolveCommand, host)
		logrus.Debugf("Resolving host: '%s' using command: '%s'", host.Host, command)

		args, err := shlex.Split(command)
		if err != nil {
			return err
		}

		out, err := exec.Command(args[0], args[1:]...).Output()
		if err != nil {
			return err
		}

		host.Host = strings.TrimSpace(fmt.Sprintf("%s", out))
		logrus.Debugf("Resolved host is: %s", host.Host)
	}

	logrus.Debugf("Connecting to %s:%d", host.Host, host.Port)
	conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", host.Host, host.Port))
	if err != nil {
		return err
	}
	defer conn.Close()

	logrus.Debugf("Connected to %s:%d", host.Host, host.Port)

	// Create Stdio pipes
	c1 := readAndWrite(conn, os.Stdout)
	c2 := readAndWrite(os.Stdin, conn)

	select {
	case err = <-c1:
	case err = <-c2:
	}
	if err != nil {
		return err
	}

	return nil
}
Пример #2
0
func proxyCommand(host *config.Host, command string) error {
	command = commandApplyHost(command, host)
	args, err := shlex.Split(command)
	logrus.Debugf("ProxyCommand: %s", command)
	if err != nil {
		return err
	}
	spawn := exec.Command(args[0], args[1:]...)
	spawn.Stdout = os.Stdout
	spawn.Stdin = os.Stdin
	spawn.Stderr = os.Stderr
	return spawn.Run()
}
Пример #3
0
func proxyCommand(host *config.Host, command string) error {
	command = host.ExpandString(command)
	args, err := shlex.Split(command)
	Logger.Debugf("ProxyCommand: %s", command)
	if err != nil {
		return err
	}
	spawn := exec.Command(args[0], args[1:]...)
	spawn.Stdout = os.Stdout
	spawn.Stdin = os.Stdin
	spawn.Stderr = os.Stderr
	return spawn.Run()
}
Пример #4
0
func hostPrepare(host *config.Host) error {
	if host.HostName == "" {
		host.HostName = host.Name()
	}

	if len(host.ResolveNameservers) > 0 {
		Logger.Debugf("Resolving host: '%s' using nameservers %s", host.HostName, host.ResolveNameservers)
		// FIXME: resolve using custom dns server
		results, err := net.LookupAddr(host.HostName)
		if err != nil {
			return err
		}
		if len(results) > 0 {
			host.HostName = results[0]
		}
		Logger.Debugf("Resolved host is: %s", host.HostName)
	}

	if host.ResolveCommand != "" {
		command := host.ExpandString(host.ResolveCommand)
		Logger.Debugf("Resolving host: %q using command: %q", host.HostName, command)

		args, err := shlex.Split(command)
		if err != nil {
			return err
		}

		out, err := exec.Command(args[0], args[1:]...).Output()
		if err != nil {
			return err
		}

		host.HostName = strings.TrimSpace(fmt.Sprintf("%s", out))
		Logger.Debugf("Resolved host is: %s", host.HostName)
	}
	return nil
}