public function testLoginPasswordFailed() { $configuration = new Configuration('localhost'); $session = new Session($configuration); $authentication = new Password(TEST_USER, 'invalid'); $login = $authentication->authenticate($session->getResource()); $this->assertFalse($login, 'Authentification should have failed.'); }
protected function setUp() { $this->configuration = new Configuration('localhost'); $this->auth = new Password(TEST_USER, TEST_PASSWORD); $this->session = new Session($this->configuration, $this->auth); $this->sftp = $this->session->getSftp(); $this->createFixtures(); }
/** * @expectedException \RuntimeException */ public function testExecuteErrorOutput() { $configuration = new Configuration('localhost'); $authentication = new Password(TEST_USER, TEST_PASSWORD); $session = new Session($configuration, $authentication); $exec = $session->getExec(); $output = $exec->run('false'); $this->assertEquals('', trim($output)); }
/** * {@inheritdoc} */ public function download($local, $remote) { $this->checkConnection(); if (!$this->session->getSftp()->receive($remote, $local)) { throw new \RuntimeException('Can not download file.'); } }
/** * @Route("/pydf/{serverId}", name="pydf") */ public function pydfAction($serverId) { $server = $this->getDoctrine()->getRepository('iTransactDatabaseBundle:Server')->findOneById($serverId); $conf = new Ssh\Configuration($server->getHost()); $auth = new Ssh\Authentication\Password($server->getUsername(), $server->getPassword()); $session = new Ssh\Session($conf, $auth); $exec = $session->getExec(); $pydf = $exec->run('pydf'); $totalDiskSpace = 0; $totalDiskTaken = 0; //REMOVE COLOURS AND ADDITIONAL BRACKETS $find = ['0m', '33m', ']', '[', '?', '0x1B']; $replace = ['']; $pydf = str_replace($find, $replace, $pydf); $pydf = explode(PHP_EOL, $pydf); //REMOVE EMPTY LINES AND TOP LINE WITH HEADERS foreach ($pydf as $key => $line) { if ($line == "") { unset($pydf[$key]); } } unset($pydf[0]); //REMOVE FUNNY AND UNICODE CHARACTERS $pydf = preg_replace('/[\\x00-\\x1F\\x80-\\xFF]/', '', $pydf); foreach ($pydf as $key => $line) { if ($line[1] . $line[2] . $line[3] == 'dev') { $line = array_values(array_filter(explode(' ', $line))); $totalDiskSpace += $this->unitToValueIndex(1, $line); $totalDiskTaken += $this->unitToValueIndex(2, $line); } } $percentage = 100 * $totalDiskTaken / $totalDiskSpace; $response = new Response(json_encode(json_encode(array('percentage' => number_format($percentage, 2))))); $response->headers->set('Content-Type', 'application/json'); return $response; }
/** * Gets the SSH session executor * @return \Ssh\Exec */ public function getExec() { return $this->session->getExec(); }
/** * Execute the command string * * @param $command string */ protected function execute($command) { $exec = $this->sshSession->getExec(); $exec->run($command); }