self.process = pexpect.spawn('/usr/bin/ctf', env={'HOME':expanduser('~')}, timeout=5)
self.process.expect(self.PROMPT)
self.process.sendline('connect to %s' % server)
sw = self.process.expect(['ERROR', 'Username:', 'Connected to (.*) as (.*)'])
if sw == 0:
elif sw == 1:
asked_for_pw = self.process.expect([pexpect.TIMEOUT, 'Password:'])
if not asked_for_pw:
self.process.sendline(user)
self.process.expect('Password:')
self.process.sendline(passwd)
success = self.process.expect(['Password:', self.PROMPT])
if not success:
self.process.close()
raise CTFError('Invalid password')
elif sw == 2:
self.server = self.process.match.groups()[0]
self.user = self.process.match.groups()[1].strip()
else:
info('Could not match any strings, trying to get server and user')
self.server = self.process.match.groups()[0]
self.user = self.process.match.groups()[1].strip()
info('Connected to %s as %s' % (self.server, self.user))