Tunnel version: ' . tunnelversion . '.
This PHP page exposes the MySQL API as a set of webservices.
This page allows SQLyog to manage a MySQL server even if the MySQL port is blocked or remote access to MySQL is not allowed.
Visit Webyog to get more details about SQLyog.';
echo ( '
SQLyog HTTP Tunneling'.
''.
'

'
);
echo ( '
' );
/* we show PHP version error also if required */
if ( CheckPHPVersion() == FALSE ) {
echo ( '
Error: SQLyog HTTP Tunnel feature requires PHP version > 4.3.0 |
' );
}
if ($extra != "" ) {
echo ( '
' );
}
echo ( '' );
WriteLog ( "Exit showaccesserror" );
}
/* Check PHP version compatibility*/
function CheckPHPVersion()
{
$phpversionstr = phpversion();
$versionarry = explode(".", $phpversionstr, 2);
/* We dont support v4.3.0 */
if ( (integer)$versionarry[0] < 4 ||
((integer)$versionarry[0] == 4 && (integer)$versionarry[1] < 3 ))
{
return FALSE;
}
else
{
return TRUE;
}
return TRUE;
}
/* function checks if a required module is installed or not */
function AreModulesInstalled ()
{
WriteLog ( "Enter aremodulesinstalled" );
$modules = get_loaded_extensions();
$modulenotfound = '';
$thisExtension="";
if ( extension_loaded ( "xml" ) != TRUE )
{
$modulenotfound = 'XML';
$thisExtension="this extension";
} else if ( DB_EXTENSION=="-1")
{
$modulenotfound = 'php_mysqli or php_mysql';
$thisExtension="one of these these extensions";
}
else
{
WriteLog ( "Exit aremodulesinstalled" );
// if correct modules are found - exit IMMEDIATELY
return TRUE;
}
if(isset($_GET['app'])) // from SQLyog - just indicate to SQLyog that SOME modules are not installed
{
echo(tunnelversionstring);
echo(phpmoduleerror);
WriteLog ( "Exit aremodulesinstalled" );
return FALSE;
}
// It will come here only when its called from a browser
$errmsg = '
Error: Extension
' . $modulenotfound . ' was not found compiled and loaded in the PHP interpreter. SQLyog requires '.$thisExtension .' to work properly.';
$errmsg .= '
Tunnel version: ' . tunnelversion . '.
This PHP page exposes the MySQL API as a set of webservices.
This page allows SQLyog to manage a MySQL server even if the MySQL port is blocked or remote access to MySQL is not allowed.
Visit Webyog to get more details about SQLyog.';
echo ( '
SQLyog HTTP Tunneling
' );
echo ( '
' );
echo ( '' );
WriteLog ( "Exit aremodulesinstalled" );
}
/**
* checks if the XML stream is base 64 encoded
*
* @return bool If stream is encoded, return true. Else false;
*
*/
function LibXml2IsBase64Encoded()
{
global $libxml2_is_base64;
if ($libxml2_is_base64 == 0){
return false;
}
return true;
}
/** Detect if the user's PHP/LibXML is affected by the following bug: -
* http://bugs.php.net/bug.php?id=45996
*/
function LibXml2IsBuggy()
{
global $libxml2_test_query;
$libxml2_test_query = '';
$testxml = '
select 'a'';
GetDetailsFromPostedXML ($testxml);
if(strcasecmp($libxml2_test_query, 'select a') == 0)
{
//This PHP/LibXML is buggy!
return true;
}
//Not buggy!
return false;
}
/* we can now use SQLyogTunnel.php to log debug informations, which will help us to point out the error */
function WriteLog ( $loginfo )
{
if ( defined("DEBUG") )
{
$fp = fopen ( "yogtunnel.log", "a" );
if ( $fp == FALSE )
return;
fwrite ( $fp, $loginfo . "\r\n" ); // MY_CHANGE: Because below it was
// printing 'Enter' instead of new line
fclose ( $fp );
}
}
function WriteLogTemp ( $loginfo )
{
if ( defined("DEBUG") )
{
$fp = fopen ( "sabya.log", "a" );
if ( $fp == FALSE )
return;
fwrite ( $fp, $loginfo . "\r\n" ); // MY_CHANGE: Because below it was
// printing 'Enter' instead of new line
fclose ( $fp );
}
}
/* Process the query*/
function ProcessQuery ()
{
WriteLog ( "Enter processquery" );
if ( CheckPHPVersion() == FALSE )
{
/* now the call can be of three types
1.) Specific to check tunnel version
2.) Normal where it is expected that the PHP page is 4.3.0
3.) From browser
We check this by checking the query string which is sent if just a check is done by SQLyog */
WriteLog ( "CheckPHPVersion is FALSE" );
if(isset($_GET['app']))
{
echo(tunnelversionstring);
echo(phpversionerror);
}
else
{
WriteLog ( "CheckPHPVersion is FALSE and app query string not set" );
ShowAccessError();
}
return;
}
/* in special case, sqlyog just sends garbage data with query string to check for tunnel version. we need to process that now */
if(isset($_GET['app']))
{
WriteLog ( "app query string not set" );
echo(tunnelversionstring);
echo(tunnelversion);
return;
}
/* Starting from 5.1 BETA 4, we dont get the data as URL encoded POST data, we just get it as raw data */
WriteLog ( "Trying to get php://input" );
$xmlrecvd = file_get_contents("php://input");
WriteLog ( "Got php://input!" );
if ( strlen ( $xmlrecvd ) == 0 )
{
WriteLog ( "Called from browser." );
ShowAccessError ();
WriteLog ( "xmlrecvd is blank" );
return;
}
WriteLog ( $xmlrecvd );
global $host;
global $port;
global $username;
global $pwd;
global $db;
global $batch;
global $query;
global $base;
$ret = GetDetailsFromPostedXML ( $xmlrecvd );
if ( $ret == FALSE )
return;
/* Wrap result in
tag */
echo "";
//If the stream is not base-64 encoded and the PHP has the libxml2 bug display extra error.
if(LibXml2IsBase64Encoded() == false && LibXml2IsBuggy() == true)
{
$extra_msg =
'Your PHP/libxml version is affected by a bug. ' .
'Please check "Always Use Base64 Encoding For Data Stream" in "Advanced" section of HTTP tab.'
;
HandleError (4, $extra_msg);
WriteLog ('libxml2 error');
echo "";
return;
}
/* connect to the mysql server */
WriteLog ( "Trying to connect" );
$mysql = yog_mysql_connect ( $host,$port, $username, $pwd );
if ( !$mysql )
{
HandleError ( yog_mysql_connect_errno(), yog_mysql_connect_error() );
WriteLog ( yog_mysql_connect_error() );
echo "";
return;
}
WriteLog ( "Connected" );
/* Function will execute setnames in the server as it does in SQLyog client */
SetName ( $mysql );
yog_mysql_select_db ( str_replace ( '`', '', $db ), $mysql );
/* set sql_mode to zero */
SetNonStrictMode ( $mysql );
if ( $batch ) {
ExecuteBatchQuery ( $mysql, $query );
}
else
ExecuteSingleQuery ( $mysql, $query );
yog_mysql_close ( $mysql );
echo "";
WriteLog ( "Exit processquery" );
}
/*********** Global Section **********/
define ( "COMMENT_OFF", 0 );
define ( "COMMENT_HASH", 1 );
define ( "COMMENT_DASH", 2 );
define ( "COMMENT_START", 0 );
/* current element state while parsing XML received as post */
define ( "XML_NOSTATE", 0 );
define ( "XML_HOST", 1 );
define ( "XML_USER", 2 );
define ( "XML_DB", 3 );
define ( "XML_PWD", 4 );
define ( "XML_PORT", 5 );
define ( "XML_QUERY", 6 );
define ( "XML_CHARSET", 7 );
define ( "XML_LIBXML2_TEST_QUERY", 8);
/* uncomment this line to create a debug log */
//define ( "DEBUG", 1 );
/* version constant */
/* You will need to change the version in processquery method too, where it shows: $versionheader = 'TunnelVersion:5.13.1' */
define ( "tunnelversion", '8.8');
define ( "tunnelversionstring", 'TunnelVersion:' );
define ( "phpversionerror", 'PHP_VERSION_ERROR' );
define ( "phpmoduleerror", 'PHP_MODULE_NOT_INSTALLED' );
/* we stop all error reporting as we check for all sort of errors */
WriteLog ( "" );
if ( defined("DEBUG") )
error_reporting ( E_ALL );
else
error_reporting ( 0 );
set_time_limit ( 0 );
if (!defined("MYSQLI_TYPE_BIT")) {
define ( "MYSQLI_TYPE_BIT", 16);
}
/* current character in the query */
$curpos = 0;
//ini_set("display_errors",0);
/* check whether global variables are registered or not */
if (!get_cfg_var("register_globals"))
{
extract($_REQUEST);
}
/* we have to set the value to be off during runtime coz it does not work when magic_quotes_runtime = On is setin Php.ini */
set_magic_quotes_runtime (0);
/* Check for the PHP_MYSQL/PHP_MYSQLI extension loaded */
if (extension_loaded('mysqli'))
{
define ("DB_EXTENSION", "mysqli");
}
elseif (extension_loaded('mysql'))
{
define ("DB_EXTENSION", "mysql");
}
else
{
define ("DB_EXTENSION", "-1");
}
/* global variable to keep the state of current XML element */
$xml_state = XML_NOSTATE;
/* global variables to track various informations about the query */
$host = NULL;
$port = NULL;
$db = NULL;
$username = NULL;
$pwd = NULL;
$charset = NULL;
$batch = 0;
$base = 0;
$query = NULL;
$libxml2_test_query = NULL;
$libxml2_is_base64 = 0;
/* we check if all the external libraries support i.e. expat and mysql in our case is built in or not */
/* if any of the libraries are not found then we show a warning and exit */
if ( AreModulesInstalled () == TRUE )
{
ProcessQuery ();
}
?>