MCPcopy Create free account
hub / github.com/Driver-C/tryssh / tryLoginWithoutCache

Method tryLoginWithoutCache

pkg/control/ssh.go:49–82  ·  view source on GitHub ↗
(user string)

Source from the content-addressed store, hash-verified

47}
48
49func (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.
85func NewSSHController(targetIP string, configuration *config.MainConfig) *SSHController {

Callers 2

TryLoginMethod · 0.95
tryLoginWithCacheMethod · 0.95

Calls 8

GenerateCombinationFunction · 0.92
InfolnFunction · 0.92
UpdateConfigFunction · 0.92
ErrorfFunction · 0.92
ConcurrencyTryToConnectFunction · 0.85
LaunchMethod · 0.65

Tested by

no test coverage detected