<?php
/* Change Default Password */

$passwd = "MyPass123";

/*
 *
 *
 *
 */
######################################################################
####### YOU ARE NOT ALLOW TO EDIT OR COPY ANYTHING FROM BELOW ########
######################################################################
/*
 *
 *
 *
 */
/**
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* (c) 2007-2012 Tools2U Software.
* This script is copyrighted by Tools2U.com
* Alteration of this script in any way, copying, reproducing, distributing,
* displaying, republishing, retransmitting, reposting, archiving, selling,
* or transferring of this Script is a Violation of the Copyright and License
* Agreement.
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
ignore_user_abort(true);
set_time_limit(0);
if ($_REQUEST["zipfilename"]) {
$zipfilename = $_REQUEST["zipfilename"];
} else {
$zipfilename = md5($_SERVER["HTTP_HOST"] . time() . rand(9999, 999999));
}
if (file_exists('readme.html')) {
@unlink('readme.html');
}
if ($_REQUEST['delbackupfiles'] == "Y") {
if (file_exists('masterblog.sql')) {
@unlink('masterblog.sql');
}
if (file_exists('wordpress.zip')) {
@unlink('wordpress.zip');
}
if (file_exists($zipfilename . '_wordpress.zip')) {
@unlink($zipfilename . '_wordpress.zip');
}
exit();
}
if (md5($_REQUEST['chkpass']) != md5($passwd)) {
if ($_REQUEST['softacc'] == "Y") {
echo "\r\n\r\nLogin Failed? please check the PHP File Password";
} else {
echo '<html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="robots" content="noindex,nofollow"></head><body style="padding:10px;"><form name="wdp_login" action="" method="post"><table border="0" cellpadding="2"><tr><td>Password:</td></tr><tr><td><input type="password" name="chkpass" value="" size="25"></td></tr><tr><td>Filename:</td></tr><tr><td><input type="text" name="zipfilename" value="'.$zipfilename.'" size="30">_wordpress.zip</td></tr><tr><td>(OPTIONAL)<br>Save to another folder:</td></tr><tr><td><input type="text" name="zipfoldername" value="" size="25"></td></tr><tr><td><input type="submit" name="submit" value="Submit"></td></tr></table></form></body></html>';
}
exit();
}
/*
if ($_REQUEST['getbackupfile'] == "Y") {
if (file_exists($zipfilename . '_wordpress.zip')) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('wordpress.zip'));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($zipfilename . '_wordpress.zip'));
ob_clean();
flush();
readfile($zipfilename . '_wordpress.zip');
exit();
}
}
*/
if ($_REQUEST['softacc'] != "Y") {
echo '<html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body,pre{color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:14px; margin:8px;}
</style>
</head><body style="padding:10px;">';
}
include("./wp-admin/includes/class-pclzip.php");
function get_current_url() {
$protocol = 'http';
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')) {
$protocol .= 's';
$protocol_port = $_SERVER['SERVER_PORT'];
} else {
$protocol_port = 80;
}
$host = $_SERVER['HTTP_HOST'];
$port = $_SERVER['SERVER_PORT'];
$request = dirname($_SERVER['PHP_SELF']);
$query = substr($_SERVER['argv'][0], strpos($_SERVER['argv'][0], ';') + 1);
$fnurl = $protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request . (empty($query) ? '' : '?' . $query);
if (substr($fnurl, -1) == "/") {
$fnurl = substr($fnurl, 0, -1);
}
return $fnurl;
}
function _filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
if (file_exists('wordpress.zip')) {
if (!unlink('wordpress.zip')) {
die("Error : There was an error trying to delete the file (wordpress.zip).");
}
}
if (file_exists($zipfilename . '_wordpress.zip')) {
if (!unlink($zipfilename . '_wordpress.zip')) {
die("Error : There was an error trying to delete the file ({$zipfilename}_wordpress.zip).");
}
}
if (file_exists('masterblog.sql')) {
if (!unlink('masterblog.sql')) {
die("Error : There was an error trying to delete the file (masterblog.sql).");
}
}
if (!@include 'wp-config.php') {
die("Error : Failed to include wp-config.php");
}
echo "<h2>Exporting Database Tables to masterblog.sql file .</h2>";
flush();
function exec_enabled() {
$disabled = explode(',', ini_get('disable_functions'));
foreach($disabled as $disable) {
if (trim($disable) == 'exec') {
$returnst = false;
break;
} else {
$returnst = true;
}
}
return $returnst;
}
backup_tables($table_prefix, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
function backup_tables($table_prefix,$host,$user,$pass,$name,$tables = '*') {
$link = mysql_connect($host, $user, $pass) or die('Error : Could not connect: ' . mysql_error());
mysql_select_db($name, $link) or die('Error : Can\'t use ' . $name .  ' : ' . mysql_error());
@mysql_query('SET NAMES utf8', $link);
@mysql_query('SET CHARACTER SET utf8', $link);
if (exec_enabled()) {
if ($_REQUEST['softacc'] == "Y") {
echo exec('export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/cpanel/bin:/usr/local/mysql/bin:$HOME/bin" && mysqldump --version') . '
';
} else {
echo exec('export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/cpanel/bin:/usr/local/mysql/bin:$HOME/bin" && mysqldump --version') . '<br>';
}
$command = 'export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/cpanel/bin:/usr/local/mysql/bin:$HOME/bin" && mysqldump --opt -h' . escapeshellarg($host) .' -u' . escapeshellarg($user) .' -p' . escapeshellarg($pass) .' ' . escapeshellarg($name) .' > ' . getcwd().'/masterblog.sql';
exec($command, $output=array(), $worked);
switch($worked) {
case 0:
echo 'Database "' .$name .'" successfully exported to "' . getcwd().'/masterblog.sql' .'"';
break;
case 1:
echo 'There was a warning during the export of "' .$name .'" to "' . getcwd().'/masterblog.sql' .'"';
break;
case 2:
echo 'There was a warning during the export of "' .$name .'" to "' . getcwd().'/masterblog.sql' .'"';
break;
}
} else {
if ($_REQUEST['softacc'] == "Y") {
echo 'Failed to run mysqldump because exec() has been disabled in php.ini but the script will try to export SQL using PHP functions:
';
} else {
echo 'Failed to run mysqldump because exec() has been disabled in php.ini but the script<br>will try to export SQL using PHP functions:<br>';
}
if ($tables == '*') {
$tables = array();
$result = mysql_query('SHOW TABLES', $link);
while($row = mysql_fetch_row($result)) {
$tables[] = $row[0];
}
} else {
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
foreach($tables as $table) {
$result = mysql_query('SELECT * FROM '.$table, $link) or die('Error : Could not run query: ' . mysql_error($link));
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE IF EXISTS `'.$table.'`;';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table, $link)) or die('Error : Could not run query: ' . mysql_error($link));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++) {
while ($row = mysql_fetch_row($result)) {
$return.= 'INSERT INTO '.$table.' VALUES(';
for ($j=0; $j<$num_fields; $j++) {
$row[$j] = addslashes($row[$j]);
$row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n";
}
$return = str_replace($table_prefix, "wp_", trim($return))."\n";
$handle = fopen('masterblog.sql','w+');
fwrite($handle,$return);
fclose($handle);
@mysql_close();
@mysql_close($link);
echo 'Database "' .$name .'" successfully exported to "' . getcwd().'/masterblog.sql' .'"';
}
}
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "Thumbs.db" && $file != "php_errorlog" && $file != "error_log" && $file != "php-errors.log" && $file != ".DS_Store" && substr($file, -8, 8) != "__MACOSX" && substr($file, -13, 13) != "wordpress.zip") {
if (is_dir($directory. "/" . $file)) {
if ($recursive) {
$array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
}
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
} else {
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $array_items;
}
echo "<h2>Searching for WordPress files ..</h2>";
if($_REQUEST['softacc'] != "Y") {
echo "<textarea id=\"outputArea\" name=\"outputArea\" rows=\"20\" cols=\"70\">";
}
flush();
$wp_files = array();
$diritems = directoryToArray(getcwd()."/", true);
asort($diritems);
foreach($diritems as $item) {
$item = str_replace("//", "/", $item);
$item = str_replace(getcwd()."/", "", $item);
$chkitem = count(explode("/", $item));
if ($chkitem == "1") {
if (!is_dir(getcwd()."/".$item) && strpos($_SERVER['SCRIPT_FILENAME'], $item) === FALSE && $item != "wp-config.php" && $item != "wp-admin/.htaccess") {
$wp_files[] = $item;
}
} elseif (substr($item, 0, 8) == "wp-admin" || substr($item, 0, 10) == "wp-content" || substr($item, 0, 11) == "wp-includes") {
$wp_files[] = $item;
}
}
$files = "";
foreach($wp_files as $file) {
if ($_REQUEST['softacc'] != "Y") {
echo "/{$file}\n";
}
ob_clean();
flush();
$files .= "{$file},";
}
$files = substr($files, 0, -1);
if ($_REQUEST['softacc'] == "Y") {
echo "Done";
} else {
echo "</textarea>";
echo "<br><br>Done";
}
if($_REQUEST["zipfilename"]) {
$zipfilename = $_REQUEST["zipfilename"];
}
$zipfoldername = trim($_REQUEST["zipfoldername"]);
if ($zipfoldername != "") {
echo "<h2>Creating \"{$zipfoldername}\" folder ...</h2>";
flush();
if (!file_exists($zipfoldername)) {
if (!mkdir($zipfoldername, 0755)) {
die('Failed to create '.$zipfoldername.' folder.');
}
}
echo "Done";
}
echo "<h2>Creating WordPress archive file ...</h2>";
flush();
if ($zipfoldername != "") {
if (file_exists('./' . $zipfoldername . '/' . $zipfilename . '_wordpress.zip')) {
if (!unlink('./' . $zipfoldername . '/' . $zipfilename . '_wordpress.zip')) {
die("Error : There was an error trying to delete the file (/{$zipfoldername}/{$zipfilename}_wordpress.zip).");
}
}
$archive = new PclZip('./' . $zipfoldername . '/' . $zipfilename . '_wordpress.zip');
} else {
$archive = new PclZip($zipfilename . '_wordpress.zip');
}
$v_list = $archive->create("{$files}", PCLZIP_OPT_ADD_PATH, "wordpress");
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
}
if ($zipfoldername != "") {
echo "/{$zipfoldername}/{$zipfilename}_wordpress.zip (";
echo _filesize(filesize("./" . $zipfoldername . "/{$zipfilename}_wordpress.zip"), 2);
} else {
echo "{$zipfilename}_wordpress.zip (";
echo _filesize(filesize("./{$zipfilename}_wordpress.zip"), 2);
}
if($_REQUEST['softacc'] == "Y") {
echo ")
Created Successfully. ";
} else {
echo ") <br><br> Created Successfully. ";
}
if (file_exists('masterblog.sql')) {
if (!unlink('masterblog.sql')) {
die("Error : There was an error trying to delete the file (masterblog.sql).");
}
}
if ($_REQUEST['softacc'] != "Y") {
if ($zipfoldername != "") {
$fullurltozip = get_current_url() . "/{$zipfoldername}/{$zipfilename}_wordpress.zip";
} else {
$fullurltozip = get_current_url() . "/{$zipfilename}_wordpress.zip";    
}
echo "<br><br><hr><br>Master Blog (ZIP File) complete URL for the Software:<br><br><a href=\"" . $fullurltozip . "\" style=\"text-decoration:none;\">" . $fullurltozip . "</a><br><br>";
echo '</body></html>';
}
?>