*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
if(@is_file("../cloner.config.php")){
echo "
Access denied, if you are trying to restore a backup, please move the restore script in another directory!
";
exit;
}
@set_time_limit(3600);
@ini_set("error_reporting", E_ALL^E_NOTICE);
###################### Do not edit Below #############################
$g_pcltar_lib_dir = "./";
require "TAR.php";
$_CONFIG['my_version'] = "3.0.1";
$_CONFIG['script_name'] = "XCloner.php";
$_CONFIG['sql_usefile'] = "";
$_CONFIG['filesLimit'] = 100;
$_CONFIG['seek'] = 0;
if(isset($_REQUEST['sql_setfile']))
$_CONFIG['sql_usefile'] = $_REQUEST['sql_setfile'];
if(trim($_CONFIG['sql_usefile']) == "")
$_CONFIG['sql_usefile'] = "database-sql.sql";
if(isset($_REQUEST['strrep'])){
setcookie ("strrep_c", "", time() - 3600);
setcookie("strrep_c", str_replace("\r\n","*-*",stripslashes($_REQUEST['strrep'])), time()+3600); /* expire in 1 hour */
}else{
$_REQUEST['strrep'] = str_replace("*-*", "\r\n", $_COOKIE['strrep_c']);
}
if ($handle = opendir('./')) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))){
$ext = substr($file,strlen($file)-4,strlen($file));
if(($file!='XCloner.php')&&($file!='..')&&($file!='.')&&(($ext=='.tgz')||($ext=='.tar'))){
$_CONFIG[versions][] = $file;
}
}
closedir($handle);
}else{
echo "Unable to open my directory for reading and listing!";exit;
}
######################################################################
$_CONFIG['output_path'] = $_REQUEST['output_path'];
$_CONFIG['output_url'] = $_REQUEST['output_url_pref']."://".$_REQUEST['output_url'];
$_REQUEST['output_url'] = str_replace("/###","",$_REQUEST['output_url']."###");
$_REQUEST['output_url'] = str_replace("###","",$_REQUEST['output_url']);
if(function_exists('filter_var')){
$_CONFIG['output_url'] = filter_var($_CONFIG['output_url'], FILTER_SANITIZE_URL);
}
$_CONFIG['tmp'] = $_REQUEST['output_path'];
if($_REQUEST['files_skip'] == 1)
$_REQUEST['do_database'] = 1;
if($_REQUEST['fpos'])
$_CONFIG['seek'] = $_REQUEST['fpos'];
$filepath =$_SERVER["SCRIPT_FILENAME"];
$pathinfo = pathinfo($filepath);
$startscript = $pathinfo['dirname'];
$_CONFIG[group] = $groupinfo[name];
$_CONFIG[owner] =$ownerinfo[name];
###################### FRONT AREA ###################################
//setCache();
?>
XCloner Restore - - Backup and Restore Made Easy
The database details provided are incorrect and/or empty. Unable to connect to mysql server");
@mysql_query("CREATE database $DBname;");
if (!@mysql_select_db($DBname)) {
die(" Could not connect to $DBname database! Please make sure the database exists and that you assigned the mysql user to it...");
}
mysql_query("SET sql_mode='';");
if($_REQUEST['charset_of_file']!="")
mysql_query("SET NAMES ".$_REQUEST['charset_of_file']."");
else
mysql_query("SET NAMES utf8;");
}
if($_REQUEST['do_database'] != 1){
############ DATABASE ONLY RESTRICTION##################################################
########################### START FTP MODE #################################
if($_REQUEST[transfer_mode]==2){
$_CONFIG[output_path] = $_CONFIG[output_path]."/archive_tmp/";
@mkdir($_CONFIG[output_path]);
// set up basic connection
$conn_id = @ftp_connect($_REQUEST[ftp_server], $_REQUEST[ftp_port]) or die("Could not connect to $_REQUEST[ftp_server] on port $_REQUEST[ftp_port]! Ftp connection has failed!");
// login with username and password
$login_result = @ftp_login($conn_id, $_REQUEST[ftp_user], $_REQUEST[ftp_pass]) or die("Could not login to ftp server for user $_REQUEST[ftp_user] and provided pass! Ftp connection has failed!");
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to ".$_REQUEST[ftp_server].":".$_REQUEST[ftp_port]." for user ".$_REQUEST[ftp_user]."";
return;
} else {
echo " Connected to $_REQUEST[ftp_server], for user $_REQUEST[ftp_user], starting transfer... ";
}
$ftp_dir_original = ftp_pwd($conn_id);
@ftp_mkdir($conn_id,$_REQUEST[ftp_path]);
// try to change the directory to somedir
if (@ftp_chdir($conn_id, $_REQUEST[ftp_path])) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
echo "Couldn't change directory to $_REQUEST[ftp_path], please verify that the ftp location exists or use the \"Install files directly\" option! \n";
return;
}
@ftp_chdir($conn_id, $ftp_dir_original);
}
########################## END FTP MODE ######################################
##### START extract ######
if($_REQUEST['refresh'] < 1){
$ext = substr($file, strlen($file)-4, strlen($file));
if($_REQUEST['file_utilities'] != '1'){
$tar_object = new Archive_Tar($file);
if($_REQUEST['manual_ftp']){
$tar_object->_openRead();
fseek($tar_object->_file, $_CONFIG['seek']);
$seek = $tar_object->_extractList($_CONFIG['output_path'], $return, "partial", "", "", $_CONFIG['filesLimit']);
$seek = $seek - 512;//reverse 512 bytes
if($seek > 0){
$backupSize = filesize($file);
$rurl = rurl($seek, $backupSize);
$percent = sprintf("%.2f",($seek*100)/$backupSize);
echo "
Processing files - ".$percent."%
";
echo "";
return;
}
$_REQUEST['fpos'] = 0;
$_REQUEST['chunk'] = 0;
}
else{
$tar_object->extract($_CONFIG['output_path']);
#$tar_object->extractList("backups/perm.txt", $_CONFIG['output_path']);
}
}else{
if($ext == '.tgz') $compress = 'z';
else $compress = '';
shell_exec("tar -x".$compress."pf $file -C $_CONFIG[output_path]");
}
}
##### END extract ######
$new_arr = array();
#@chmod($_CONFIG[output_path], 0777);
$tran_file = $_CONFIG[output_path]."/transfer.txt";
if($_REQUEST[transfer_mode]==2){
# initialise list arrays, directories and files separately and array counters for them
$excludedFolders = array();
$d_arr = array(); $d = 0;
$ds_arr = array();
$f_arr = array(); $f = 0;
$s_arr = array(); $s = 0;
$d_arr[$d] = $_CONFIG[output_path];
if($_REQUEST['refresh'] < 1){
# obtain the list of files by recursing the mambo file store
recurseFiles($d_arr, $ds_arr, $f_arr, $s_arr, $d, $f, $s, $excludedFolders , '', $_CONFIG[output_path]);
recurseFiles($d_arr, $ds_arr, $f_arr, $s_arr, $d, $f, $s, $d_arr , '', $_CONFIG[output_path]);
sort($d_arr);
sort($f_arr);
$new_arr = array_merge($d_arr, $f_arr);
if($_REQUEST[transfer_mode]==2)
if($fp = fopen($tran_file, "w")){
foreach($new_arr as $file){
fwrite($fp, $file."\n");
}
fclose($fp);
}else{
echo "Unable to write to directory ".$_CONFIG[output_path]."! Please check that this directory is writeable!"; return;
}
else{};
}else{
$content = "";
$new_arr = file($tran_file);
}
if(sizeof($new_arr) != 0 )
$percn = sprintf("%.2f",($_REQUEST[next] * 100)/sizeof($new_arr));
if($percn > sizeof($new_arr))
$percn = sizeof($new_arr);
}
if($_REQUEST['refresh'] == 1){
echo "
Transfering $percn% of ".sizeof($new_arr)." files through ftp
";
echo "All should be done! Click here to continue... ";
return ;
}
if (($DBcreated=='on')&&($_REQUEST['do_database'] == 1)){
$sqlfile = $_CONFIG[output_path]."/administrator/backups/".$_CONFIG['sql_usefile'];
if(!file_exists($sqlfile)){
echo "Unable to read the database backup file $sqlfile , database was not imported!";
}else{
if($_REQUEST['manual_sql'])
$errors = populate_db_manual( $db, $sqlfile);
else
$errors = populate_db( $db, $sqlfile);
if(sizeof($errors)>0){
echo "There were some errors while importing the database: ";
echo "";
exit;
}else{
@unlink($_CONFIG[output_path]."/administrator/backups/".$_CONFIG['sql_usefile']);
}
echo "
Database populated...
";
}
}
###################################################################################
if($_REQUEST['do_database'] != 1) {
$vars = "";
foreach($_REQUEST as $key=>$value)
$vars .= $key.'='.@urlencode($value).'&';
#$href = "XCloner.php?".$vars."do_database=1";
$href = rurl()."&do_database=1";
echo " Please click here to continue with database import...";
return;
}else{
echo " All should be done! Click here to continue...
";
return ;
}
}
function write_config($file){
global $_CONFIG;
if(@$fp = fopen($file, "r")){
$config_data = "";
while(!feof($fp))
$config_data .= fread($fp, 1024);
fclose($fp);
}
if ($_REQUEST[DBcreated] == 'on'){
$config_data = str_replace("define('DB_HOST', '", "define('DB_HOST', '".$_REQUEST[mysql_server]."');#", $config_data);
$config_data = str_replace("define('DB_USER', '", "define('DB_USER', '".$_REQUEST[mysql_username]."');#", $config_data);
$config_data = str_replace("define('DB_PASSWORD', '", "define('DB_PASSWORD', '".$_REQUEST[mysql_pass]."');#", $config_data);
$config_data = str_replace("define('DB_NAME', '", "define('DB_NAME', '".$_REQUEST[mysql_db]."');#", $config_data);
$liveurl = $_CONFIG['output_url'];
$config_data = str_replace("define('DB_HOST", "define('WP_SITEURL','".$liveurl."');\ndefine('WP_HOME','".$liveurl."');\ndefine('RELOCATE',true);\ndefine('DB_HOST", $config_data);
$config_data = str_replace("define('WP_SITEURL', '", "define('WP_SITEURL', '".$liveurl."');#", $config_data);
$config_data = str_replace("define('WP_HOME', '", "define('WP_HOME', '".$liveurl."');#", $config_data);
}
if($_REQUEST['transfer_mode'] == 2){
$config_data = str_replace('$'.'ftp_host =',"$"."ftp_host ='".$_REQUEST[ftp_server]."';#", $config_data);
$config_data = str_replace('$'.'ftp_port =',"$"."ftp_port ='".$_REQUEST[ftp_port]."';#", $config_data);
$config_data = str_replace('$'.'ftp_user =',"$"."ftp_user ='".$_REQUEST[ftp_user]."';#", $config_data);
$config_data = str_replace('$'.'ftp_pass =',"$"."ftp_pass ='".$_REQUEST[ftp_pass]."';#", $config_data);
$config_data = str_replace('$'.'ftp_root =',"$"."ftp_root ='".$_REQUEST[ftp_path]."';#", $config_data);
}else{
$config_data = str_replace('$'.'ftp_enable =',"$"."ftp_enable ='0';#", $config_data);
}
$config_data = str_replace('$'.'live_site =',"$"."live_site ='".$_CONFIG['output_url']."';#", $config_data);
$config_data = str_replace('$'.'absolute_path =',"$"."absolute_path ='".$_CONFIG['output_path']."';#", $config_data);
if ($fp = fopen($file, "w")) {
fwrite( $fp, $config_data);
fclose( $fp );
} else {
return false;
} // if
return true;
}
function step1(){
global $_CONFIG;
$ftarget = $_CONFIG[output_path]."/".$_REQUEST[ver];
if($_REQUEST['refresh'] < 1)
if(!is_writable($_CONFIG[output_path])){
echo "Directory ".$_CONFIG[output_path]." is not writeable or does not exists! Could not continue...";
return ;
}
$ftarget = $_REQUEST[ver];
if((!file_exists($ftarget)) and (!$_REQUEST['files_skip'])){
echo "Could not continue, unable to read the clone backup file! Please make sure you copied the backup in the same directory as XCloner.php ";
return;
}
step2($ftarget);
return;
}
function start() {
global $_CONFIG,$pathinfo;
$pdir = str_replace($_CONFIG['script_name'], "", $_SERVER["SCRIPT_FILENAME"]);
$purl = $_SERVER['HTTP_HOST'].str_replace("/".$_CONFIG['script_name'],"", $_SERVER['SCRIPT_NAME']);
?>
Skip files restore
Restore files permissions
Restore by using the server utilities(tar)
Incremental transfer
Ftp server:
:
Ftp username:
Ftp password:
Ftp upload path:
ftp root path of where the backup will be restored
*after hitting submit please wait for the package to get unarchived and transfered through ftp if it is the case!
Security Note: After restore delete the XCloner.php script from your server