<? /*
// File: restore.php
// Purpose: restores
// Author: Peter Drake <hide@address.com>
*/
function get_file_perm($filepath) {
$decperms = fileperms($filepath);
$octalperms = sprintf("%o",$decperms);
// -4 value should include ugo and strange bits for files and folders
return substr($octalperms,-4);
}
////////////////////////////////////////////////////////
/// cp function/////////////////////////////////
////////////////////////////////////////////////////////
function cp($wf, $wto) { // it moves $wf to $wto
$p = get_file_perm($wf);
$poa = posix_getpwuid(fileowner($wf));
$po = $poa['name'];
$goa = posix_getgrgid(filegroup($wf));
$go = $goa['name'];
mkdir($wto);
chown($wto,$po);
chgrp($wto,$go);
exec("chmod ".$p." ".$wto);
$arr = ls_a($wf);
foreach ($arr as $fn) {
if ($fn) {
$fl = "$wf/$fn";
$flto = "$wto/$fn";
if (is_dir($fl)) {
cp($fl,$flto);
} else {
$fp = get_file_perm($fl);
$foa = posix_getpwuid(fileowner($fl));
$fo = $foa['name'];
$goa = posix_getgrgid(filegroup($wf));
$go = $goa['name'];
copy($fl,$flto);
chown($flto, $fo);
chgrp($flto,$go);
exec("chmod ".$fp." ".$flto);
}
}
}
}
///////////////////////////////////////////////////
/// ls_a function////////////////////////
// This function lists a directory.
// ANd is needed for the cp function.
function ls_a($wh){
if ($handle = opendir($wh)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." ) {
if(!$files) $files="$file";
else $files="$file\n$files";
}
}
closedir($handle);
}
$arr=explode("\n",$files);
return $arr;
}
for($i=0; $i<sizeOf($restoreFiles); $i++) {
$filelocation = $restoreFiles[$i];
$curArray = explode("/", $filelocation);
$domainname = $curArray[2];
$filename = $curArray[4];
webcp_log(2,0,'restore.php',"Restore: Started for ".$domainname,0,$echo);
chdir("/tmp");
mkdir($filename, 0777);
chdir("/tmp/".$filename);
copy($filelocation, "/tmp/".$filename."/".$filename);
exec("tar -xvzf /tmp/".$filename."/".$filename);
$filesfrom = substr($cfg['webdir'], 1, strlen($cfg['webdir']) - 1)."/".$domainname;
$filesto = $cfg['webdir']."/".$domainname;
cp($filesfrom, $filesto);
chdir("/tmp");
exec("rm ".$filename." -rf");
}
?>