/** * ListDirs * @path path to a system directory * @return array of all directories in that path */ public static function ListDirs($path = '.') { $dirs = array(); foreach (new DirectoryIterator($path) as $file) { if ($file->isDir() && !$file->isDot()) { $dirs[] = duplicator_safe_path($file->getPathname()); } } return $dirs; }
function resursiveZip($directory) { try { $folderPath = duplicator_safe_path($directory); //EXCLUDE: Snapshot directory if (strstr($folderPath, DUPLICATOR_SSDIR_PATH) || empty($folderPath)) { return; } //EXCLUDE: Directory Exclusions List if (is_array($GLOBALS['duplicator_bypass-array'])) { foreach ($GLOBALS['duplicator_bypass-array'] as $val) { if (duplicator_safe_path($val) == $folderPath) { duplicator_log("path filter found: {$val}", 2); return; } } } $dh = new DirectoryIterator($folderPath); foreach ($dh as $file) { if (!$file->isDot()) { $fullpath = "{$folderPath}/{$file}"; $localpath = str_replace($this->rootFolder, '', $folderPath); $localname = empty($localpath) ? '' : ltrim("{$localpath}/", '/'); $filename = $file->getFilename(); if ($file->isDir()) { if (!in_array($fullpath, $GLOBALS['duplicator_bypass-array'])) { $this->zipArchive->addEmptyDir("{$localname}{$filename}"); @set_time_limit(0); duplicator_fcgi_flush(); } $this->resursiveZip($fullpath); } else { //Check filter extensions $ext = @pathinfo($fullpath, PATHINFO_EXTENSION); if ($ext == '' || !in_array($ext, $this->skipNames)) { $this->zipArchive->addFile("{$folderPath}/{$filename}", "{$localname}{$filename}"); } } $this->limitItems++; } } //Check if were over our count if ($this->limitItems > $this->limit) { duplicator_log("log:class.zip=>new open handle {$this->zipArchive->numFiles}"); $this->zipArchive->close(); $this->zipArchive->open($this->zipFilePath, ZIPARCHIVE::CREATE); $this->limitItems = 0; duplicator_fcgi_flush(); } @closedir($dh); } catch (Exception $e) { duplicator_log("log:class.zip=>runtime error: " . $e); } }
<?php /** WordPress Administration Bootstrap see: http://codex.wordpress.org/Roles_and_Capabilities#export Must be logged in from the WordPress Admin */ require_once '../../../../wp-admin/admin.php'; require_once '../define.php'; if (!current_user_can('level_8')) { die("You must be a WordPress Administrator to view the Duplicator logs."); } $logs = glob(DUPLICATOR_SSDIR_PATH . '/*.log'); if (count($logs)) { @chmod(duplicator_safe_path($logs[0]), 0644); } if (count($logs)) { @usort($logs, create_function('$a,$b', 'return filemtime($b) - filemtime($a);')); } if (isset($_GET['logname'])) { $logname = trim($_GET['logname']); //prevent escaping the folder $validFiles = array_map('basename', $logs); if (validate_file($logname, $validFiles) > 0) { //Invalid filename provided, don't use it unset($logname); } //done with validFiles unset($validFiles); } if (!isset($logname) || !$logname) { $logname = basename($logs[0]); }
function resursiveZip($directory) { try { $folderPath = duplicator_safe_path($directory); if (!($dh = opendir($folderPath))) { return false; } //EXCLUDE: Snapshot directory if (strstr($folderPath, DUPLICATOR_SSDIR_PATH)) { return; } //EXCLUDE: Directory Exclusions List if ($GLOBALS['duplicator_bypass-array'] != null) { foreach ($GLOBALS['duplicator_bypass-array'] as $val) { if (duplicator_safe_path($val) == $folderPath) { duplicator_log("path filter found: {$val}", 2); return; } } } /* Legacy: Excludes empty diretories and files with no extention while (false !== ($file = @readdir($dh))) { if ($file != '.' && $file != '..') { $fullpath = "{$folderPath}/{$file}"; if(is_dir($fullpath)) { duplicator_fcgi_flush(); $this->resursiveZip($fullpath); } else if(is_file($fullpath) && is_readable($fullpath)) { //Check filter extensions if(!in_array(@pathinfo($fullpath, PATHINFO_EXTENSION), $this->skipNames)) { $localpath = str_replace($this->rootFolder, '', $folderPath); $localname = empty($localpath) ? '' : ltrim("{$localpath}/", '/'); $this->zipArchive->addFile("{$folderPath}/{$file}", "{$localname}{$file}"); } } $this->limitItems++; } } */ while (false !== ($file = @readdir($dh))) { if ($file != '.' && $file != '..') { $fullpath = "{$folderPath}/{$file}"; $localpath = str_replace($this->rootFolder, '', $folderPath); $localname = empty($localpath) ? '' : ltrim("{$localpath}/", '/'); if (is_dir($fullpath)) { duplicator_fcgi_flush(); $this->zipArchive->addEmptyDir("{$localname}{$file}"); $this->resursiveZip($fullpath); } else { if (is_file($fullpath) && is_readable($fullpath)) { //Check filter extensions $ext = @pathinfo($fullpath, PATHINFO_EXTENSION); if ($ext == '' || !in_array($ext, $this->skipNames)) { $this->zipArchive->addFile("{$folderPath}/{$file}", "{$localname}{$file}"); } } } $this->limitItems++; } } //Check if were over our count if ($this->limitItems > $this->limit) { duplicator_log("log:class.zip=>new open handle {$this->zipArchive->numFiles}"); $this->zipArchive->close(); $this->zipArchive->open($this->zipFilePath, ZIPARCHIVE::CREATE); $this->limitItems = 0; duplicator_fcgi_flush(); } closedir($dh); } catch (Exception $e) { duplicator_log("log:class.zip=>runtime error: " . $e); } }
_e("Email a notice when completed", 'wpduplicator'); ?> </label><br/> <input type="text" name="email_others" id="email_others" value="<?php echo esc_html($GLOBALS['duplicator_opts']['email_others']); ?> " placeholder="mail1@mysite.com;mail2@mysite.com;" title="<?php _e("WP-admin email is included. Add extra emails semicolon separated.", 'wpduplicator'); ?> " /> <br /> </fieldset><br/> <!-- FILTERS --> <?php $uploads = wp_upload_dir(); $upload_dir = duplicator_safe_path($uploads['basedir']); ?> <fieldset> <legend><b><?php _e("Exclusion Filters", 'wpduplicator'); ?> </b></legend> <label for="dir_bypass" title="<?php _e("Separate all filters by semicolon", 'wpduplicator'); ?> "><?php _e("Directories", 'wpduplicator'); ?> : </label> <div class='dup-quick-links'> <a href="javascript:void(0)" onclick="Duplicator.Pack.OptionsAddExcludePath('<?php
?> </label></th> <td> <input type="checkbox" name="uninstall_files" id="uninstall_files" <?php echo $uninstall_files ? 'checked="checked"' : ''; ?> /> <label for="uninstall_files"><?php _e("Delete entire snapshot directory when removing plugin", 'wpduplicator'); ?> </label><br/> <p class="description"><?php _e("Snapshot Directory", 'wpduplicator'); ?> : <?php echo duplicator_safe_path(DUPLICATOR_SSDIR_PATH); ?> </p> </td> </tr> </table> <p class="submit" style="margin: 20px 0px 0xp 5px;"> <div style="border-top: 1px solid #efefef"></div><br/> <input type="submit" name="submit" id="submit" class="button-primary" value="<?php _e("Save Settings", 'wpduplicator'); ?> " style="display: inline-block;"/> </p>
/** * DUPLICATOR_TASK_SAVE * Saves options associted with a packages tasks * * @return string A message about the action * - log:act__settings=>saved */ function duplicator_task_save() { //defaults add_option('duplicator_options', ''); $skip_ext = str_replace(array(' ', '.'), "", $_POST['skip_ext']); $by_pass_array = explode(";", $_POST['dir_bypass']); $by_pass_clean = ""; foreach ($by_pass_array as $val) { if (strlen($val) >= 2) { $by_pass_clean .= duplicator_safe_path(trim(rtrim($val, "/\\"))) . ";"; } } $duplicator_opts = array('dbhost' => $_POST['dbhost'], 'dbname' => $_POST['dbname'], 'dbuser' => $_POST['dbuser'], 'url_new' => rtrim($_POST['url_new'], '/'), 'email-me' => $_POST['email-me'], 'email_others' => $_POST['email_others'], 'skip_ext' => str_replace(",", ";", $skip_ext), 'dir_bypass' => $by_pass_clean, 'log_level' => $_POST['log_level']); update_option('duplicator_options', serialize($duplicator_opts)); die("log:act__task_save=>saved"); }
<!-- PRE-ZIP OVERVIEW --> <b><?php _e('Pre-Zip Overview', 'wpduplicator'); ?> :</b> <span id='dup-sys-scannow-data'> <a href="javascript:void(0)" onclick="Duplicator.Pack.ScanRootDirectory()"><?php _e("Scan Now", 'wpduplicator'); ?> </a> </span><br/> <b>W3 Total Cache:</b> <?php $w3tc_path = duplicator_safe_path(WP_CONTENT_DIR) . '/w3tc'; if (file_exists($w3tc_path) && !strstr($GLOBALS['duplicator_opts']['dir_bypass'], $w3tc_path)) { ?> <div class="dup-sys-fail"><?php _e("Cache Directory Found", 'wpduplicator'); ?> .</div> <a href="javascript:void(0)" onclick="Duplicator.Pack.OptionsAppendCachePath('<?php echo addslashes($w3tc_path); ?> ')"><?php _e("Add to exclusion path now", 'wpduplicator'); ?> </a> <?php } elseif (strstr($GLOBALS['duplicator_opts']['dir_bypass'], $w3tc_path)) {
/** * DUPLICATOR_CREATE_SNAPSHOTPATH * Creates the snapshot directory if it doesn't already exisit */ function duplicator_init_snapshotpath() { $path_wproot = duplicator_safe_path(DUPLICATOR_WPROOTPATH); $path_ssdir = duplicator_safe_path(DUPLICATOR_SSDIR_PATH); $path_plugin = duplicator_safe_path(DUPLICATOR_PLUGIN_PATH); //-------------------------------- //CHMOD DIRECTORY ACCESS //wordpress root directory @chmod($path_wproot, 0755); //snapshot directory @mkdir($path_ssdir, 0755); @chmod($path_ssdir, 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("HTML/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("HTML/1.1 404 Not Found", true, 404);} exit(); ?>'); @fclose($tokenfile); //SSDIR: Create .htaccess $htfile = @fopen($path_ssdir . '/.htaccess', 'w'); @fwrite($htfile, "Options -Indexes"); @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 . 'files/dtoken.php', 'w'); @fwrite($tokenfile2, '<?php @error_reporting(0); @require_once("../../../../wp-admin/admin.php"); global $wp_query; $wp_query->set_404(); header("HTML/1.1 404 Not Found", true, 404); header("Status: 404 Not Found"); @include(get_template_directory () . "/404.php"); ?>'); @fclose($tokenfile2); }
function duplicator_uninstall() { global $wpdb; $table_name = $wpdb->prefix . "duplicator"; $wpdb->query("DROP TABLE `{$table_name}`"); delete_option('duplicator_version_plugin'); delete_option('duplicator_options'); if ($GLOBALS['duplicator_opts']['rm_snapshot']) { $ssdir = duplicator_safe_path(DUPLICATOR_SSDIR_PATH); //Sanity check for strange setup $check = glob("{$ssdir}/wp-config.php"); if (count($check) == 0) { //PHP is sometimes flaky so lets do a 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}/*_package.zip") as $file) { if (strstr($file, '_package.zip')) { @unlink("{$file}"); } } foreach (glob("{$ssdir}/*.log") as $file) { if (strstr($file, '.log')) { @unlink("{$file}"); } } //Check for core files and only continue removing data if the snapshots directory //has not been edited by 3rd party sources, this helps to keep the system stable $files = glob("{$ssdir}/*"); if (is_array($files) && count($files) == 3) { $defaults = array("{$ssdir}/index.php", "{$ssdir}/robots.txt", "{$ssdir}/dtoken.php"); $compare = array_diff($defaults, $files); if (count($compare) == 0) { foreach ($defaults as $file) { @unlink("{$file}"); } @unlink("{$ssdir}/.htaccess"); @rmdir($ssdir); } //No packages have ever been created } else { if (is_array($files) && count($files) == 1) { $defaults = array("{$ssdir}/index.php"); $compare = array_diff($defaults, $files); if (count($compare) == 0) { @unlink("{$ssdir}/index.php"); @rmdir($ssdir); } } } } } }
?> :</b> <span id='dup-sys-scannow-data'> <a href="javascript:void(0)" onclick="Duplicator.Pack.ScanRootDirectory()"><?php _e("Scan Now", 'wpduplicator'); ?> </a> </span><br/> <b><?php _e('Cached Data', 'wpduplicator'); ?> :</b> <?php $cache_path = duplicator_safe_path(WP_CONTENT_DIR) . '/cache'; if (file_exists($cache_path) && !strstr($GLOBALS['duplicator_opts']['dir_bypass'], $cache_path)) { ?> <div class="dup-sys-fail"><?php _e("Cache Directory Found", 'wpduplicator'); ?> .</div> <a href="javascript:void(0)" onclick="Duplicator.Pack.OptionsAppendCachePath('<?php echo addslashes($cache_path); ?> ')"><?php _e("Add to exclusion path now", 'wpduplicator'); ?> </a> <?php } elseif (strstr($GLOBALS['duplicator_opts']['dir_bypass'], $cache_path)) {
<td><?php _e("Root Path", 'wpduplicator'); ?> </td> <td><?php echo DUPLICATOR_WPROOTPATH; ?> </td> </tr> <tr> <td><?php _e("Plugins Path", 'wpduplicator'); ?> </td> <td><?php echo duplicator_safe_path(WP_PLUGIN_DIR); ?> </td> </tr> <tr> <td><?php _e("Packages Built", 'wpduplicator'); ?> </td> <td> <?php echo get_option('duplicator_pack_passcount', 0); ?> <i style="font-size:11px"><?php _e("The number of successful packages created.", 'wpduplicator');
/** * DUPLICATOR_SETTINGS * Saves plugin settings * * @return string A message about the action * - log:act__settings=>saved */ function duplicator_settings() { //defaults add_option('duplicator_options', ''); $skip_ext = str_replace(array(' ', '.'), "", $_POST['skip_ext']); $by_pass_array = explode(";", $_POST['dir_bypass']); $by_pass_clean = ""; foreach ($by_pass_array as $val) { if (strlen($val) >= 2) { $by_pass_clean .= duplicator_safe_path(trim(rtrim($val, "/\\"))) . ";"; } } if (is_numeric($_POST['max_memory'])) { $maxmem = $_POST['max_memory'] < 256 ? 256 : $_POST['max_memory']; } else { $maxmem = 256; } $duplicator_opts = array('dbhost' => $_POST['dbhost'], 'dbname' => $_POST['dbname'], 'dbuser' => $_POST['dbuser'], 'dbiconv' => $_POST['dbiconv'], 'url_new' => rtrim($_POST['url_new'], '/'), 'email-me' => $_POST['email-me'], 'email_others' => $_POST['email_others'], 'max_time' => $_POST['max_time'], 'max_memory' => preg_replace('/\\D/', '', $maxmem) . 'M', 'skip_ext' => str_replace(",", ";", $skip_ext), 'dir_bypass' => $by_pass_clean, 'log_level' => $_POST['log_level'], 'rm_snapshot' => $_POST['rm_snapshot']); update_option('duplicator_options', serialize($duplicator_opts)); die("log:act__settings=>saved"); }
function resursiveZip($directory) { try { $folderPath = duplicator_safe_path($directory); //EXCLUDE: Snapshot directory if (strstr($folderPath, DUPLICATOR_SSDIR_PATH) || empty($folderPath)) { return; } //EXCLUDE: Directory Exclusions List if (is_array($GLOBALS['duplicator_bypass-array'])) { foreach ($GLOBALS['duplicator_bypass-array'] as $val) { if (duplicator_safe_path($val) == $folderPath) { duplicator_log("path filter found: {$val}", 2); return; } } } //Notes: $file->getExtension() is not reliable as it silently fails at least in php 5.2.17 //when a file has a permission such as 705 falling back to pathinfo is more stable $dh = new DirectoryIterator($folderPath); foreach ($dh as $file) { if (!$file->isDot()) { $fullpath = "{$folderPath}/{$file}"; $localpath = str_replace($this->rootFolder, '', $folderPath); $localname = empty($localpath) ? '' : ltrim("{$localpath}/", '/'); $filename = $file->getFilename(); if ($file->isDir()) { if (!in_array($fullpath, $GLOBALS['duplicator_bypass-array'])) { if ($file->isReadable() && $this->zipArchive->addEmptyDir("{$localname}{$filename}")) { $this->countDirs++; $this->resursiveZip($fullpath); } else { duplicator_log("WARNING: Unable to add directory: {$fullpath}"); } } } else { if ($file->isFile() && $file->isReadable()) { if ($this->fileExtActive) { $ext = @pathinfo($fullpath, PATHINFO_EXTENSION); if (!in_array($ext, $this->skipNames) || empty($ext)) { $this->zipArchive->addFile("{$folderPath}/{$filename}", "{$localname}{$filename}"); $this->countFiles++; } } else { $this->zipArchive->addFile("{$folderPath}/{$filename}", "{$localname}{$filename}"); $this->countFiles++; } } else { if ($file->isLink()) { $this->countLinks++; } } } $this->limitItems++; } } //Check if were over our count //This process seems to slow things down. /* if ($this->limitItems > $this->limit) { $currentfilecount = $this->countDirs + $this->countFiles; duplicator_log("ADDED=>ZIP HANDLE: ({$currentfilecount})"); $this->zipArchive->close(); $this->zipArchive->open($this->zipFilePath, ZIPARCHIVE::CREATE); $this->limitItems = 0; duplicator_fcgi_flush(); }*/ @closedir($dh); } catch (Exception $e) { duplicator_error("ERROR: Runtime error in class.zip.php resursiveZip. \nERROR INFO: {$e}"); } }
/** * DUPLICATOR_TASK_SAVE * Saves options associted with a packages tasks * * @return string A message about the action * - log:act__settings=>saved */ function duplicator_task_save() { //defaults add_option('duplicator_options', ''); //post data un-stripped, as WP magic quotes _POST for some reason... $post = stripslashes_deep($_POST); $skip_ext = str_replace(array(' ', '.'), "", $post['skip_ext']); $by_pass_array = explode(";", $post['dir_bypass']); $by_pass_clean = ""; foreach ($by_pass_array as $val) { if (strlen($val) >= 2) { $by_pass_clean .= duplicator_safe_path(trim(rtrim($val, "/\\"))) . ";"; } } $duplicator_opts = array('dbhost' => $post['dbhost'], 'dbname' => $post['dbname'], 'dbuser' => $post['dbuser'], 'ssl_admin' => $post['ssl_admin'], 'ssl_login' => $post['ssl_login'], 'cache_wp' => $post['cache_wp'], 'cache_path' => $post['cache_path'], 'url_new' => rtrim($post['url_new'], '/'), 'email-me' => $post['email-me'], 'email_others' => $post['email_others'], 'skip_ext' => str_replace(",", ";", $skip_ext), 'dir_bypass' => $by_pass_clean, 'log_level' => $post['log_level']); update_option('duplicator_options', serialize($duplicator_opts)); die("log:act__task_save=>saved"); }