/** * createFromTemplate * Generates the final installer file from the template file */ private function createFromTemplate($template) { global $wpdb; DUP_Log::Info("INSTALLER FILE: Preping for use"); $installer = DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP) . "/{$this->Package->NameHash}_installer.php"; //$tablePrefix = (is_multisite()) ? $wpdb->get_blog_prefix() : $wpdb->prefix; //Option values to delete at install time $deleteOpts = $GLOBALS['DUPLICATOR_OPTS_DELETE']; $replace_items = array("fwrite_url_old" => get_option('siteurl'), "fwrite_package_name" => "{$this->Package->NameHash}_archive.zip", "fwrite_package_notes" => $this->Package->Notes, "fwrite_secure_name" => $this->Package->NameHash, "fwrite_url_new" => $this->Package->Installer->OptsURLNew, "fwrite_dbhost" => $this->Package->Installer->OptsDBHost, "fwrite_dbname" => $this->Package->Installer->OptsDBName, "fwrite_dbuser" => $this->Package->Installer->OptsDBUser, "fwrite_dbpass" => '', "fwrite_ssl_admin" => $this->Package->Installer->OptsSSLAdmin, "fwrite_ssl_login" => $this->Package->Installer->OptsSSLLogin, "fwrite_cache_wp" => $this->Package->Installer->OptsCacheWP, "fwrite_cache_path" => $this->Package->Installer->OptsCachePath, "fwrite_wp_tableprefix" => $wpdb->prefix, "fwrite_opts_delete" => json_encode($deleteOpts), "fwrite_blogname" => esc_html(get_option('blogname')), "fwrite_wproot" => DUPLICATOR_WPROOTPATH, "fwrite_duplicator_version" => DUPLICATOR_VERSION); if (file_exists($template) && is_readable($template)) { $err_msg = "ERROR: Unable to read/write installer. \nERROR INFO: Check permission/owner on file and parent folder.\nInstaller File = <{$installer}>"; $install_str = $this->parseTemplate($template, $replace_items); empty($install_str) ? DUP_Log::Error("{$err_msg}", "DUP_Installer::createFromTemplate => file-empty-read") : DUP_Log::Info("INSTALLER FILE: Template parsed with new data"); //INSTALLER FILE $fp = !file_exists($installer) ? fopen($installer, 'x+') : fopen($installer, 'w'); if (!$fp || !fwrite($fp, $install_str, strlen($install_str))) { DUP_Log::Error("{$err_msg}", "DUP_Installer::createFromTemplate => file-write-error"); } @fclose($fp); } else { DUP_Log::Error("Installer Template missing or unreadable.", "Template [{$template}]"); } @unlink($template); DUP_Log::Info("INSTALLER FILE: Complete [{$installer}]"); }
/** * Gets the system checks which are not required * @return array An array of system checks */ public static function GetChecks() { $checks = array(); //WEB SERVER $web_test1 = false; foreach ($GLOBALS['DUPLICATOR_SERVER_LIST'] as $value) { if (stristr($_SERVER['SERVER_SOFTWARE'], $value)) { $web_test1 = true; break; } } $checks['SRV']['WEB']['model'] = $web_test1; $checks['SRV']['WEB']['ALL'] = $web_test1 ? 'Good' : 'Warn'; //PHP SETTINGS $php_test1 = ini_get("open_basedir"); $php_test1 = empty($php_test1) ? true : false; $php_test2 = ini_get("max_execution_time"); $php_test2 = $php_test2 > DUPLICATOR_SCAN_TIMEOUT || (strcmp($php_test2, 'Off') == 0 || $php_test2 == 0) ? true : false; $php_test3 = function_exists('mysqli_connect'); $checks['SRV']['PHP']['openbase'] = $php_test1; $checks['SRV']['PHP']['maxtime'] = $php_test2; $checks['SRV']['PHP']['mysqli'] = $php_test3; $checks['SRV']['PHP']['ALL'] = $php_test1 && $php_test2 && $php_test3 ? 'Good' : 'Warn'; //WORDPRESS SETTINGS global $wp_version; $wp_test1 = version_compare($wp_version, DUPLICATOR_SCAN_MIN_WP) >= 0 ? true : false; //Core Files $files = array(); $files['wp-config.php'] = file_exists(DUP_Util::SafePath(DUPLICATOR_WPROOTPATH . '/wp-config.php')); $wp_test2 = $files['wp-config.php']; //Cache $Package = DUP_Package::GetActive(); $cache_path = DUP_Util::SafePath(WP_CONTENT_DIR) . '/cache'; $dirEmpty = DUP_Util::IsDirectoryEmpty($cache_path); $dirSize = DUP_Util::GetDirectorySize($cache_path); $cach_filtered = in_array($cache_path, explode(';', $Package->Archive->FilterDirs)); $wp_test3 = $cach_filtered || $dirEmpty || $dirSize < DUPLICATOR_SCAN_CACHESIZE ? true : false; $checks['SRV']['WP']['version'] = $wp_test1; $checks['SRV']['WP']['core'] = $wp_test2; $checks['SRV']['WP']['cache'] = $wp_test3; $checks['SRV']['WP']['ALL'] = $wp_test1 && $wp_test2 && $wp_test3 ? 'Good' : 'Warn'; return $checks; }
/** * Gets the system checks which are not required * @return array An array of system checks */ public static function GetChecks() { $checks = array(); //CHK-SRV-100: PHP SETTINGS $php_test1 = ini_get("open_basedir"); $php_test1 = empty($php_test1) ? true : false; $php_test2 = ini_get("max_execution_time"); $php_test2 = $php_test2 > DUPLICATOR_SCAN_TIMEOUT || strcmp($php_test2, 'Off') == 0 || $php_test2 == 0 ? 'Good' : 'Warn'; $checks['CHK-SRV-100'] = $php_test1 && $php_test2 ? 'Good' : 'Warn'; //CHK-SRV-101: WORDPRESS SETTINGS //Version global $wp_version; $version_test = version_compare($wp_version, DUPLICATOR_SCAN_MIN_WP) >= 0 ? true : false; //Cache $Package = DUP_Package::GetActive(); $cache_path = DUP_Util::SafePath(WP_CONTENT_DIR) . '/cache'; $dirEmpty = DUP_Util::IsDirectoryEmpty($cache_path); $dirSize = DUP_Util::GetDirectorySize($cache_path); $cach_filtered = in_array($cache_path, explode(';', $Package->Archive->FilterDirs)); $cache_test = $cach_filtered || $dirEmpty || $dirSize < DUPLICATOR_SCAN_CACHESIZE ? true : false; //Core Files $files = array(); $files['wp-config.php'] = file_exists(DUP_Util::SafePath(DUPLICATOR_WPROOTPATH . '/wp-config.php')); $files_test = $files['wp-config.php']; $checks['CHK-SRV-101'] = $files_test && $cache_test && $version_test ? 'Good' : 'Warn'; //CHK-SRV-102: WEB SERVER $servers = $GLOBALS['DUPLICATOR_SERVER_LIST']; $test = false; foreach ($servers as $value) { if (stristr($_SERVER['SERVER_SOFTWARE'], $value)) { $test = true; break; } } $checks['CHK-SRV-102'] = $test ? 'Good' : 'Warn'; //RESULTS $result = in_array('Warn', $checks); $checks['Success'] = !$result; return $checks; }
/** * Creates the snapshot directory if it doesn't already exisit */ public static function InitSnapshotDirectory() { $path_wproot = DUP_Util::SafePath(DUPLICATOR_WPROOTPATH); $path_ssdir = DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH); $path_plugin = DUP_Util::SafePath(DUPLICATOR_PLUGIN_PATH); //-------------------------------- //CHMOD DIRECTORY ACCESS //wordpress root directory @chmod($path_wproot, 0755); //snapshot directory @mkdir($path_ssdir, 0755); @chmod($path_ssdir, 0755); //snapshot tmp directory $path_ssdir_tmp = $path_ssdir . '/tmp'; @mkdir($path_ssdir_tmp, 0755); @chmod($path_ssdir_tmp, 0755); //plugins dir/files @chmod($path_plugin . 'files', 0755); //-------------------------------- //FILE CREATION //SSDIR: Create Index File $ssfile = @fopen($path_ssdir . '/index.php', 'w'); @fwrite($ssfile, '<?php error_reporting(0); if (stristr(php_sapi_name(), "fcgi")) { $url = "http://" . $_SERVER["HTTP_HOST"]; header("Location: {$url}/404.html");} else { header("HTTP/1.1 404 Not Found", true, 404);} exit(); ?>'); @fclose($ssfile); //SSDIR: Create token file in snapshot $tokenfile = @fopen($path_ssdir . '/dtoken.php', 'w'); @fwrite($tokenfile, '<?php error_reporting(0); if (stristr(php_sapi_name(), "fcgi")) { $url = "http://" . $_SERVER["HTTP_HOST"]; header("Location: {$url}/404.html");} else { header("HTTP/1.1 404 Not Found", true, 404);} exit(); ?>'); @fclose($tokenfile); //SSDIR: Create .htaccess $storage_htaccess_off = DUP_Settings::Get('storage_htaccess_off'); if ($storage_htaccess_off) { @unlink($path_ssdir . '/.htaccess'); } else { $htfile = @fopen($path_ssdir . '/.htaccess', 'w'); $htoutput = "Options -Indexes"; @fwrite($htfile, $htoutput); @fclose($htfile); } //SSDIR: Robots.txt file $robotfile = @fopen($path_ssdir . '/robots.txt', 'w'); @fwrite($robotfile, "User-agent: * \nDisallow: /" . DUPLICATOR_SSDIR_NAME . '/'); @fclose($robotfile); //PLUG DIR: Create token file in plugin $tokenfile2 = @fopen($path_plugin . 'installer/dtoken.php', 'w'); @fwrite($tokenfile2, '<?php @error_reporting(0); @require_once("../../../../wp-admin/admin.php"); global $wp_query; $wp_query->set_404(); header("HTTP/1.1 404 Not Found", true, 404); header("Status: 404 Not Found"); @include(get_template_directory () . "/404.php"); ?>'); @fclose($tokenfile2); }
// If uninstall not called from WordPress, then exit if (!defined('WP_UNINSTALL_PLUGIN')) { exit; } require_once 'define.php'; require_once 'classes/settings.php'; require_once 'classes/utility.php'; global $wpdb; $DUP_Settings = new DUP_Settings(); $table_name = $wpdb->prefix . "duplicator_packages"; $wpdb->query("DROP TABLE `{$table_name}`"); delete_option('duplicator_version_plugin'); //Remvoe entire wp-snapshots directory if (DUP_Settings::Get('uninstall_files')) { $ssdir = DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH); $ssdir_tmp = DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP); //Sanity check for strange setup $check = glob("{$ssdir}/wp-config.php"); if (count($check) == 0) { //PHP sanity check foreach (glob("{$ssdir}/*_database.sql") as $file) { if (strstr($file, '_database.sql')) { @unlink("{$file}"); } } foreach (glob("{$ssdir}/*_installer.php") as $file) { if (strstr($file, '_installer.php')) { @unlink("{$file}"); } } foreach (glob("{$ssdir}/*_archive.zip") as $file) {
private function dirsToArray_New($path) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); $files = iterator_to_array($iterator); $items = array(); foreach ($files as $file) { if ($file->isDir()) { $items[] = DUP_Util::SafePath($file->getRealPath()); } } return $items; }
private function getDirs() { $rootPath = DUP_Util::SafePath(rtrim(DUPLICATOR_WPROOTPATH, '//')); $this->Dirs = array(); //If the root directory is a filter then we will only need the root files if (in_array($this->PackDir, $this->FilterDirsAll)) { $this->Dirs[] = $this->PackDir; } else { $this->Dirs = $this->dirsToArray($rootPath); $this->Dirs[] = $this->PackDir; } //Filter Directories //Invalid test contains checks for: characters over 250, invlaid characters, //empty string and directories ending with period (Windows incompatable) foreach ($this->Dirs as $key => $val) { //Remove path filter directories foreach ($this->FilterDirsAll as $item) { if (strstr($val, $item . '/') || $val == $item) { unset($this->Dirs[$key]); continue 2; } } //Locate invalid directories and warn $name = basename($val); $invalid_test = strlen($val) > 250 || preg_match('/(\\/|\\*|\\?|\\>|\\<|\\:|\\|\\|)/', $name) || trim($name) == "" || strrpos($name, '.') == strlen($name) - 1 && substr($name, -1) == '.'; if ($invalid_test || preg_match('/[^\\x20-\\x7f]/', $name)) { $this->FilterInfo->Dirs->Warning[] = DUP_Encoding::toUTF8($val); } //Dir is not readble remove and flag if (!is_readable($this->Dirs[$key])) { unset($this->Dirs[$key]); $this->FilterInfo->Dirs->Unreadable[] = $val; $this->FilterDirsAll[] = $val; } } }
<li class="tabs"><a href="javascript:void(0)" onclick="Duplicator.Pack.ToggleOptTabs(1, this)"><?php _e('Files', 'wpduplicator'); ?> </a></li> <li><a href="javascript:void(0)"onclick="Duplicator.Pack.ToggleOptTabs(2, this)"><?php _e('Database', 'wpduplicator'); ?> </a></li> </ul> <!-- TAB1: PACKAGE --> <div class="tabs-panel" id="dup-pack-opts-tabs-panel-1"> <!-- FILTERS --> <?php $uploads = wp_upload_dir(); $upload_dir = DUP_Util::SafePath($uploads['basedir']); ?> <fieldset> <legend><b> <i class="fa fa-filter"></i> <?php _e("Filters", 'wpduplicator'); ?> </b></legend> <div class="dup-enable-filters"> <input type="checkbox" id="filter-on" name="filter-on" onclick="Duplicator.Pack.ToggleFileFilters()" <?php echo $Package->Archive->FilterOn ? "checked='checked'" : ""; ?> /> <label for="filter-on"><?php _e("Enable Filters", 'wpduplicator'); ?>
private function getDirs() { $rootPath = DUP_Util::SafePath(rtrim(DUPLICATOR_WPROOTPATH, '//')); $this->Dirs = array(); //If the root directory is a filter then we will only need the root files if (in_array($this->PackDir, $this->FilterDirsAll)) { $this->Dirs[] = $this->PackDir; } else { $this->Dirs = $this->dirsToArray($rootPath, $this->FilterDirsAll); $this->Dirs[] = $this->PackDir; } //Filter Directories //Invalid test contains checks for: characters over 250, invlaid characters, //empty string and directories ending with period (Windows incompatable) foreach ($this->Dirs as $key => $val) { //WARNING: Find OS items that may have issues // was commented out in pro $name = basename($val); $warn_test = strlen($val) > 250 || preg_match('/(\\/|\\*|\\?|\\>|\\<|\\:|\\|\\|)/', $name) || trim($name) == "" || strrpos($name, '.') == strlen($name) - 1 && substr($name, -1) == '.' || preg_match('/[^\\x20-\\x7f]/', $name); if ($warn_test) { $this->FilterInfo->Dirs->Warning[] = DUP_Encoding::toUTF8($val); } //UNREADABLE: Directory is unreadable flag it if (!is_readable($this->Dirs[$key])) { unset($this->Dirs[$key]); $this->FilterInfo->Dirs->Unreadable[] = $val; $this->FilterDirsAll[] = $val; } } }
<td><?php _e("ABSPATH", 'wpduplicator'); ?> </td> <td><?php echo ABSPATH; ?> </td> </tr> <tr> <td><?php _e("Plugins Path", 'wpduplicator'); ?> </td> <td><?php echo DUP_Util::SafePath(WP_PLUGIN_DIR); ?> </td> </tr> <tr> <td><?php _e("Loaded PHP INI", 'wpduplicator'); ?> </td> <td><?php echo php_ini_loaded_file(); ?> </td> </tr> <tr> <td class='dup-settings-diag-header' colspan="2">WordPress</td>
<?php require_once DUPLICATOR_PLUGIN_PATH . '/views/javascript.php'; require_once DUPLICATOR_PLUGIN_PATH . '/views/inc.header.php'; $logs = glob(DUPLICATOR_SSDIR_PATH . '/*.log'); if ($logs != false && count($logs)) { usort($logs, create_function('$a,$b', 'return filemtime($b) - filemtime($a);')); @chmod(DUP_Util::SafePath($logs[0]), 0644); } $logname = isset($_GET['logname']) ? trim($_GET['logname']) : ""; $refresh = isset($_POST['refresh']) && $_POST['refresh'] == 1 ? 1 : 0; $auto = isset($_POST['auto']) && $_POST['auto'] == 1 ? 1 : 0; //Check for invalid file if (isset($_GET['logname'])) { $validFiles = array_map('basename', $logs); if (validate_file($logname, $validFiles) > 0) { unset($logname); } unset($validFiles); } if (!isset($logname) || !$logname) { $logname = count($logs) > 0 ? basename($logs[0]) : ""; } $logurl = get_site_url(null, '', is_ssl() ? 'https' : 'http') . '/' . DUPLICATOR_SSDIR_NAME . '/' . $logname; $logfound = strlen($logname) > 0 ? true : false; ?> <style> div#dup-refresh-count {display: inline-block} table#dup-log-panels {width:100%; } td#dup-log-panel-left {width:75%;}
private function parseDirectoryFilter($dirs = "") { $filter_dirs = ""; foreach (explode(";", $dirs) as $val) { if (strlen($val) >= 2) { $filter_dirs .= DUP_Util::SafePath(trim(rtrim($val, "/\\"))) . ";"; } } return $filter_dirs; }
</label><br/> </td> </tr> <tr valign="top"> <th scope="row"><label><?php _e("Storage", 'wpduplicator'); ?> </label></th> <td> <?php _e("Full Path", 'wpduplicator'); ?> : <?php echo DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH); ?> <br/><br/> <input type="checkbox" name="storage_htaccess_off" id="storage_htaccess_off" <?php echo $storage_htaccess_off ? 'checked="checked"' : ''; ?> /> <label for="storage_htaccess_off"><?php _e("Disable .htaccess File In Storage Directory", 'wpduplicator'); ?> </label> <p class="description"> <?php _e("Disable if issues occur when downloading installer/archive files.", 'wpduplicator'); ?> </p>
private static function recurseDirsWithFilters($directory) { $currentPath = DUP_Util::SafePath($directory); //EXCLUDE: Snapshot directory if (strstr($currentPath, DUPLICATOR_SSDIR_PATH) || empty($currentPath)) { return; } //DIRECTORIES $dh = new DirectoryIterator($currentPath); foreach ($dh as $file) { if (!$file->isDot()) { $fullPath = "{$currentPath}/{$file}"; $zipPath = str_replace(self::$compressDir, '', $currentPath); $zipPath = empty($zipPath) ? $file : ltrim("{$zipPath}/{$file}", '/'); if ($file->isDir()) { if (!in_array($fullPath, self::$filterDirsArray)) { if (preg_match('/(\\/|\\*|\\?|\\>|\\<|\\:|\\|\\|)/', $file) || trim($file) == "") { DUP_Log::Info("WARNING: Excluding invalid directory - [{$fullPath}]"); } else { if ($file->isReadable() && self::$zipArchive->addEmptyDir($zipPath)) { self::$countDirs++; self::recurseDirsWithFilters($fullPath); } else { DUP_Log::Info("WARNING: Unable to add directory: {$fullPath}"); } } } else { DUP_Log::Info("- filter@ [{$fullPath}]"); } } else { if ($file->isFile() && $file->isReadable()) { if (self::$filterExtsOn) { $ext = @pathinfo($fullPath, PATHINFO_EXTENSION); if (!in_array($ext, self::$filterExtsArray) || empty($ext)) { self::$zipArchive->addFile($fullPath, $zipPath); self::$countFiles++; } } else { self::$zipArchive->addFile($fullPath, $zipPath) ? self::$countFiles++ : DUP_Log::Info("WARNING: Unable to add file: {$fullPath}"); } } else { if ($file->isLink()) { self::$countLinks++; } } } self::$limitItems++; $fileSize = filesize($fullPath); $fileSize = $fileSize ? $fileSize : 0; self::$size = self::$size + $fileSize; } } @closedir($dh); if (self::$networkFlush) { self::flushResponse(); } }
private function runDirStats($directory) { $currentPath = DUP_Util::SafePath($directory); //EXCLUDE: Snapshot directory if (strstr($currentPath, DUPLICATOR_SSDIR_PATH) || empty($currentPath)) { return; } $dh = new DirectoryIterator($currentPath); foreach ($dh as $file) { if (!$file->isDot()) { $nextpath = "{$currentPath}/{$file}"; if ($file->isDir()) { if (!in_array($nextpath, $this->filterDirsArray)) { if (preg_match('/(\\/|\\*|\\?|\\>|\\<|\\:|\\|\\|)/', $file) || trim($file) == "") { array_push($this->InvalidFileList, $nextpath); } $result = $this->runDirStats($nextpath); $this->DirCount++; } } else { if ($file->isFile() && $file->isReadable()) { if (!in_array(@pathinfo($nextpath, PATHINFO_EXTENSION), $this->filterExtsArray)) { $fileSize = filesize($nextpath); $fileSize = $fileSize ? $fileSize : 0; $this->Size += $fileSize; $this->FileCount++; if (strlen($nextpath) > 200 || preg_match('/(\\/|\\*|\\?|\\>|\\<|\\:|\\|\\|)/', $file)) { array_push($this->InvalidFileList, $nextpath); } if ($fileSize > DUPLICATOR_SCAN_BIGFILE) { array_push($this->BigFileList, $nextpath . ' [' . DUP_Util::ByteSize($fileSize) . ']'); } } } else { if ($file->isLink()) { $this->LinkCount++; } } } } } @closedir($dh); }
/** * CREATE * Creates the zip file and adds the SQL file to the archive */ public static function Create(DUP_Archive $archive) { try { $timerAllStart = DUP_Util::GetMicrotime(); $package_zip_flush = DUP_Settings::Get('package_zip_flush'); self::$compressDir = rtrim(DUP_Util::SafePath($archive->PackDir), '/'); self::$sqlPath = DUP_Util::SafePath("{$archive->Package->StorePath}/{$archive->Package->Database->File}"); self::$zipPath = DUP_Util::SafePath("{$archive->Package->StorePath}/{$archive->File}"); self::$zipArchive = new ZipArchive(); self::$networkFlush = empty($package_zip_flush) ? false : $package_zip_flush; $filterDirs = empty($archive->FilterDirs) ? 'not set' : $archive->FilterDirs; $filterExts = empty($archive->FilterExts) ? 'not set' : $archive->FilterExts; $filterOn = $archive->FilterOn ? 'ON' : 'OFF'; //LOAD SCAN REPORT $json = file_get_contents(DUPLICATOR_SSDIR_PATH_TMP . "/{$archive->Package->NameHash}_scan.json"); self::$scanReport = json_decode($json); DUP_Log::Info("\n********************************************************************************"); DUP_Log::Info("ARCHIVE (ZIP):"); DUP_Log::Info("********************************************************************************"); $isZipOpen = self::$zipArchive->open(self::$zipPath, ZIPARCHIVE::CREATE) === TRUE; if (!$isZipOpen) { DUP_Log::Error("Cannot open zip file with PHP ZipArchive.", "Path location [" . self::$zipPath . "]"); } DUP_Log::Info("ARCHIVE DIR: " . self::$compressDir); DUP_Log::Info("ARCHIVE FILE: " . basename(self::$zipPath)); DUP_Log::Info("FILTERS: *{$filterOn}*"); DUP_Log::Info("DIRS: {$filterDirs}"); DUP_Log::Info("EXTS: {$filterExts}"); DUP_Log::Info("----------------------------------------"); DUP_Log::Info("COMPRESSING"); DUP_Log::Info("SIZE:\t" . self::$scanReport->ARC->Size); DUP_Log::Info("STATS:\tDirs " . self::$scanReport->ARC->DirCount . " | Files " . self::$scanReport->ARC->FileCount); //ADD SQL $isSQLInZip = self::$zipArchive->addFile(self::$sqlPath, "database.sql"); if ($isSQLInZip) { DUP_Log::Info("SQL ADDED: " . basename(self::$sqlPath)); } else { DUP_Log::Error("Unable to add database.sql to archive.", "SQL File Path [" . self::$sqlath . "]"); } self::$zipArchive->close(); self::$zipArchive->open(self::$zipPath, ZipArchive::CREATE); //ZIP DIRECTORIES foreach (self::$scanReport->ARC->Dirs as $dir) { if (self::$zipArchive->addEmptyDir(ltrim(str_replace(self::$compressDir, '', $dir), '/'))) { self::$countDirs++; } else { //Don't warn when dirtory is the root path if (strcmp($dir, rtrim(self::$compressDir, '/')) != 0) { DUP_Log::Info("WARNING: Unable to zip directory: '{$dir}'" . rtrim(self::$compressDir, '/')); } } } /* ZIP FILES: Network Flush * This allows the process to not timeout on fcgi * setups that need a response every X seconds */ if (self::$networkFlush) { foreach (self::$scanReport->ARC->Files as $file) { if (self::$zipArchive->addFile($file, ltrim(str_replace(self::$compressDir, '', $file), '/'))) { self::$limitItems++; self::$countFiles++; } else { DUP_Log::Info("WARNING: Unable to zip file: {$file}"); } //Trigger a flush to the web server after so many files have been loaded. if (self::$limitItems > DUPLICATOR_ZIP_FLUSH_TRIGGER) { $sumItems = self::$countDirs + self::$countFiles; self::$zipArchive->close(); self::$zipArchive->open(self::$zipPath); self::$limitItems = 0; DUP_Util::FcgiFlush(); DUP_Log::Info("Items archived [{$sumItems}] flushing response."); } } //Normal } else { foreach (self::$scanReport->ARC->Files as $file) { if (self::$zipArchive->addFile($file, ltrim(str_replace(self::$compressDir, '', $file), '/'))) { self::$countFiles++; } else { DUP_Log::Info("WARNING: Unable to zip file: {$file}"); } } } DUP_Log::Info(print_r(self::$zipArchive, true)); //-------------------------------- //LOG FINAL RESULTS DUP_Util::FcgiFlush(); $zipCloseResult = self::$zipArchive->close(); $zipCloseResult ? DUP_Log::Info("COMPRESSION RESULT: '{$zipCloseResult}'") : DUP_Log::Error("ZipArchive close failure.", "This hosted server may have a disk quota limit.\nCheck to make sure this archive file can be stored."); $timerAllEnd = DUP_Util::GetMicrotime(); $timerAllSum = DUP_Util::ElapsedTime($timerAllEnd, $timerAllStart); self::$zipFileSize = @filesize(self::$zipPath); DUP_Log::Info("COMPRESSED SIZE: " . DUP_Util::ByteSize(self::$zipFileSize)); DUP_Log::Info("ARCHIVE RUNTIME: {$timerAllSum}"); DUP_Log::Info("MEMORY STACK: " . DUP_Server::GetPHPMemory()); } catch (Exception $e) { DUP_Log::Error("Runtime error in package.archive.zip.php constructor.", "Exception: {$e}"); } }
<a href="javascript:void(0)" onclick="Duplicator.Pack.AddExcludePath('<?php echo rtrim(DUPLICATOR_WPROOTPATH, '/'); ?> ')">[<?php _e("root path", 'wpduplicator'); ?> ]</a> <a href="javascript:void(0)" onclick="Duplicator.Pack.AddExcludePath('<?php echo rtrim($upload_dir, '/'); ?> ')">[<?php _e("wp-uploads", 'wpduplicator'); ?> ]</a> <a href="javascript:void(0)" onclick="Duplicator.Pack.AddExcludePath('<?php echo DUP_Util::SafePath(WP_CONTENT_DIR); ?> /cache')">[<?php _e("cache", 'wpduplicator'); ?> ]</a> <a href="javascript:void(0)" onclick="jQuery('#filter-dirs').val('')"><?php _e("(clear)", 'wpduplicator'); ?> </a> </div> <textarea name="filter-dirs" id="filter-dirs" placeholder="/full_path/exclude_path1;/full_path/exclude_path2;"><?php echo str_replace(";", ";\n", esc_textarea($Package->Archive->FilterDirs)); ?> </textarea><br/> <label class="no-select" title="<?php
</a> <div id="data-srv-wp-all"></div> </div> <div class='dup-scan-info dup-info-box'> <?php //VERSION CHECK echo '<span id="data-srv-wp-version"></span> <b>' . DUP_Util::__('WordPress Version') . ":</b> '{$wp_version}' <br/>"; echo '<small>'; printf(DUP_Util::__('It is recommended to have a version of WordPress that is greater than %1$s'), DUPLICATOR_SCAN_MIN_WP); echo '</small>'; //CORE FILES echo '<hr size="1" /><span id="data-srv-wp-core"></span> <b>' . DUP_Util::__('Core Files') . "</b> <br/>"; echo '<small>'; DUP_Util::_e("If the scanner is unable to locate the wp-config.php file in the root directory, then you will need to manually copy it to its new location."); echo '</small>'; //CACHE DIR $cache_path = $cache_path = DUP_Util::SafePath(WP_CONTENT_DIR) . '/cache'; $cache_size = DUP_Util::ByteSize(DUP_Util::GetDirectorySize($cache_path)); echo '<hr size="1" /><span id="data-srv-wp-cache"></span> <b>' . DUP_Util::__('Cache Path') . ":</b> '{$cache_path}' ({$cache_size}) <br/>"; echo '<small>'; DUP_Util::_e("Cached data will lead to issues at install time and increases your archive size. It is recommended to empty your cache directory at build time. Use caution when removing data from the cache directory. If you have a cache plugin review the documentation for how to empty it; simply removing files might cause errors on your site. The cache size minimum threshold is currently set at "); echo DUP_Util::ByteSize(DUPLICATOR_SCAN_CACHESIZE) . '.'; echo '</small>'; ?> </div> </div> </div><!-- end .dup-panel --> </div><!-- end .dup-panel-panel --> <h2 style="font-size:18px; font-weight:bold; margin:-15px 0 0 10px"><i class="fa fa-file-archive-o"></i> <?php DUP_Util::_e('Archive'); ?>
private function parseDirectoryFilter($dirs = "") { $dirs = str_replace(array("\n", "\t", "\r"), '', $dirs); $filter_dirs = ""; $dir_array = array_unique(explode(";", $dirs)); foreach ($dir_array as $val) { if (strlen($val) >= 2) { $filter_dirs .= DUP_Util::SafePath(trim(rtrim($val, "/\\"))) . ";"; } } return $filter_dirs; }
/** * DUPLICATOR_PACKAGE_DELETE * Deletes the files and database record entries * * @return json A json message about the action. * Use console.log to debug from client */ function duplicator_package_delete() { DUP_Util::CheckPermissions('export'); check_ajax_referer('package_list', 'nonce'); try { global $wpdb; $json = array(); $post = stripslashes_deep($_POST); $tblName = $wpdb->prefix . 'duplicator_packages'; $postIDs = isset($post['duplicator_delid']) ? $post['duplicator_delid'] : null; $list = explode(",", $postIDs); $delCount = 0; if ($postIDs != null) { foreach ($list as $id) { $getResult = $wpdb->get_results($wpdb->prepare("SELECT name, hash FROM `{$tblName}` WHERE id = %d", $id), ARRAY_A); if ($getResult) { $row = $getResult[0]; $nameHash = "{$row['name']}_{$row['hash']}"; $delResult = $wpdb->query($wpdb->prepare("DELETE FROM `{$tblName}` WHERE id = %d", $id)); if ($delResult != 0) { //Perms @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_archive.zip"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_database.sql"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_installer.php"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_archive.zip"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_database.sql"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_installer.php"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_scan.json"), 0644); @chmod(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}.log"), 0644); //Remove @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_archive.zip")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_database.sql")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_installer.php")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_archive.zip")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_database.sql")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_installer.php")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}_scan.json")); @unlink(DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH . "/{$nameHash}.log")); //Unfinished Zip files $tmpZip = DUPLICATOR_SSDIR_PATH_TMP . "/{$nameHash}_archive.zip.*"; array_map('unlink', glob($tmpZip)); @unlink(DUP_Util::SafePath()); $delCount++; } } } } } catch (Exception $e) { $json['error'] = "{$e}"; die(json_encode($json)); } $json['ids'] = "{$postIDs}"; $json['removed'] = $delCount; die(json_encode($json)); }