Exemplo n.º 1
0
 /**
  * Create a Command object that will execute the SSH command
  * @param string $remoteCommand Command to run on remote server
  * @return Shell\Command Command instance configured to establish SSH
  * connection and execute the remote command
  */
 public function createShellCommand($remoteCommand)
 {
     $sshCommandStem = 'ssh %s -q -p %s';
     $args = array($this->host, $this->port);
     foreach ($this->options as $option) {
         $sshCommandStem .= ' -o %s';
         $args[] = $option;
     }
     if ($this->user) {
         $sshCommandStem .= ' -l %s';
         $args[] = $this->user;
     }
     if ($this->keyFile) {
         $sshCommandStem .= ' -i %s';
         $args[] = $this->keyFile;
     }
     $sshCommandStem .= ' %s';
     $args[] = $remoteCommand;
     // Put all the args into one array
     array_unshift($args, $sshCommandStem);
     /** @var \Bart\Shell $shell */
     $shell = Diesel::create('Bart\\Shell');
     /** @var \Bart\Shell\Command $cmd */
     return call_user_func_array(array($shell, 'command'), $args);
 }
Exemplo n.º 2
0
 public function testLocateNew_WithReferenceArgs()
 {
     return;
     // This won't work because we can't pass $c as undef because
     // create signature doesn't specify a reference param
     $this->enableDieselDefaults();
     $class = Diesel::create('Bart\\DieselTestClassWithParams', 1, 2, $c);
     $this->assertInstanceOf('Bart\\DieselTestClassWithParams', $class);
     $this->assertEquals('Bart\\DieselTestClassWithParams', $c, 'ref param');
 }
Exemplo n.º 3
0
 public function __construct(array $config)
 {
     $this->host = $config['server'];
     $this->port = $config['port'];
     $this->timeout = $config['timeout'];
     $this->auth_dn = $config['binduser'];
     $this->auth_pwd = $config['bindpw'];
     $this->basedn = $config['basedn'];
     $this->logger = \Logger::getLogger(__CLASS__);
     $this->phpldap = Diesel::create('Bart\\PHPLDAP');
 }
Exemplo n.º 4
0
 /**
  * @return \Bart\Curl Create and configure a new Curl instance
  */
 protected function initCurl()
 {
     // Set default port and update if specified
     $port = substr($this->baseUri, 0, 5) == 'https' ? 443 : 80;
     if (preg_match('#http[s]?://[^:]+:(\\d+)($|/)#', $this->baseUri, $matches)) {
         $port = $matches[1];
     }
     // Bart\Curl does no validation of URLS and simply concats hostURI and path
     // so we will just pass fully validated URI with request
     /** @var \Bart\Curl curler */
     $curler = Diesel::create('\\Bart\\Curl', $this->baseUri, $port);
     if ($this->authMethod !== null) {
         $curler->setAuth($this->username, $this->password, $this->authMethod);
     }
     $curlOpts = array(CURLOPT_TIMEOUT => $this->timeout, CURLOPT_HEADER => true);
     if (!$this->sslPeerVerification) {
         $curlOpts[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curler->setPhpCurlOpts($curlOpts);
     return $curler;
 }