Started SSH class for tunneled connections

This commit is contained in:
Timothy Warren 2012-02-29 16:53:07 -05:00
parent 015da3778c
commit dafbdbf4d2
2 changed files with 61 additions and 0 deletions

View File

@ -17,6 +17,7 @@ Because php-gtk is such a pain to compile on Windows, I've put together this pac
* php5-mysql
* php5-postgresql
* php5-sqlite
* php5-ssh2
* Run via terminal in the OpenSQLManager folder using `php index.php`
## PHP Requirements

60
sys/common/ssh.php Normal file
View File

@ -0,0 +1,60 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Class to create ssh tunnels to connect to protected database servers
*/
class SSH {
private $session, $stream;
/**
* Constructor
*
* @param string $host
* @param int $port
*/
public function __construct($host, $port=22)
{
$this->session =& ssh2_connect($host, $port);
if($this->session === FALSE)
{
return FALSE;
}
return $this;
}
/**
* Create a tunnel using the current ssh connection
*
* @param string $host
* @param int $port
* @param string $auth_type
* @param array $auth_params
* @return stream
*/
public function tunnel($host, $port, $auth_type='password', $auth_params)
{
if($auth_type === 'password')
{
ssh2_auth_password(&$this->session, $auth_params['user'], $auth_params['pass']);
}
$this->stream =& ssh2_tunnel(&$this->session, $host, $port);
return $this->stream;
}
}