Esempio n. 1
0
 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.');
 }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
 /**
  * @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));
 }
Esempio n. 4
0
 /**
  * {@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;
 }
Esempio n. 6
0
 /**
  * Gets the SSH session executor
  * @return \Ssh\Exec
  */
 public function getExec()
 {
     return $this->session->getExec();
 }
Esempio n. 7
0
 /**
  * Execute the command string
  *
  * @param $command string
  */
 protected function execute($command)
 {
     $exec = $this->sshSession->getExec();
     $exec->run($command);
 }