Exemplo n.º 1
0
 protected function _writeTmpKeys()
 {
     $ts = time();
     try {
         $this->_privKeyTempFile = $this->config('tmpPath') . DIRECTORY_SEPARATOR . 'NDL-' . $ts . md5($this->_credentials->getPrivateKey()) . '.key';
         @file_put_contents($this->_privKeyTempFile, $this->_credentials->getPrivateKey());
         $this->_pubKeyTempFile = $this->config('tmpPath') . DIRECTORY_SEPARATOR . 'NDL-' . $ts . md5($this->_credentials->getPublicKey()) . '.pub';
         @file_put_contents($this->_pubKeyTempFile, $this->_credentials->getPublicKey());
     } catch (Exception $e) {
         throw new \Exception('Cannot write to tmpPath: ' . $this->tmpPath);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * testReset method
  *
  * @return void
  */
 public function testReset()
 {
     $Creds = new Credentials(['username' => 'admin', 'password' => 'abc123']);
     $Creds->reset();
     $this->assertSame($Creds->get(), array('username' => '', 'password' => ''));
 }