(user string)
| 47 | } |
| 48 | |
| 49 | func (sc *SSHController) tryLoginWithoutCache(user string) { |
| 50 | combinations := config.GenerateCombination(sc.targetIP, user, sc.configuration) |
| 51 | launchers := launcher.NewSSHLaunchersByCombinations(combinations, sc.sshTimeout) |
| 52 | connectors := make([]launcher.Connector, len(launchers)) |
| 53 | for i, l := range launchers { |
| 54 | connectors[i] = l |
| 55 | } |
| 56 | hitLaunchers := ConcurrencyTryToConnect(sc.concurrency, connectors) |
| 57 | if len(hitLaunchers) > 0 { |
| 58 | utils.Infoln("Login succeeded. The cache will be added.") |
| 59 | hitLauncher := hitLaunchers[0].(*launcher.SSHLauncher) |
| 60 | newServerCache := launcher.GetConfigFromSSHConnector(&hitLauncher.SSHConnector) |
| 61 | if sc.cacheIsFound { |
| 62 | newServerCache.Alias = sc.configuration.ServerLists[sc.cacheIndex].Alias |
| 63 | utils.Infoln("The old cache will be deleted.") |
| 64 | sc.configuration.ServerLists = append( |
| 65 | sc.configuration.ServerLists[:sc.cacheIndex], sc.configuration.ServerLists[sc.cacheIndex+1:]...) |
| 66 | } |
| 67 | sc.configuration.ServerLists = append(sc.configuration.ServerLists, *newServerCache) |
| 68 | if err := config.UpdateConfig(sc.configuration); err == nil { |
| 69 | utils.Infoln("Cache added.") |
| 70 | if hitLauncher.SSHTimeout < sshClientTimeoutWhenLogin { |
| 71 | hitLauncher.SSHTimeout = sshClientTimeoutWhenLogin |
| 72 | } |
| 73 | if !hitLauncher.Launch() { |
| 74 | utils.Errorf("Login failed.\n") |
| 75 | } |
| 76 | } else { |
| 77 | utils.Errorf("Cache added failed.\n\n") |
| 78 | } |
| 79 | } else { |
| 80 | utils.Errorf("There is no password combination that can log in.\n") |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // NewSSHController creates a new SSHController for the given target IP and configuration. |
| 85 | func NewSSHController(targetIP string, configuration *config.MainConfig) *SSHController { |
no test coverage detected