Code:
/*** BEGIN CONFIG ***/
$sellertwo = 'sellertwo.com';
$whmUser = 'sellertwouser';
$whmPass = 'sellertwopass';
$bkUpsellertwo = true;
$sellertwoCpTheme = 'x3';
/*
Destination for the backup...
$destinType = '/';
$destinType = 'ftp';
$destinType = 'passiveftp';
*/
$destinType = 'ftp';
$destinServer = 'ftp.destin.com';//only if $destinServer = 'ftp' or 'passiveftp'
$destinUser = 'ftpuser';//only if $destinServer = 'ftp' or 'passiveftp'
$destinPass = 'ftppass';//only if $destinServer = 'ftp' or 'passiveftp'
$destinEmail = 'mail@whateveremail.com';
$logType = 'file';
$logFileName = 'backup_full.txt';
$useSsl = false;
$day = strtolower(date('l'));
$dst_dir = $day;
$dir = $dst_dir;
$conn_id = ftp_connect($Server) or die("Couldn't connect to $destinServer");destin
if (@ftp_login($conn_id, $destinUser, $destinPass))
{ echo "Connected as $destinUser@$destinServer\n";
$ar_files = ftp_nlist($conn_id, $dst_dir);
if (is_array($ar_files))
{ for ($i=0;$i<sizeof($ar_files);$i++)
{ $st_file = basename($ar_files[$i]);
if($st_file == '.' || $st_file == '..') continue;
if (ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1)
{ ftp_rmAll($conn_id, $dst_dir.'/'.$st_file);
}
else { ftp_delete($conn_id, $dst_dir.'/'.$st_file);
} } }
$flag = ftp_rmdir($conn_id, $dst_dir);
}
else { header ("location : backup_full.php");
}
if ( @ftp_chdir( $conn_id, $dir ) )
{ $original_directory = ftp_pwd( $conn_id );
ftp_chdir( $conn_id, $original_directory );
}
else { if (ftp_mkdir($conn_id, $dir))
{ echo '<p>successfully created '.$dir.'</p>';
}
else { echo '<p>There was a problem while creating '.$dir.'</p>';
}
}
ftp_close($conn_id);
$domains = 'example1.com,example2.net';
$domains = '';
set_time_limit(0);
$time_start = getMicroTime();
if (!extension_loaded('curl')) {
dl('php_curl.' .PHP_SHLIB_SUFFIX) or die("Could not load curl extension");
}
if($useSsl) { $protocol = 'https://';
$cpPort = '2083';
$whmPort = '2087';
writeLog("Using SSL.\n");
}
else {
$protocol = 'http://';
$cpPort = '2082';
$whmPort = '2086';
writeLog("Not using SSL.\n");
}
$domains = trim($domains);
if(!empty($domains)){
$chkDoms = true;
$domains = explode(',',$domains);
foreach($domains as $d){
$domains[] = trim($d);
}
}
else {
$chkDoms = false;
$domains = array();
}
//$postFields = urlencode("destin=$destinType&server=$destinServer&user=$destinPass&pass=$destinPass&email=$destinEmail");
$postFields = '';
$postArray = array();
$postArray['destin'] = $destinType;
$postArray['server'] = $destinServer;
$postArray['user'] = $destinUser;
$postArray['pass'] = $destinPass;
$postArray['email'] = $destinEmail;
$postArray['rdir'] = $day;
$thingy = '';
foreach ($postArray as $k=>$v)
{
$thingy.= "$k=".utf8_encode($v).'&';
}
$postFields = substr($thingy,0,-1);
writeLog("Retrieving WHM accounts page...\n");
$accountsPage = getByCurl("$protocol$sellertwo:$whmPort/scripts/fetchcsv",$whmUser,$whmPass);
//var_dump($accountsPage );
$accounts = array();
$accounts = explode("\n", trim($accountsPage ));
//var_dump($accounts);
$account_records = array();
foreach ($accounts as $row) {
$account_records[] = explode(',', $row);
}
writeLog("Parsing accounts...\n");
//var_dump($account_records);
//die('here');
foreach($account_records as $match) {
$accountDom= '';
$accountUser= '';
$accountTheme = '';
$r = '';
$fullUrl = '';
$accountDom= strip_tags(trim($match[1]));
if($chkDoms)
if(!in_array($accountDom,$domains)) continue;
$accountUser= strip_tags(trim($match[3]));
$accountTheme = strip_tags(trim($match[14]));
$fullUrl = "$protocol$accountDom:$cpPort/frontend/$accountTheme/backup/dofullbackup.html";
writeLog("Requesting backup of $accountDom...\n");
$r =& getByCurl($fullUrl,$accountUser,$whmPass,array('CURLOPT_POST'=>$postFields));
if($r === false){
writeLog("Backup request of $accountDomcaused an unknown error.\n");
}
else {
writeLog("Backup request of $accountDomcomplete.\n");
}
//writeLog("\n\n--$accountDom--\n\n$r\n\n------\n\n");
}
if($bkUpsellertwo){
$fullUrl = "$protocol$sellertwo:$cpPort/frontend/$sellertwoCpTheme/backup/dofullbackup.html";
writeLog("Requesting backup of $sellertwo...\n");
$r =& getByCurl($fullUrl,$accountUser,$whmPass,array('CURLOPT_POST'=>$postFields));
}
$time_end = getMicroTime();
$time = $time_end - $time_start;
writeLog("Elapsed time: ".round($time,2)." seconds.\n");
function getByCurl($url, $user = '', $pass = '',$extra = '') {
global $useSsl;
$ch = curl_init();
//tells curl to save result in a variable instead of outputing to page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt ($ch, CURLOPT_COOKIEJAR, './cookie.txt');
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
if(!empty($extra) && is_array($extra)){
foreach($extra as $opt=>$val){
switch($opt){
case 'CURLOPT_REFERER':
curl_setopt($ch,CURLOPT_REFERER,$val);
break;
case 'CURLOPT_POST':
case 'CURLOPT_POSTFIELDS':
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$val);
break;
}
}
}
if($useSsl){
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function writeLog($entry) {
global $logType,$logFileName;
$method = strtolower($logType);
$entry = date('r').' - '.$entry;
if($method == 'file') {
$fp = fopen($logFileName,'ab');
fwrite($fp, $entry);
fclose($fp);
} elseif($method == 'echo'){
echo nl2br($entry);//browser
flush();
}
return;
}
function getMicroTime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$text = file_get_contents('backup_full.txt.txt');
echo $text;
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message = stripslashes($text);
mail("email_address","Full Backup Initiated",$message,"from_email_address");
unlink('backup_full.txt.txt');
?>
Bookmarks