private function createSshTunnel($parameters) { $sshConfig = $parameters['elastic']['ssh']; // // check params // foreach (['keys', 'sshHost', 'user'] as $k) { // if (empty($sshConfig[$k])) { // throw new UserException(sprintf("Parameter %s is missing.", $k)); // } // } if (empty($sshConfig['user'])) { $sshConfig['user'] = $parameters['user']; } if (empty($sshConfig['remoteHost'])) { $sshConfig['remoteHost'] = $parameters['elastic']['host']; } if (empty($sshConfig['remotePort'])) { $sshConfig['remotePort'] = $parameters['elastic']['port']; } if (empty($sshConfig['localPort'])) { $sshConfig['localPort'] = 19200; } if (empty($sshConfig['sshPort'])) { $sshConfig['sshPort'] = 22; } $sshConfig['privateKey'] = $sshConfig['keys']['private']; $tunnelParams = array_intersect_key($sshConfig, array_flip(['user', 'sshHost', 'sshPort', 'localPort', 'remoteHost', 'remotePort', 'privateKey'])); $this->logger->info("Creating SSH tunnel to '" . $tunnelParams['sshHost'] . "'"); $ssh = new SSH(); $ssh->openTunnel($tunnelParams); $parameters['elastic']['host'] = '127.0.0.1'; $parameters['elastic']['port'] = $sshConfig['localPort']; return $parameters; }
public function createSshTunnel($dbConfig) { $sshConfig = $dbConfig['ssh']; // check params foreach (['keys', 'sshHost'] as $k) { if (empty($sshConfig[$k])) { throw new UserException(sprintf("Parameter %s is missing.", $k)); } } if (empty($sshConfig['user'])) { $sshConfig['user'] = $dbConfig['user']; } if (empty($sshConfig['localPort'])) { $sshConfig['localPort'] = 33006; } if (empty($sshConfig['remoteHost'])) { $sshConfig['remoteHost'] = $dbConfig['host']; } if (empty($sshConfig['remotePort'])) { $sshConfig['remotePort'] = $dbConfig['port']; } if (empty($sshConfig['sshPort'])) { $sshConfig['sshPort'] = 22; } $sshConfig['privateKey'] = isset($sshConfig['keys']['#private']) ? $sshConfig['keys']['#private'] : $sshConfig['keys']['private']; $tunnelParams = array_intersect_key($sshConfig, array_flip(['user', 'sshHost', 'sshPort', 'localPort', 'remoteHost', 'remotePort', 'privateKey'])); $this->logger->info("Creating SSH tunnel to '" . $tunnelParams['sshHost'] . "'"); try { $ssh = new SSH(); $ssh->openTunnel($tunnelParams); } catch (SSHException $e) { throw new UserException($e->getMessage(), 0, $e); } $dbConfig['host'] = '127.0.0.1'; $dbConfig['port'] = $sshConfig['localPort']; return $dbConfig; }