/** * Sets the defaults if they have not been set * @return True if option value has changed, false if not or if update failed. */ public static function SetDefaults() { $default = array(); $default['version'] = self::$Version; //Flag used to remove the wp_options value duplicator_settings which are all the settings in this class $default['uninstall_settings'] = isset(self::$Data['uninstall_settings']) ? self::$Data['uninstall_settings'] : true; //Flag used to remove entire wp-snapshot directory $default['uninstall_files'] = isset(self::$Data['uninstall_files']) ? self::$Data['uninstall_files'] : true; //Flag used to remove all tables $default['uninstall_tables'] = isset(self::$Data['uninstall_tables']) ? self::$Data['uninstall_tables'] : true; //Flag used to show debug info $default['package_debug'] = isset(self::$Data['package_debug']) ? self::$Data['package_debug'] : false; //Flag used to enable mysqldump $default['package_mysqldump'] = isset(self::$Data['package_mysqldump']) ? self::$Data['package_mysqldump'] : false; //Optional mysqldump search path $default['package_mysqldump_path'] = isset(self::$Data['package_mysqldump_path']) ? self::$Data['package_mysqldump_path'] : ''; //Optional mysqldump search path $default['package_zip_flush'] = isset(self::$Data['package_zip_flush']) ? self::$Data['package_zip_flush'] : false; self::$Data = $default; return self::Save(); }
/** * 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); }
} } 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) < 6) { $defaults = array("{$ssdir}/index.php", "{$ssdir}/robots.txt", "{$ssdir}/dtoken.php"); $compare = array_diff($defaults, $files); //There might be a .htaccess file or index.php/html etc. if (count($compare) < 3) { foreach ($defaults as $file) { @unlink("{$file}"); } @unlink("{$ssdir}/.htaccess"); @rmdir($ssdir_tmp); @rmdir($ssdir); } } } } //Remove all Settings if (DUP_Settings::Get('uninstall_settings')) { DUP_Settings::Delete(); delete_option('duplicator_ui_view_state'); delete_option('duplicator_package_active'); }
private function phpDump() { global $wpdb; $wpdb->query("SET session wait_timeout = " . DUPLICATOR_DB_MAX_TIME); $handle = fopen($this->dbStorePath, 'w+'); $tables = $wpdb->get_col('SHOW TABLES'); $filterTables = isset($this->FilterTables) ? explode(',', $this->FilterTables) : null; $tblAllCount = count($tables); $tblFilterOn = $this->FilterOn ? 'ON' : 'OFF'; $qryLimit = DUP_Settings::Get('package_phpdump_qrylimit'); if (is_array($filterTables) && $this->FilterOn) { foreach ($tables as $key => $val) { if (in_array($tables[$key], $filterTables)) { unset($tables[$key]); } } } $tblCreateCount = count($tables); $tblFilterCount = $tblAllCount - $tblCreateCount; DUP_Log::Info("TABLES: total:{$tblAllCount} | filtered:{$tblFilterCount} | create:{$tblCreateCount}"); DUP_Log::Info("FILTERED: [{$this->FilterTables}]"); $sql_header = "/* DUPLICATOR MYSQL SCRIPT CREATED ON : " . @date("Y-m-d H:i:s") . " */\n\n"; $sql_header .= "SET FOREIGN_KEY_CHECKS = 0;\n\n"; fwrite($handle, $sql_header); //BUILD CREATES: //All creates must be created before inserts do to foreign key constraints foreach ($tables as $table) { //$sql_del = ($GLOBALS['duplicator_opts']['dbadd_drop']) ? "DROP TABLE IF EXISTS {$table};\n\n" : ""; //@fwrite($handle, $sql_del); $create = $wpdb->get_row("SHOW CREATE TABLE `{$table}`", ARRAY_N); @fwrite($handle, "{$create[1]};\n\n"); } //BUILD INSERTS: //Create Insert in 100 row increments to better handle memory foreach ($tables as $table) { $row_count = $wpdb->get_var("SELECT Count(*) FROM `{$table}`"); //DUP_Log::Info("{$table} ({$row_count})"); if ($row_count > $qryLimit) { $row_count = ceil($row_count / $qryLimit); } else { if ($row_count > 0) { $row_count = 1; } } if ($row_count >= 1) { fwrite($handle, "\n/* INSERT TABLE DATA: {$table} */\n"); } for ($i = 0; $i < $row_count; $i++) { $sql = ""; $limit = $i * $qryLimit; $query = "SELECT * FROM `{$table}` LIMIT {$limit}, {$qryLimit}"; $rows = $wpdb->get_results($query, ARRAY_A); if (is_array($rows)) { foreach ($rows as $row) { $sql .= "INSERT INTO `{$table}` VALUES("; $num_values = count($row); $num_counter = 1; foreach ($row as $value) { if (is_null($value) || !isset($value)) { $num_values == $num_counter ? $sql .= 'NULL' : ($sql .= 'NULL, '); } else { $num_values == $num_counter ? $sql .= '"' . @esc_sql($value) . '"' : ($sql .= '"' . @esc_sql($value) . '", '); } $num_counter++; } $sql .= ");\n"; } fwrite($handle, $sql); } } //Flush buffer if enabled if ($this->networkFlush) { DUP_Util::FcgiFlush(); } $sql = null; $rows = null; } $sql_footer = "\nSET FOREIGN_KEY_CHECKS = 1; \n\n"; $sql_footer .= "/* Duplicator WordPress Timestamp: " . date("Y-m-d H:i:s") . "*/\n"; $sql_footer .= "/* " . DUPLICATOR_DB_EOF_MARKER . " */\n"; fwrite($handle, $sql_footer); $wpdb->flush(); fclose($handle); }
function duplicator_wpfront_integrate() { if (DUP_Settings::Get('wpfront_integrate')) { do_action('wpfront_user_role_editor_duplicator_init', array('export', 'manage_options', 'read')); } }
<?php $view_state = DUP_UI::GetViewStateArray(); $ui_css_general = isset($view_state['dup-package-dtl-general-panel']) && $view_state['dup-package-dtl-general-panel'] ? 'display:block' : 'display:none'; $ui_css_storage = isset($view_state['dup-package-dtl-storage-panel']) && $view_state['dup-package-dtl-storage-panel'] ? 'display:block' : 'display:none'; $ui_css_archive = isset($view_state['dup-package-dtl-archive-panel']) && $view_state['dup-package-dtl-archive-panel'] ? 'display:block' : 'display:none'; $ui_css_install = isset($view_state['dup-package-dtl-install-panel']) && $view_state['dup-package-dtl-install-panel'] ? 'display:block' : 'display:none'; $link_sql = "{$package->StoreURL}{$package->NameHash}_database.sql"; $link_archive = "{$package->StoreURL}{$package->NameHash}_archive.zip"; $link_installer = "{$package->StoreURL}{$package->NameHash}_installer.php?get=1&file={$package->NameHash}_installer.php"; $link_log = "{$package->StoreURL}{$package->NameHash}.log"; $link_scan = "{$package->StoreURL}{$package->NameHash}_scan.json"; $debug_on = DUP_Settings::Get('package_debug'); $mysqldump_on = DUP_Settings::Get('package_mysqldump') && DUP_Database::GetMySqlDumpPath(); $mysqlcompat_on = isset($Package->Database->Compatible) && strlen($Package->Database->Compatible); $mysqlcompat_on = $mysqldump_on && $mysqlcompat_on ? true : false; $dbbuild_mode = $mysqldump_on ? 'mysqldump (fast)' : 'PHP (slow)'; ?> <style> /*COMMON*/ div.toggle-box {float:right; margin: 5px 5px 5px 0} div.dup-box {margin-top: 15px; font-size:14px; clear: both} table.dup-dtl-data-tbl {width:100%} table.dup-dtl-data-tbl tr {vertical-align: top} table.dup-dtl-data-tbl tr:first-child td {margin:0; padding-top:0 !important;} table.dup-dtl-data-tbl td {padding:0 6px 0 0; padding-top:15px !important;} table.dup-dtl-data-tbl td:first-child {font-weight: bold; width:150px} table.dup-sub-list td:first-child {white-space: nowrap; vertical-align: middle; width: 70px !important;} table.dup-sub-list td {white-space: nowrap; vertical-align:top; padding:0 !important; font-size:12px} div.dup-box-panel-hdr {font-size:14px; display:block; border-bottom: 1px dotted #efefef; margin:5px 0 5px 0; font-weight: bold; padding: 0 0 5px 0}
<?php $qryResult = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}duplicator_packages` ORDER BY id DESC", ARRAY_A); $qryStatus = $wpdb->get_results("SELECT status FROM `{$wpdb->prefix}duplicator_packages` WHERE status >= 100", ARRAY_A); $totalElements = count($qryResult); $statusCount = count($qryStatus); $package_debug = DUP_Settings::Get('package_debug'); ?> <style> div#dup-list-alert-nodata {padding:50px 20px;text-align:center; font-size:20px; line-height:26px} div.dup-notice-msg {border:1px solid silver; padding: 10px; border-radius: 5px; width: 550px; margin:40px auto 0px auto; font-size:12px; text-align: left; word-break:normal; background: #fefcea; background: -moz-linear-gradient(top, #fefcea 0%, #efe5a2 100%); background: -ms-linear-gradient(top, #fefcea 0%,#efe5a2 100%); background: linear-gradient(to bottom, #fefcea 0%,#efe5a2 100%); } input#dup-bulk-action-all {margin:0px;padding:0px 0px 0px 5px;} button.dup-button-selected {border:1px solid #000 !important; background-color:#dfdfdf !important;} div.dup-details-area-error {padding:10px; background-color:#FEF6F3; width:98%; border:1px solid silver; border-radius: 3px } /* Table package details */ table.dup-pack-table {word-break:break-all;} table.dup-pack-table th {white-space:nowrap !important;} table.dup-pack-table td.pack-name {text-overflow:ellipsis; white-space:nowrap} table.dup-pack-table input[name="delete_confirm"] {margin-left:15px} table.dup-pack-table td.fail {border-left: 4px solid #d54e21;} table.dup-pack-table td.pass {border-left: 4px solid #2ea2cc;} tr.dup-pack-info td {white-space:nowrap; padding:12px 30px 0px 7px;} tr.dup-pack-info td.get-btns {text-align:right; padding:3px 5px 6px 0px !important;}
switch ($_POST['action']) { case 'duplicator_package_active': $action_response = __('Package settings have been reset.', 'wpduplicator'); break; } } DUP_Util::InitSnapshotDirectory(); $Package = new DUP_Package(); $Package = $Package->GetActive(); $dup_tests = array(); $dup_tests = DUP_Package::GetSystemRequirments(); $default_name = DUP_Package::GetDefaultName(); $view_state = DUP_UI::GetViewStateArray(); $ui_css_archive = isset($view_state['dup-pack-archive-panel']) && $view_state['dup-pack-archive-panel'] ? 'display:block' : 'display:none'; $ui_css_installer = isset($view_state['dup-pack-installer-panel']) && $view_state['dup-pack-installer-panel'] ? 'display:block' : 'display:none'; $package_skip_scanner = DUP_Settings::Get('package_skip_scanner'); ?> <style> /* ----------------------------- REQUIRMENTS*/ div.dup-sys-section {margin:1px 0px 5px 0px} div.dup-sys-title {display:inline-block; width:250px; padding:1px; } div.dup-sys-title div {display:inline-block;float:right; } div.dup-sys-info {display:none; max-width: 800px} div.dup-sys-pass {display:inline-block; color:green;} div.dup-sys-fail {display:inline-block; color:#AF0000;} div.dup-sys-contact {padding:5px 0px 0px 10px; font-size:11px; font-style:italic} span.dup-toggle {float:left; margin:0 2px 2px 0; } /* -----------------------------
<?php require_once DUPLICATOR_PLUGIN_PATH . 'classes/package.php'; global $wp_version; $Package = new DUP_Package(); $Package->SaveActive($_POST); $Package = DUP_Package::GetActive(); $package_mysqldump = DUP_Settings::Get('package_mysqldump'); $mysqlDumpPath = DUP_Database::GetMySqlDumpPath(); $build_mode = $mysqlDumpPath && $package_mysqldump ? 'mysqldump (fast)' : 'PHP (slow)'; ?> <style> /* ============---------- PROGRESS ARES-CHECKS */ div#dup-progress-area {text-align:center; max-width:650px; min-height:200px; margin:0px auto 0px auto; padding:0px;} div#dup-msg-success {color:#18592A; padding:5px; text-align: left} div#dup-msg-success-subtitle {font-style: italic; margin:7px 0px} div#dup-msg-error {color:#A62426; padding:5px; max-width: 790px;} div#dup-msg-error-response-text { max-height:350px; overflow-y:scroll; border:1px solid silver; border-radius: 3px; padding:8px;background:#fff} div.dup-panel {margin-bottom: 25px} div.dup-scan-filter-status {display:inline; float: right; font-size:11px; margin-right:10px; color:#AF0000; font-style: italic} /* SERVER-CHECKS */ div.dup-scan-title {display:inline-block; padding:1px; font-weight: bold;} div.dup-scan-title a {display:inline-block; min-width:200px; padding:3px; } div.dup-scan-title a:focus {outline: 1px solid #fff; box-shadow: none} div.dup-scan-title div {display:inline-block; } div.dup-scan-info {display:none;} div.dup-scan-good {display:inline-block; color:green;font-weight: bold;} div.dup-scan-warn {display:inline-block; color:#AF0000;font-weight: bold;}
/** * Sets the defaults if they have not been set * @return True if option value has changed, false if not or if update failed. */ public static function SetDefaults() { $defaults = self::GetAllDefaults(); self::$Data = $defaults; return self::Save(); }
//WPFront DUP_Settings::Set('wpfront_integrate', isset($_POST['wpfront_integrate']) ? "1" : "0"); $action_updated = DUP_Settings::Save(); DUP_Util::InitSnapshotDirectory(); } $uninstall_settings = DUP_Settings::Get('uninstall_settings'); $uninstall_files = DUP_Settings::Get('uninstall_files'); $uninstall_tables = DUP_Settings::Get('uninstall_tables'); $storage_htaccess_off = DUP_Settings::Get('storage_htaccess_off'); $package_debug = DUP_Settings::Get('package_debug'); $package_zip_flush = DUP_Settings::Get('package_zip_flush'); $phpdump_chunkopts = array("20", "100", "500", "1000", "2000"); $package_phpdump_qrylimit = DUP_Settings::Get('package_phpdump_qrylimit'); $package_mysqldump = DUP_Settings::Get('package_mysqldump'); $package_mysqldump_path = trim(DUP_Settings::Get('package_mysqldump_path')); $wpfront_integrate = DUP_Settings::Get('wpfront_integrate'); $wpfront_ready = apply_filters('wpfront_user_role_editor_duplicator_integration_ready', false); $mysqlDumpPath = DUP_Database::GetMySqlDumpPath(); $mysqlDumpFound = $mysqlDumpPath ? true : false; ?> <style> form#dup-settings-form input[type=text] {width: 400px; } input#package_mysqldump_path_found {margin-top:5px} div.dup-feature-found {padding:3px; border:1px solid silver; background: #f7fcfe; border-radius: 3px; width:400px; font-size: 12px} div.dup-feature-notfound {padding:3px; border:1px solid silver; background: #fcf3ef; border-radius: 3px; width:400px; font-size: 12px} </style> <form id="dup-settings-form" action="<?php echo admin_url('admin.php?page=duplicator-settings&tab=general'); ?>
/** * Returns the mysqldump path if the server is enabled to execute it * @return boolean|string */ public static function GetMySqlDumpPath() { //Is shell_exec possible if (!DUP_Util::IsShellExecAvailable()) { return false; } $custom_mysqldump_path = DUP_Settings::Get('package_mysqldump_path'); $custom_mysqldump_path = strlen($custom_mysqldump_path) ? $custom_mysqldump_path : ''; //Common Windows Paths if (DUP_Util::IsOSWindows()) { $paths = array($custom_mysqldump_path, 'C:/xampp/mysql/bin/mysqldump.exe', 'C:/Program Files/xampp/mysql/bin/mysqldump', 'C:/Program Files/MySQL/MySQL Server 6.0/bin/mysqldump', 'C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump', 'C:/Program Files/MySQL/MySQL Server 5.4/bin/mysqldump', 'C:/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump', 'C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump'); //Common Linux Paths } else { $path1 = ''; $path2 = ''; $mysqldump = `which mysqldump`; if (@is_executable($mysqldump)) { $path1 = !empty($mysqldump) ? $mysqldump : ''; } $mysqldump = dirname(`which mysql`) . "/mysqldump"; if (@is_executable($mysqldump)) { $path2 = !empty($mysqldump) ? $mysqldump : ''; } $paths = array($custom_mysqldump_path, $path1, $path2, '/usr/local/bin/mysqldump', '/usr/local/mysql/bin/mysqldump', '/usr/mysql/bin/mysqldump', '/usr/bin/mysqldump', '/opt/local/lib/mysql6/bin/mysqldump', '/opt/local/lib/mysql5/bin/mysqldump', '/opt/local/lib/mysql4/bin/mysqldump'); } // Find the one which works foreach ($paths as $path) { if (@is_executable($path)) { return $path; } } return false; }
/** * 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::$filterDirsArray = array_map('DUP_Util::SafePath', explode(";", $archive->FilterDirs, -1)); self::$filterDirsList = $archive->FilterDirs; self::$filterExtsArray = explode(";", $archive->FilterExts, -1); self::$filterExtsList = $archive->FilterExts; self::$filterOn = $archive->FilterOn; 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::$filterDirsOn = count(self::$filterDirsArray); self::$filterExtsOn = count(self::$filterExtsArray); self::$networkFlush = empty($package_zip_flush) ? false : $package_zip_flush; DUP_Log::Info("\n********************************************************************************"); DUP_Log::Info("ARCHIVE (ZIP):"); DUP_Log::Info("********************************************************************************"); DUP_Log::Info("ARCHIVE DIR: " . self::$compressDir); DUP_Log::Info("ARCHIVE FILE: " . basename(self::$zipPath)); DUP_Log::Info("FILTER DIRS: " . self::$filterDirsList); DUP_Log::Info("FILTER EXTS: " . self::$filterExtsList); //-------------------------------- //OPEN ZIP $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 . "]"); } //-------------------------------- //ADD FILES DUP_Log::Info("----------------------------------------"); DUP_Log::Info("SCANNING"); $timerFilesStart = DUP_Util::GetMicrotime(); if (self::$filterOn && (self::$filterDirsOn || self::$filterExtsOn)) { DUP_Log::Info("FILTERS *ON*"); !in_array(self::$compressDir, self::$filterDirsArray) ? self::recurseDirsWithFilters(self::$compressDir) : DUP_Log::Info("-filter@[" . self::$compressDir . "]"); } else { DUP_Log::Info("FILTERS *OFF*"); self::recurseDirs(self::$compressDir); } $timerFilesEnd = DUP_Util::GetMicrotime(); $timerFilesSum = DUP_Util::ElapsedTime($timerFilesEnd, $timerFilesStart); DUP_Log::Info("STATS:\tDirs " . self::$countDirs . " | Files " . self::$countFiles . " | Links " . self::$countLinks); DUP_Log::Info("SIZE:\t" . DUP_Util::ByteSize(self::$size)); DUP_Log::Info("TIME:\t{$timerFilesSum}"); DUP_Log::Info("----------------------------------------"); DUP_Log::Info("COMPRESSING"); //-------------------------------- //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 file to archive.", "SQL File Path [" . self::$sqlath . "]"); } self::$zipArchive->close(); self::$zipArchive->open(self::$zipPath, ZipArchive::CREATE); 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}"); } catch (Exception $e) { DUP_Log::Error("Runtime error in package.archive.zip.php constructor.", "Exception: {$e}"); } }
<?php require_once DUPLICATOR_PLUGIN_PATH . 'classes/package.php'; global $wpdb; //POST BACK $action_updated = null; if (isset($_POST['action'])) { $action_result = DUP_Settings::DeleteWPOption($_POST['action']); switch ($_POST['action']) { case 'duplicator_package_active': $action_response = __('Package settings have been reset.', 'wpduplicator'); break; } } DUP_Util::InitSnapshotDirectory(); $Package = DUP_Package::GetActive(); $package_hash = $Package->MakeHash(); $dup_tests = array(); $dup_tests = DUP_Server::GetRequirments(); $default_name = DUP_Package::GetDefaultName(); $view_state = DUP_UI::GetViewStateArray(); $ui_css_archive = isset($view_state['dup-pack-archive-panel']) && $view_state['dup-pack-archive-panel'] ? 'display:block' : 'display:none'; $ui_css_installer = isset($view_state['dup-pack-installer-panel']) && $view_state['dup-pack-installer-panel'] ? 'display:block' : 'display:none'; ?> <style> /* ----------------------------- REQUIRMENTS*/ div.dup-sys-section {margin:1px 0px 5px 0px} div.dup-sys-title {display:inline-block; width:250px; padding:1px; } div.dup-sys-title div {display:inline-block;float:right; }
/** * 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}"); } }
$action_response = __('Package settings have been reset.', 'duplicator'); break; } } DUP_Util::InitSnapshotDirectory(); $Package = DUP_Package::GetActive(); $package_hash = $Package->MakeHash(); $dup_tests = array(); $dup_tests = DUP_Server::GetRequirements(); $default_name = DUP_Package::GetDefaultName(); $view_state = DUP_UI::GetViewStateArray(); $ui_css_storage = isset($view_state['dup-pack-storage-panel']) && $view_state['dup-pack-storage-panel'] ? 'display:block' : 'display:none'; $ui_css_archive = isset($view_state['dup-pack-archive-panel']) && $view_state['dup-pack-archive-panel'] ? 'display:block' : 'display:none'; $ui_css_installer = isset($view_state['dup-pack-installer-panel']) && $view_state['dup-pack-installer-panel'] ? 'display:block' : 'display:none'; $dup_intaller_files = implode(", ", array_keys(DUP_Server::GetInstallerFiles())); $dbbuild_mode = DUP_Settings::Get('package_mysqldump') && DUP_Database::GetMySqlDumpPath() ? 'mysqldump' : 'PHP'; ?> <style> /* ----------------------------- REQUIREMENTS*/ div.dup-sys-section {margin:1px 0px 5px 0px} div.dup-sys-title {display:inline-block; width:250px; padding:1px; } div.dup-sys-title div {display:inline-block;float:right; } div.dup-sys-info {display:none; max-width: 98%; margin:4px 4px 12px 4px} div.dup-sys-pass {display:inline-block; color:green;} div.dup-sys-fail {display:inline-block; color:#AF0000;} div.dup-sys-contact {padding:5px 0px 0px 10px; font-size:11px; font-style:italic} span.dup-toggle {float:left; margin:0 2px 2px 0; } table.dup-sys-info-results td:first-child {width:200px} </style>
//POST BACK $action_updated = null; if (isset($_POST['action'])) { $action_result = DUP_Settings::DeleteWPOption($_POST['action']); switch ($_POST['action']) { case 'duplicator_settings': $action_response = __('Plugin settings reset.', 'wpduplicator'); break; case 'duplicator_ui_view_state': $action_response = __('View state settings reset.', 'wpduplicator'); break; case 'duplicator_package_active': $action_response = __('Active package settings reset.', 'wpduplicator'); break; case 'clear_legacy_data': DUP_Settings::LegacyClean(); $action_response = __('Legacy data removed.', 'wpduplicator'); break; } } ?> <style> div#message {margin:0px 0px 10px 0px} div#dup-server-info-area { padding:10px 5px; } div#dup-server-info-area table { padding:1px; background:#dfdfdf; -webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px; width:100% !important; box-shadow:0 8px 6px -6px #777; } div#dup-server-info-area td, th {padding:3px; background:#fff; -webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px;} div#dup-server-info-area tr.h img { display:none; } div#dup-server-info-area tr.h td{ background:none; } div#dup-server-info-area tr.h th{ text-align:center; background-color:#efefef; } div#dup-server-info-area td.e{ font-weight:bold }
DUP_Settings::Set('uninstall_tables', isset($_POST['uninstall_tables']) ? "1" : "0"); DUP_Settings::Set('package_skip_scanner', isset($_POST['package_skip_scanner']) ? "1" : "0"); DUP_Settings::Set('package_debug', isset($_POST['package_debug']) ? "1" : "0"); DUP_Settings::Set('package_zip_flush', isset($_POST['package_zip_flush']) ? "1" : "0"); DUP_Settings::Set('package_mysqldump', isset($_POST['package_mysqldump']) ? "1" : "0"); DUP_Settings::Set('package_mysqldump_path', trim($_POST['package_mysqldump_path'])); $action_updated = DUP_Settings::Save(); } $uninstall_settings = DUP_Settings::Get('uninstall_settings'); $uninstall_files = DUP_Settings::Get('uninstall_files'); $uninstall_tables = DUP_Settings::Get('uninstall_tables'); $package_skip_scanner = DUP_Settings::Get('package_skip_scanner'); $package_debug = DUP_Settings::Get('package_debug'); $package_zip_flush = DUP_Settings::Get('package_zip_flush'); $package_mysqldump = DUP_Settings::Get('package_mysqldump'); $package_mysqldump_path = trim(DUP_Settings::Get('package_mysqldump_path')); $mysqlDumpPath = DUP_Database::GetMySqlDumpPath(); $mysqlDumpFound = $mysqlDumpPath ? true : false; ?> <style> form#dup-settings-form input[type=text] {width: 400px; } input#package_mysqldump_path_found {margin-top:5px} div.dup-mysql-dump-found {padding:3px; border:1px solid silver; background: #f7fcfe; border-radius: 3px; width:400px; font-size: 12px} div.dup-mysql-dump-notfound {padding:3px; border:1px solid silver; background: #fcf3ef; border-radius: 3px; width:400px; font-size: 12px} </style> <form id="dup-settings-form" action="<?php echo admin_url('admin.php?page=duplicator-settings&tab=general'); ?> " method="post">