/** * Send authentication * * @return bool */ protected function _auth() { // check to see if already authenticated if ($this->_authenticated === true) { return true; } switch ($this->config('ssh.authType')) { case 'password': // perform password auth if (@ssh2_auth_password($this->_connection, $this->_credentials->getUsername(), $this->_credentials->getPassword())) { $this->_authenticated = true; return true; } break; case 'publicKey': // perform public key auth $this->_writeTmpKeys(); if (@ssh2_auth_pubkey_file($this->_connection, $this->_credentials->getUsername(), $this->_pubKeyTempFile, $this->_privKeyTempFile)) { $this->_authenticated = true; $this->_destroyTmpKeys(); return true; } $this->_destroyTmpKeys(); break; } //end switch() //return false; throw new \Exception('SSH ' . $this->config('ssh.authType') . ' Authentication Failed'); }
/** * testConstructProcedural method * * @return void */ public function testConstructProcedural() { $Creds = new Credentials(); $Creds->setUsername('admin'); $this->assertEquals($Creds->getUsername(), 'admin'); $Creds->setPassword('abc123'); $this->assertEquals($Creds->getPassword(), 'abc123'); $this->assertSame($Creds->get(), array('username' => 'admin', 'password' => 'abc123')); }
/** * Send authentication * * @return bool */ protected function _auth() { // check to see if already authenticated if ($this->_authenticated === true) { return true; } switch ($this->config('ssh.authType')) { case 'password': // perform password auth if ($this->_phpseclib->login($this->_credentials->getUsername(), $this->_credentials->getPassword())) { //get last line and set as prompt $response = $this->_phpseclib->read($this->config('prompt.command')); $lines = split("\n", $response); $this->config('prompt.command', trim(end($lines))); $this->_authenticated = true; return true; } break; case 'publicKey': // perform public key auth $this->_writeTmpKeys(); $privkey = new \Crypt_RSA(); //phpseclib has no DSA support :( $privkey->loadKey($this->_pubKeyTempFile); if ($this->_phpseclib->login($this->_credentials->getUsername(), $privkey)) { $this->_destroyTmpKeys(); $this->_authenticated = true; return true; } $this->_destroyTmpKeys(); break; } //end switch() //return false; throw new \Exception('SSH ' . $this->config('ssh.authType') . ' Authentication Failed'); }
/** * Send authentication * * @return void * @throws \NetDeviceLib\Net\Error\SocketException */ protected function _auth() { if ($this->authenticated) { return true; } //Expect <<prompt>> send <<command>><<cr><<lf>> $this->expect('ogin:')->send('figpal2'); //Expect <<prompt>> send <<command>><<cr><<lf>> Expect <<failPrompt>> or <<successPrompt>> $this->expect('assword:')->send('figpal2'); /*->fail('ogin failed', function($response) { throw new TelnetException('Authentication Failed'); }) ->success('/\[(.*)@(.*)\]\s>/', function($response) { $this->authenticated = true; });*/ //Expect <<prompt>> send <<command>><<cr><<lf>> read Data until <<prompt>> Return <<response>>-<<prompt>> //$config = $this->expect('>')->send('export')->readTo('>'); //echo "\n\n\$config=\n" . $config . "\n\n\n"; //Send <<command>><<cr><<lf>> read Data until <<prompt>> Return <<response>>-<<prompt>> $foo = $this->readTo('>'); echo $foo; $this->send('/user print'); $info = $this->readTo('>'); echo $info; $this->send('/user print'); $info = $this->readTo('>'); echo $info; exit; //Send <<command>><<cr><<lf>> read Data until <<timeout>> exceeded //$info2 = $this->send('/system routerboard print')->read( $timeout = 2 ); //end testing $this->read($this->config('prompt.username')); $this->execute($this->_credentials->getUsername()); //echo "Sent username\n"; $this->read($this->config('prompt.password')); $this->execute($this->_credentials->getPassword()); //echo "Sent password\n"; $response = $this->read(); if (preg_match('/(' . $this->config('prompt.noauth') . ')/', $response)) { return $this->authenticated = false; } return $this->authenticated = true; }