changeset 0:45012f7a69aa

Initial commit
author Eris Caffee <discordia@eldalin.com>
date Thu, 29 Sep 2011 13:28:04 -0500
parents
children f9775b1dc8f4
files dump.php
diffstat 1 files changed, 615 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dump.php	Thu Sep 29 13:28:04 2011 -0500
     1.3 @@ -0,0 +1,615 @@
     1.4 +<?php
     1.5 +//
     1.6 +// TODO
     1.7 +//
     1.8 +// Object oriented design.  A class for the mysql connection and dumping.
     1.9 +// A class for each supported script.
    1.10 +//
    1.11 +// A method to post the form.
    1.12 +//
    1.13 +// A way to drive from command line via wget.   (Might need to switch to GET form
    1.14 +//
    1.15 +// 
    1.16 +//
    1.17 +
    1.18 +set_time_limit(0);
    1.19 +
    1.20 +$print_form = 1;
    1.21 +
    1.22 +//test mysql connection
    1.23 +if( isset($_REQUEST['action']) ) 
    1.24 +    {
    1.25 +    $db_host=$_REQUEST['db_host'];
    1.26 +    $db_name=$_REQUEST['db_name'];
    1.27 +    $db_user=$_REQUEST['db_user'];
    1.28 +    $db_password=$_REQUEST['db_password'];
    1.29 +    if ('Test Connection' == $_REQUEST['action']) 
    1.30 +	{
    1.31 +	$retval = mysql_test($db_host,$db_name, $db_user, $db_password);
    1.32 +	if ($retval) 
    1.33 +	    {
    1.34 +	    echo "Success!"."<br>";
    1.35 +	    } 
    1.36 +	else 
    1.37 +	    {
    1.38 +	    echo "Unable to connect."."<br />";
    1.39 +	    }
    1.40 +	}
    1.41 +    else if ('Export Using MySQLDump' == $_REQUEST['action']) 
    1.42 +	{
    1.43 +	$retval = mysql_test($db_host, $db_name, $db_user, $db_password);
    1.44 +	if ($retval) 
    1.45 +	    {
    1.46 +	    $print_form=0;
    1.47 +	    send_dump($db_host, $db_name, $db_user, $db_password);
    1.48 +	    } 
    1.49 +	else 
    1.50 +	    {
    1.51 +	    echo "Unable to connect."."<br />";
    1.52 +	    }
    1.53 +	}    
    1.54 +  else if ('Export Using MySQLDump, Save File On Server' == $_REQUEST['action']) 
    1.55 +      {
    1.56 +      $retval = mysql_test($db_host, $db_name, $db_user, $db_password);
    1.57 +      if ($retval) 
    1.58 +	  {
    1.59 +	  $print_form=0;
    1.60 +	  save_dump($db_host, $db_name, $db_user, $db_password);
    1.61 +	  } 
    1.62 +      else 
    1.63 +	  {
    1.64 +	  echo "Unable to connect."."<br />";
    1.65 +	  }
    1.66 +      }    
    1.67 +  else if ('Export Using SQL' == $_REQUEST['action']) 
    1.68 +      {
    1.69 +      $link = mysql_login($db_host, $db_name, $db_user, $db_password);
    1.70 +      if ($link) 
    1.71 +	  {
    1.72 +	  $print_form=0;
    1.73 +	  send_dump_old($link, $db_host, $db_name);
    1.74 +	  } 
    1.75 +      else 
    1.76 +	  {
    1.77 +	  echo "Unable to connect."."<br />";
    1.78 +	  }
    1.79 +      }    
    1.80 +  else if ('View Dump' == $_REQUEST['action']) 
    1.81 +      {
    1.82 +      $link = mysql_login($db_host, $db_name, $db_user, $db_password);
    1.83 +      if ($link) 
    1.84 +	  {
    1.85 +	  $print_form=0;
    1.86 +	  view_dump($link, $db_host, $db_name);
    1.87 +	  } 
    1.88 +      else 
    1.89 +	  {
    1.90 +	  echo "Unable to connect."."<br />";
    1.91 +	  }
    1.92 +      }    
    1.93 +  else if ('Try Wordpress' == $_REQUEST['action']) 
    1.94 +      {
    1.95 +      $found = wp_get_logins($db_host, $db_name, $db_user, $db_password, $table_prefix, $multi);
    1.96 +      if ($found) 
    1.97 +	  {
    1.98 +	  $retval = mysql_test($db_host, $db_name, $db_user, $db_password);
    1.99 +	  if ($retval) 
   1.100 +	      {
   1.101 +	      echo "Success!"."<br>";
   1.102 +	      $_REQUEST['db_host']=$db_host;
   1.103 +	      $_REQUEST['db_name']=$db_name;
   1.104 +	      $_REQUEST['db_user']=$db_user;
   1.105 +	      $_REQUEST['db_password']=$db_password;
   1.106 +	      } 
   1.107 +	  } 
   1.108 +      else 
   1.109 +	  {
   1.110 +	  echo "Wordpress not found"."<br />";
   1.111 +	  }
   1.112 +      } 
   1.113 +  else if ('Try Joomla' == $_REQUEST['action']) 
   1.114 +      {
   1.115 +      $found = get_joomla_info($db_host, $db_name, $db_user, $db_password);
   1.116 +      if ($found) 
   1.117 +	  {
   1.118 +	  $retval = mysql_test($db_host,$db_name, $db_user, $db_password);
   1.119 +	  if ($retval) 
   1.120 +	      {
   1.121 +	      echo "Success!"."<br>";
   1.122 +	      $_REQUEST['db_host']=$db_host;
   1.123 +	      $_REQUEST['db_name']=$db_name;
   1.124 +	      $_REQUEST['db_user']=$db_user;
   1.125 +	      $_REQUEST['db_password']=$db_password;
   1.126 +	      } 
   1.127 +	  else 
   1.128 +	      {
   1.129 +	      printf("Unable to connect using<br />host: %s<br />database: %s<br />user:%s<br />password: %s<br />", $db_host, $db_name, $db_user, $db_password);
   1.130 +	      }
   1.131 +	  } 
   1.132 +      else 
   1.133 +	  {
   1.134 +	  echo "Joomla not found"."<br />";
   1.135 +	  }
   1.136 +      } 
   1.137 +  else if ('Try Simple Machines Forum' == $_REQUEST['action']) 
   1.138 +      {
   1.139 +      $found = get_smf_info($db_host, $db_name, $db_user, $db_password);
   1.140 +      if ($found) 
   1.141 +	  {
   1.142 +	  $retval = mysql_test($db_host,$db_name, $db_user, $db_password);
   1.143 +	  if ($retval) 
   1.144 +	      {
   1.145 +	      echo "Success!"."<br>";
   1.146 +	      $_REQUEST['db_host']=$db_host;
   1.147 +	      $_REQUEST['db_name']=$db_name;
   1.148 +	      $_REQUEST['db_user']=$db_user;
   1.149 +	      $_REQUEST['db_password']=$db_password;
   1.150 +	      } 
   1.151 +	  else 
   1.152 +	      {
   1.153 +	      printf("Unable to connect using<br />host: %s<br />database: %s<br />user:%s<br />password: %s<br />", $db_host, $db_name, $db_user, $db_password);
   1.154 +	      }
   1.155 +	  } 
   1.156 +      else 
   1.157 +	  {
   1.158 +	  echo "Simple Machines Forum not found"."<br />";
   1.159 +	  }
   1.160 +      }
   1.161 +    }
   1.162 +
   1.163 +////////////////////////////////////////////////////////////////////////////////
   1.164 +function send_dump($db_host, $db_name, $db_user, $db_password) 
   1.165 +    {
   1.166 +    $dumpname = $db_host."_".$db_name."-".date("Y\.m\.d\_H\.i\.s").".sql";
   1.167 +    header('Content-type: text/plain;charset=UTF-8');
   1.168 +    header('Content-Disposition: attachment; filename="'.$dumpname.'"');
   1.169 +    passthru("mysqldump --opt -u'".$db_user."' -p'".$db_password."' -h'".$db_host."' '".$db_name."'");
   1.170 +    }
   1.171 +
   1.172 +////////////////////////////////////////////////////////////////////////////////
   1.173 +function save_dump($db_host, $db_name, $db_user, $db_password) 
   1.174 +    {
   1.175 +    $dumpname = $db_host."_".$db_name."-".date("Y\.m\.d\_H\.i\.s").".sql";
   1.176 +    echo "<p>Saving dump to ".$dumpname."</p>";
   1.177 +    passthru("mysqldump --opt -u'".$db_user."' -p'".$db_password."' -h'".$db_host."' '".$db_name."' > ".$dumpname);
   1.178 +    }
   1.179 +
   1.180 +////////////////////////////////////////////////////////////////////////////////
   1.181 +function send_dump_old($link, $db_host, $db_name) 
   1.182 +    {
   1.183 +    $dumpname = $db_host."_".$db_name."-".date("Y\.m\.d\_H\.i\.s").".sql";
   1.184 +    header('Content-type: text/plain;charset=UTF-8');
   1.185 +    header('Content-Disposition: attachment; filename="'.$dumpname.'"');
   1.186 +    mysqldump($link, $db_host, $db_name);
   1.187 +    }
   1.188 +
   1.189 +////////////////////////////////////////////////////////////////////////////////
   1.190 +function view_dump($link, $db_host, $db_name) 
   1.191 +    {
   1.192 +    header('Content-type: text/plain;charset=UTF-8');
   1.193 +    mysqldump($link, $db_host, $db_name);
   1.194 +    }
   1.195 +
   1.196 +////////////////////////////////////////////////////////////////////////////////
   1.197 +function mysql_login($db_host, $db_name, $db_user, $db_password) 
   1.198 +    {
   1.199 +    $link = mysql_connect($db_host, $db_user, $db_password);
   1.200 +    if ($link) 
   1.201 +	{
   1.202 +	$db_selected = mysql_select_db($db_name, $link);
   1.203 +	if ($db_selected) 
   1.204 +	    {
   1.205 +	    mysql_query("SET NAMES utf8;", $link);
   1.206 +	    }
   1.207 +	else
   1.208 +	    {
   1.209 +	    printf("Connected, but unable to select database using<br />host: %s<br />database: %s<br />user:%s<br />password: %s<br />", $db_host, $db_name, $db_user, $db_password);	
   1.210 +	    mysql_close($link);
   1.211 +	    $link = FALSE;
   1.212 +	    }
   1.213 +	}
   1.214 +    else
   1.215 +	{
   1.216 +	printf("Unable to connect using<br />host: %s<br />database: %s<br />user:%s<br />password: %s<br />", $db_host, $db_name, $db_user, $db_password);
   1.217 +	mysql_close($link);
   1.218 +	$link = FALSE;
   1.219 +	}
   1.220 +    return $link;
   1.221 +    }
   1.222 +
   1.223 +////////////////////////////////////////////////////////////////////////////////
   1.224 +function mysql_test($db_host, $db_name, $db_user, $db_password) 
   1.225 +    {
   1.226 +    $retval = 0;
   1.227 +    $link = mysql_login($db_host, $db_name, $db_user, $db_password);
   1.228 +    if ($link) 
   1.229 +	{
   1.230 +	mysql_close($link);
   1.231 +	$retval = 1;
   1.232 +	} 
   1.233 +    return $retval;
   1.234 +    }
   1.235 +
   1.236 +////////////////////////////////////////////////////////////////////////////////
   1.237 +// Miscellaneous functions 
   1.238 +////////////////////////////////////////////////////////////////////////////////
   1.239 +function find_files(&$filelist, $regex, $dir='.', $maxdepth=PHP_INT_MAX) 
   1.240 +    {
   1.241 +    static $depth = -1;
   1.242 +    $depth++;
   1.243 +    if ($handle = opendir($dir) )
   1.244 +	{
   1.245 +	while (false !== ($file = readdir($handle))) 
   1.246 +	    {
   1.247 +	    if (($file == ".") || ($file == ".."))
   1.248 +		{
   1.249 +		continue;
   1.250 +		}
   1.251 +	    if (preg_match($regex, $file) > 0)
   1.252 +		{
   1.253 +		array_push($filelist, $dir."/".$file);
   1.254 +		}
   1.255 +	    else if (is_dir($file) && $depth < $maxdepth)
   1.256 +		{
   1.257 +		find_files($filelist, $regex, $dir."/".$file, $maxdepth);
   1.258 +		}
   1.259 +	    }
   1.260 +	closedir($handle);
   1.261 +	}
   1.262 +    $depth = -1;
   1.263 +    }
   1.264 +
   1.265 +////////////////////////////////////////////////////////////////////////////////
   1.266 +// Wordpress functions
   1.267 +////////////////////////////////////////////////////////////////////////////////
   1.268 +function wp_find_configs(&$configs, $dir=".", $maxdepth=2)
   1.269 +    {
   1.270 +    $configs = array();
   1.271 +    find_files($configs, "/^wp-config.php$/", $dir, $maxdepth);
   1.272 +    }
   1.273 +
   1.274 +function wp_get_logins(&$db_host, &$db_name, &$db_user, &$db_password, &$table_prefix, &$multi) 
   1.275 +    {
   1.276 +    $found = 0;
   1.277 +    $conf = fopen("wp-config.php", "r");
   1.278 +    if ($conf) 
   1.279 +	{
   1.280 +	while (($line = fgets($conf, 4096)) != false) 
   1.281 +	    {
   1.282 +	    if (preg_match('/([\'\"])DB_NAME\1\s*,\s*([\'\"])(.*?)\2/', $line, $matches)) 
   1.283 +		{
   1.284 +		$db_name = $matches[3];
   1.285 +		++$found;
   1.286 +		}
   1.287 +	    if (preg_match('/([\'\"])DB_USER\1\s*,\s*([\'\"])(.*?)\2/', $line, $matches)) 
   1.288 +		{
   1.289 +		$db_user = $matches[3];
   1.290 +		++$found;
   1.291 +		}
   1.292 +	    if (preg_match('/([\'\"])DB_PASSWORD\1\s*,\s*([\'\"])(.*?)\2/', $line, $matches)) 
   1.293 +		{
   1.294 +		$db_password = $matches[3];
   1.295 +		++$found;
   1.296 +		}
   1.297 +	    if (preg_match('/([\'\"])DB_HOST\1\s*,\s*([\'\"])(.*?)\2/', $line, $matches)) 
   1.298 +		{
   1.299 +		$db_host = $matches[3];
   1.300 +		++$found;
   1.301 +		}
   1.302 +	    }
   1.303 +	}
   1.304 +    fclose($conf);
   1.305 +    if ($found != 4) 
   1.306 +	{
   1.307 +	return 0;
   1.308 +	}
   1.309 +    return 1;
   1.310 +    }
   1.311 +
   1.312 +function wp_list_sites()
   1.313 +    {
   1.314 +    
   1.315 +    }
   1.316 +
   1.317 +////////////////////////////////////////////////////////////////////////////////
   1.318 +// Joomla functions
   1.319 +////////////////////////////////////////////////////////////////////////////////
   1.320 +function get_joomla_info(&$host, &$database, &$username, &$password) 
   1.321 +    {
   1.322 +    $found = 0;
   1.323 +    $conf = fopen("configuration.php", "r");
   1.324 +    if ($conf) 
   1.325 +	{
   1.326 +	while (($line = fgets($conf, 4096)) != false) 
   1.327 +	    {
   1.328 +	    if (preg_match('/\Q$\Edb\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.329 +		{
   1.330 +		printf("%s\n", $line);
   1.331 +		print_r($matches); echo "<br />";
   1.332 +		$database = $matches[2];
   1.333 +		++$found;
   1.334 +		}
   1.335 +	    if (preg_match('/\Q$\Euser\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.336 +		{
   1.337 +		print_r($matches); echo "<br />";
   1.338 +		$username = $matches[2];
   1.339 +		++$found;
   1.340 +		}
   1.341 +	    if (preg_match('/\Q$\Epassword\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.342 +		{
   1.343 +		print_r($matches); echo "<br />";
   1.344 +		$password = $matches[2];
   1.345 +		++$found;
   1.346 +		}
   1.347 +	    if (preg_match('/\Q$\Ehost\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.348 +		{
   1.349 +		print_r($matches); echo "<br />";
   1.350 +		$host = $matches[2];
   1.351 +		++$found;
   1.352 +		}
   1.353 +	    }
   1.354 +	}
   1.355 +    fclose($conf);
   1.356 +    if ($found != 4) 
   1.357 +	{
   1.358 +	return 0;
   1.359 +	}
   1.360 +    return 1;
   1.361 +    }
   1.362 +
   1.363 +////////////////////////////////////////////////////////////////////////////////
   1.364 +// Simple Machines Forum functions
   1.365 +////////////////////////////////////////////////////////////////////////////////
   1.366 +function get_smf_info(&$host, &$database, &$username, &$password) 
   1.367 +    {
   1.368 +    $found = 0;
   1.369 +    $conf = fopen("Settings.php", "r");
   1.370 +    if ($conf) 
   1.371 +	{
   1.372 +	while (($line = fgets($conf, 4096)) != false) 
   1.373 +	    {
   1.374 +	    if (preg_match('/\$db_name\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.375 +		{
   1.376 +		$database = $matches[2];
   1.377 +		++$found;
   1.378 +		}
   1.379 +	    if (preg_match('/\$db_user\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.380 +		{
   1.381 +		$username = $matches[2];
   1.382 +		++$found;
   1.383 +		}
   1.384 +	    if (preg_match('/\$db_passwd\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.385 +		{
   1.386 +		$password = $matches[2];
   1.387 +		++$found;
   1.388 +		}
   1.389 +	    if (preg_match('/\$db_server\s*=\s*([\'\"])(.*)\1/', $line, $matches)) 
   1.390 +		{
   1.391 +		$host = $matches[2];
   1.392 +		++$found;
   1.393 +		}
   1.394 +	    }
   1.395 +	}
   1.396 +    fclose($conf);
   1.397 +    if ($found != 4) 
   1.398 +	{
   1.399 +	return 0;
   1.400 +	}
   1.401 +    return 1;
   1.402 +    }
   1.403 +
   1.404 +
   1.405 +
   1.406 +////////////////////////////////////////////////////////////////////////////////
   1.407 +// Mostly original mysqldump.php functions
   1.408 +////////////////////////////////////////////////////////////////////////////////
   1.409 +function mysqldump($link, $db_host, $db_name) 
   1.410 +    {
   1.411 +    printf("-- Host: %s\n".
   1.412 +	   "-- Database: %s\n".
   1.413 +	   "\n".
   1.414 +	   "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n".
   1.415 +	   "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n".
   1.416 +	   "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n".
   1.417 +	   "/*!40101 SET NAMES utf8 */;\n".
   1.418 +	   "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n".
   1.419 +	   "/*!40103 SET TIME_ZONE='+00:00' */;\n".
   1.420 +	   "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n".
   1.421 +	   "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n".
   1.422 +	   "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n".
   1.423 +	   "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;".
   1.424 +	   "\n\n\n", $db_host, $db_name);
   1.425 +    
   1.426 +    $sql = "SHOW TABLES;";
   1.427 +    $result = mysql_query($sql, $link);
   1.428 +    if ($result) 
   1.429 +	{
   1.430 +	while ($row = mysql_fetch_row($result)) 
   1.431 +	    {
   1.432 +	    mysqldump_table_structure($link, $row[0]);
   1.433 +	    mysqldump_table_data($link, $row[0]);
   1.434 +	    }
   1.435 +	} 
   1.436 +    else 
   1.437 +	{
   1.438 +	printf("-- no tables in database \n");
   1.439 +	}
   1.440 +    mysql_free_result($result);
   1.441 +
   1.442 +    printf("\n\n\n".
   1.443 +	   "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n".
   1.444 +	   "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n".
   1.445 +	   "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n".
   1.446 +	   "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n".
   1.447 +	   "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n".
   1.448 +	   "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n".
   1.449 +	   "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n".
   1.450 +	   "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
   1.451 +    }
   1.452 +
   1.453 +////////////////////////////////////////////////////////////////////////////////
   1.454 +function mysqldump_table_structure($link, $table) 
   1.455 +    {
   1.456 +    echo "-- Table structure for table ".$table." \n";
   1.457 +    echo "DROP TABLE IF EXISTS `".$table."`;\n\n";
   1.458 +    $sql = "SHOW CREATE TABLE `".$table."`; ";
   1.459 +    $result=mysql_query($sql, $link);
   1.460 +    if ($result) 
   1.461 +	{
   1.462 +	if ($row= mysql_fetch_assoc($result)) 
   1.463 +	    {
   1.464 +	    echo $row['Create Table'].";\n\n";
   1.465 +	    }
   1.466 +	}
   1.467 +    mysql_free_result($result);
   1.468 +    }
   1.469 +
   1.470 +////////////////////////////////////////////////////////////////////////////////
   1.471 +function mysqldump_table_data($link, $table) 
   1.472 +    {
   1.473 +    $sql = "SELECT * FROM `".$table."`;";
   1.474 +    $result = mysql_query($sql, $link);
   1.475 +    if ($result) 
   1.476 +	{
   1.477 +	$num_rows = mysql_num_rows($result);
   1.478 +	$num_fields = mysql_num_fields($result);
   1.479 +	
   1.480 +	if ($num_rows > 0) 
   1.481 +	    {
   1.482 +	    printf("-- dumping data for table %s\n".
   1.483 +		   "LOCK TABLE `%s`;\n".
   1.484 +		   "/*!40000 ALTER TABLE `%s` DISABLE KEYS */;\n", 
   1.485 +		   $table, $table, $table);;
   1.486 +	    
   1.487 +	    $field_type = array();
   1.488 +	    $i = 0;
   1.489 +	    while ($i < $num_fields) 
   1.490 +		{
   1.491 +		$meta = mysql_fetch_field($result, $i);
   1.492 +		array_push($field_type, $meta->type);
   1.493 +		$i++;
   1.494 +		}
   1.495 +	    
   1.496 +	    printf("INSERT INTO `%s` VALUES\n", $table);;
   1.497 +	    $index = 0;
   1.498 +	    while ($row = mysql_fetch_row($result)) 
   1.499 +		{
   1.500 +		echo "(";
   1.501 +		for ($i = 0; $i < $num_fields; $i++) 
   1.502 +		    {
   1.503 +		    if (is_null ($row[$i]))
   1.504 +		       echo "null";
   1.505 +		    else 
   1.506 +			{
   1.507 +			switch ($field_type[$i])
   1.508 +			    {
   1.509 +			    case 'int':
   1.510 +			    echo $row[$i];
   1.511 +			    break;
   1.512 +			    case 'string':
   1.513 +			    case 'blob' :
   1.514 +			    default:
   1.515 +			    printf("'%s'", mysql_real_escape_string($row[$i]));
   1.516 +			    }
   1.517 +			}
   1.518 +		    if ($i < $num_fields-1)
   1.519 +		       echo ",";
   1.520 +		    }
   1.521 +		echo ")";
   1.522 +		
   1.523 +		if ($index < $num_rows-1)
   1.524 +		   echo ",";
   1.525 +		else
   1.526 +		   echo ";";
   1.527 +		echo "\n";
   1.528 +		
   1.529 +		$index++;
   1.530 +		}
   1.531 +	    printf("/*!40000 ALTER TABLE `%s` ENABLE KEYS */;\n".
   1.532 +		   "UNLOCK TABLE `%s`;\n", 
   1.533 +		   $table, $table);
   1.534 +	    }
   1.535 +	}
   1.536 +    mysql_free_result($result);
   1.537 +    echo "\n";
   1.538 +    }
   1.539 +
   1.540 +
   1.541 +////////////////////////////////////////////////////////////////////////////////
   1.542 +// The actual web page.
   1.543 +////////////////////////////////////////////////////////////////////////////////
   1.544 +
   1.545 +if ($print_form > 0)
   1.546 +    {
   1.547 +?>
   1.548 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
   1.549 +
   1.550 +<html>
   1.551 +<head>
   1.552 +<title>dump.php</title>
   1.553 +</head>
   1.554 +
   1.555 +<body>
   1.556 +<hr />
   1.557 +<form action="" method="post">
   1.558 +MySQL connection parameters:
   1.559 +<table border="0">
   1.560 +  <tr>
   1.561 +    <td>Host:</td>
   1.562 +    <td><input  name="db_host" value="<?php if(isset($_REQUEST['db_host']))echo $_REQUEST['db_host']; else echo 'localhost';?>"  /></td>
   1.563 +  </tr>
   1.564 +  <tr>
   1.565 +    <td>Database:</td>
   1.566 +    <td><input  name="db_name" value="<?php echo $_REQUEST['db_name']; ?>"  /></td>
   1.567 +  </tr>
   1.568 +  <tr>
   1.569 +    <td>Username:</td>
   1.570 +    <td><input  name="db_user" value="<?php echo $_REQUEST['db_user']; ?>"  /></td>
   1.571 +  </tr>
   1.572 +  <tr>
   1.573 +    <td>Password:</td>
   1.574 +    <td><input  type="password" name="db_password" value="<?php echo $_REQUEST['db_password']; ?>"  /></td>
   1.575 +  </tr>
   1.576 +</table>
   1.577 +<input type="submit" name="action"  value="Test Connection"> &nbsp;
   1.578 +<input type="submit" name="action"  value="Export Using MySQLDump"> &nbsp;
   1.579 +<input type="submit" name="action"  value="Export Using MySQLDump, Save File On Server"> &nbsp;
   1.580 +<input type="submit" name="action"  value="Export Using SQL"> &nbsp;
   1.581 +<input type="submit" name="action"  value="View Dump"><br />
   1.582 +<hr />
   1.583 +<input type="submit" name="action"  value="Try Wordpress"><br />
   1.584 +<input type="submit" name="action"  value="Try Joomla"><br />
   1.585 +<input type="submit" name="action"  value="Try Simple Machines Forum"><br />
   1.586 +</form>
   1.587 +</body>
   1.588 +</html>
   1.589 +
   1.590 +<?php
   1.591 +    /*
   1.592 +    $configs = array();
   1.593 +    wp_find_configs($configs);
   1.594 +    if (count($configs) > 0)
   1.595 +	{
   1.596 +	echo "<table>\n<th>Wordpress Configs</th>\n";
   1.597 +	foreach ($configs as $conf)
   1.598 +	    {
   1.599 +	    printf("<tr><td>%s</td></tr>\n", $conf);
   1.600 +	    }
   1.601 +	echo "</table>";
   1.602 +	}
   1.603 +
   1.604 +    $configs = array();
   1.605 +    find_files($configs, "/^configuration.php$/");
   1.606 +    if (count($configs) > 0)
   1.607 +	{
   1.608 +	echo "<table>\n<th>Joomla Configs</th>\n";
   1.609 +	foreach ($configs as $conf)
   1.610 +	    {
   1.611 +	    printf("<tr><td>%s</td></tr>\n", $conf);
   1.612 +	    }
   1.613 +	echo "</table>";
   1.614 +	}
   1.615 +    */
   1.616 +    }
   1.617 +?>
   1.618 +