Skip to content

Commit

Permalink
Added phpssh2.php to PHP Tunnel into remote service on localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
apmuthu committed Feb 27, 2018
1 parent 722c417 commit e3cfcd0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* `jsDynaField` - [jQuery](https://jquery.org/) based Dynamic Form Field Addition
* `phpGetDomains` - domain_lister.php - Get Insert SQL statements from registrar records at [Daily Changes](http://www.dailychanges.com)
* `php-mysql-functions` - PHP functions for MySQL and Password set/blank bash scripts for MySQL 5.6
* `phpssh2.php` - PHP Tunnel into remote service on localhost
* `phpunzip` - Unzip archives using php by [PHPConcepts](http://www.phpconcept.net)
* `pincodes` - Data Dump of Indian Postal Codes
* `wiki_extract.php` - Extract urls of uploaded files in MediaWiki based Wikis and use with `wget`
Expand Down
34 changes: 34 additions & 0 deletions phpssh2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// PHP tunnel into a remote server and access services on it from localhost

$config['MW-DB']['host'] = '127.0.0.1';
$config['MW-DB']['user'] = 'someusername';
$config['MW-DB']['pass'] = 'somerandompassword';
$config['MW-DB']['dbname'] = 'somerandomdbname';


$config['SSH-TUN']['server'] = "hostIpAddress";
$config['SSH-TUN']['password'] = 'SSHPasswordForHost';
$config['SSH-TUN']['remote-port'] = 'SSH Port to use';
$config['SSH-TUN']['username'] = 'SSHUsernameOnHost';

//Establish the MySQL SSH Tunnel

if(function_exists("ssh2_tunnel"))
echo "success";
else
echo "failure";

$connection = ssh2_connect($config['SSH-TUN']['server'], $config['SSH-TUN']['remote-port']);
if (ssh2_auth_password($connection, $config['SSH-TUN']['username'], $config['SSH-TUN']['password'])) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}

$tunnel = ssh2_tunnel($connection, '127.0.0.1', 3306);

$conn = mysql_connect($config['MW-DB']['host'], $config['MW-DB']['user'], $config['MW-DB']['pass']) or die (mysql_error());


?>

0 comments on commit e3cfcd0

Please sign in to comment.