-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added phpssh2.php to PHP Tunnel into remote service on localhost
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
|
||
?> |