add scannedVia field to know the way of access such as SSH, local or pseudo (#811)

* add sacnned via

* change scannedVia type to const
This commit is contained in:
sadayuki-matsuno
2019-05-15 13:33:09 +09:00
committed by Kota Kanbe
parent 824fbb6368
commit 53aaea9fe2
5 changed files with 96 additions and 82 deletions

View File

@@ -162,8 +162,7 @@ func exec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (resul
logger := getSSHLogger(log...)
logger.Debugf("Executing... %s", strings.Replace(cmd, "\n", "", -1))
if c.Port == "local" &&
(c.Host == "127.0.0.1" || c.Host == "localhost") {
if isLocalExec(c.Port, c.Host) {
result = localExec(c, cmd, sudo)
} else if conf.Conf.SSHNative {
result = sshExecNative(c, cmd, sudo)
@@ -175,6 +174,10 @@ func exec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (resul
return
}
func isLocalExec(port, host string) bool {
return port == "local" && (host == "127.0.0.1" || host == "localhost")
}
func localExec(c conf.ServerInfo, cmdstr string, sudo bool) (result execResult) {
cmdstr = decorateCmd(c, cmdstr, sudo)
var cmd *ex.Cmd