/**
  * Generates a scan report
  * @return array of scan results
  */
 public function Scan()
 {
     $timerStart = DUP_Util::GetMicrotime();
     $report = array();
     $this->ScanFile = "{$this->NameHash}_scan.json";
     $report['RPT']['ScanTime'] = "0";
     $report['RPT']['ScanFile'] = $this->ScanFile;
     //SERVER
     $srv = DUP_Server::GetChecks();
     $report['SRV']['PHPServer'] = $srv['CHK-SRV-100'];
     $report['SRV']['WPSettings'] = $srv['CHK-SRV-101'];
     $report['SRV']['WebServer'] = $srv['CHK-SRV-102'];
     //FILES
     $this->Archive->Stats();
     $report['ARC']['Size'] = DUP_Util::ByteSize($this->Archive->Size) or "unknown";
     $report['ARC']['DirCount'] = number_format(count($this->Archive->Dirs));
     $report['ARC']['FileCount'] = number_format(count($this->Archive->Files));
     $report['ARC']['LinkCount'] = number_format(count($this->Archive->Links));
     $report['ARC']['WarnFileName'] = is_array($this->Archive->WarnFileName) ? $this->Archive->WarnFileName : "unknown";
     $report['ARC']['WarnFileSize'] = is_array($this->Archive->WarnFileSize) ? $this->Archive->WarnFileSize : "unknown";
     $report['ARC']['Status']['Size'] = $this->Archive->Size > DUPLICATOR_SCAN_SITE ? 'Warn' : 'Good';
     $report['ARC']['Status']['Names'] = count($this->Archive->WarnFileName) ? 'Warn' : 'Good';
     $report['ARC']['Status']['Big'] = count($this->Archive->WarnFileSize) ? 'Warn' : 'Good';
     $report['ARC']['Dirs'] = $this->Archive->Dirs;
     $report['ARC']['Files'] = $this->Archive->Files;
     $report['ARC']['OmitFiles'] = $this->Archive->OmitFiles;
     $report['ARC']['OmitDirs'] = $this->Archive->OmitDirs;
     //DATABASE
     $db = $this->Database->Stats();
     $report['DB']['Status'] = $db['Status'];
     $report['DB']['Size'] = DUP_Util::ByteSize($db['Size']) or "unknown";
     $report['DB']['Rows'] = number_format($db['Rows']) or "unknown";
     $report['DB']['TableCount'] = $db['TableCount'] or "unknown";
     $report['DB']['TableList'] = $db['TableList'] or "unknown";
     $report['RPT']['ScanTime'] = DUP_Util::ElapsedTime(DUP_Util::GetMicrotime(), $timerStart);
     $fp = fopen(DUPLICATOR_SSDIR_PATH_TMP . "/{$this->ScanFile}", 'w');
     fwrite($fp, json_encode($report));
     fclose($fp);
     return $report;
 }
Ejemplo n.º 2
0
 /**
  * Starts the package build process
  * @return DUP_Package
  */
 public function Build()
 {
     global $wp_version;
     global $wpdb;
     global $current_user;
     $timerStart = DUP_Util::GetMicrotime();
     $this->Archive->File = "{$this->NameHash}_archive.zip";
     $this->Installer->File = "{$this->NameHash}_installer.php";
     $this->Database->File = "{$this->NameHash}_database.sql";
     //START LOGGING
     DUP_Log::Open($this->NameHash);
     $php_max_time = @ini_get("max_execution_time");
     $php_max_memory = @ini_set('memory_limit', DUPLICATOR_PHP_MAX_MEMORY);
     $php_max_time = $php_max_time == 0 ? "(0) no time limit imposed" : "[{$php_max_time}] not allowed";
     $php_max_memory = $php_max_memory === false ? "Unabled to set php memory_limit" : DUPLICATOR_PHP_MAX_MEMORY . " ({$php_max_memory} default)";
     $info = "********************************************************************************\n";
     $info .= "PACKAGE-LOG: " . @date("Y-m-d H:i:s") . "\n";
     $info .= "NOTICE: Do NOT post to public sites or forums \n";
     $info .= "********************************************************************************\n";
     $info .= "VERSION:\t" . DUPLICATOR_VERSION . "\n";
     $info .= "WORDPRESS:\t{$wp_version}\n";
     $info .= "PHP INFO:\t" . phpversion() . ' | ' . 'SAPI: ' . php_sapi_name() . "\n";
     $info .= "SERVER:\t\t{$_SERVER['SERVER_SOFTWARE']} \n";
     $info .= "PHP TIME LIMIT: {$php_max_time} \n";
     $info .= "PHP MAX MEMORY: {$php_max_memory} \n";
     $info .= "MEMORY STACK: " . DUP_Server::GetPHPMemory();
     DUP_Log::Info($info);
     $info = null;
     //CREATE DB RECORD
     $packageObj = serialize($this);
     if (!$packageObj) {
         DUP_Log::Error("Unable to serialize pacakge object while building record.");
     }
     $this->ID = $this->FindHashKey($this->Hash);
     if ($this->ID != 0) {
         $this->SetStatus(DUP_PackageStatus::START);
     } else {
         $results = $wpdb->insert($wpdb->prefix . "duplicator_packages", array('name' => $this->Name, 'hash' => $this->Hash, 'status' => DUP_PackageStatus::START, 'created' => current_time('mysql', get_option('gmt_offset', 1)), 'owner' => isset($current_user->user_login) ? $current_user->user_login : '******', 'package' => $packageObj));
         if ($results == false) {
             $error_result = $wpdb->print_error();
             DUP_Log::Error("Duplicator is unable to insert a package record into the database table.", "'{$error_result}'");
         }
         $this->ID = $wpdb->insert_id;
     }
     //START BUILD
     //PHPs serialze method will return the object, but the ID above is not passed
     //for one reason or another so passing the object back in seems to do the trick
     $this->Database->Build($this);
     $this->Archive->Build($this);
     $this->Installer->Build($this);
     //INTEGRITY CHECKS
     DUP_Log::Info("\n********************************************************************************");
     DUP_Log::Info("INTEGRITY CHECKS:");
     DUP_Log::Info("********************************************************************************");
     $dbSizeRead = DUP_Util::ByteSize($this->Database->Size);
     $zipSizeRead = DUP_Util::ByteSize($this->Archive->Size);
     $exeSizeRead = DUP_Util::ByteSize($this->Installer->Size);
     DUP_Log::Info("SQL File: {$dbSizeRead}");
     DUP_Log::Info("Installer File: {$exeSizeRead}");
     DUP_Log::Info("Archive File: {$zipSizeRead} ");
     if (!($this->Archive->Size && $this->Database->Size && $this->Installer->Size)) {
         DUP_Log::Error("A required file contains zero bytes.", "Archive Size: {$zipSizeRead} | SQL Size: {$dbSizeRead} | Installer Size: {$exeSizeRead}");
     }
     //Validate SQL files completed
     $sql_tmp_path = DUP_UTIL::SafePath(DUPLICATOR_SSDIR_PATH_TMP . '/' . $this->Database->File);
     $sql_complete_txt = DUP_Util::TailFile($sql_tmp_path, 3);
     if (!strstr($sql_complete_txt, 'DUPLICATOR_MYSQLDUMP_EOF')) {
         DUP_Log::Error("ERROR: SQL file not complete.  The end of file marker was not found.  Please try to re-create the package.");
     }
     $timerEnd = DUP_Util::GetMicrotime();
     $timerSum = DUP_Util::ElapsedTime($timerEnd, $timerStart);
     $this->Runtime = $timerSum;
     $this->ExeSize = $exeSizeRead;
     $this->ZipSize = $zipSizeRead;
     $this->buildCleanup();
     //FINAL REPORT
     $info = "\n********************************************************************************\n";
     $info .= "RECORD ID:[{$this->ID}]\n";
     $info .= "TOTAL PROCESS RUNTIME: {$timerSum}\n";
     $info .= "PEAK PHP MEMORY USED: " . DUP_Server::GetPHPMemory(true) . "\n";
     $info .= "DONE PROCESSING => {$this->Name} " . @date("Y-m-d H:i:s") . "\n";
     DUP_Log::Info($info);
     DUP_Log::Close();
     $this->SetStatus(DUP_PackageStatus::COMPLETE);
     return $this;
 }
Ejemplo n.º 3
0
require_once DUPLICATOR_PLUGIN_PATH . '/assets/js/javascript.php';
require_once DUPLICATOR_PLUGIN_PATH . '/views/inc.header.php';
$nonce = wp_create_nonce('duplicator_cleanup_page');
$_GET['action'] = isset($_GET['action']) ? $_GET['action'] : 'display';
if (isset($_GET['action'])) {
    if ($_GET['action'] == 'installer' || $_GET['action'] == 'legacy' || $_GET['action'] == 'tmp-cache') {
        $verify_nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($verify_nonce, 'duplicator_cleanup_page')) {
            exit;
            // Get out of here bad nounce!
        }
    }
}
$txt_found = DUP_Util::__("File Found");
$txt_not_found = DUP_Util::__("File Removed");
$installer_files = DUP_Server::GetInstallerFiles();
switch ($_GET['action']) {
    case 'installer':
        $action_response = __('Installer file cleanup ran!');
        $css_hide_msg = 'div.error {display:none}';
        break;
    case 'legacy':
        DUP_Settings::LegacyClean();
        $action_response = __('Legacy data removed.');
        break;
    case 'tmp-cache':
        DUP_Package::TmpCleanup(true);
        $action_response = __('Build cache removed.');
        break;
}
?>
Ejemplo n.º 4
0
 /**
  *  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}");
     }
 }
Ejemplo n.º 5
0
$serverinfo = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $serverinfo);
$serverinfo = preg_replace('%^.*<title>(.*)</title>.*$%ms', '$1', $serverinfo);
$action_response = null;
$dbvar_maxtime = DUP_Util::MysqlVariableValue('wait_timeout');
$dbvar_maxpacks = DUP_Util::MysqlVariableValue('max_allowed_packet');
$dbvar_maxtime = is_null($dbvar_maxtime) ? __("unknow", 'duplicator') : $dbvar_maxtime;
$dbvar_maxpacks = is_null($dbvar_maxpacks) ? __("unknow", 'duplicator') : $dbvar_maxpacks;
$space = @disk_total_space(DUPLICATOR_WPROOTPATH);
$space_free = @disk_free_space(DUPLICATOR_WPROOTPATH);
$perc = @round(100 / $space * $space_free, 2);
$mysqldumpPath = DUP_Database::GetMySqlDumpPath();
$mysqlDumpSupport = $mysqldumpPath ? $mysqldumpPath : 'Path Not Found';
$view_state = DUP_UI::GetViewStateArray();
$ui_css_srv_panel = isset($view_state['dup-settings-diag-srv-panel']) && $view_state['dup-settings-diag-srv-panel'] ? 'display:block' : 'display:none';
$ui_css_opts_panel = isset($view_state['dup-settings-diag-opts-panel']) && $view_state['dup-settings-diag-opts-panel'] ? 'display:block' : 'display:none';
$client_ip_address = DUP_Server::GetClientIP();
//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.', 'duplicator');
            break;
        case 'duplicator_ui_view_state':
            $action_response = __('View state settings reset.', 'duplicator');
            break;
        case 'duplicator_package_active':
            $action_response = __('Active package settings reset.', 'duplicator');
            break;
        case 'clear_legacy_data':
Ejemplo n.º 6
0
 /**
  * Shows a display message in the wp-admin if any researved files are found
  * @return type void
  */
 public static function ShowReservedFilesNotice()
 {
     if (!is_plugin_active('duplicator/duplicator.php')) {
         return;
     }
     $hide = isset($_REQUEST['page']) && $_REQUEST['page'] == 'duplicator-tools' ? true : false;
     $perms = current_user_can('install_plugins') && current_user_can('import');
     if (!$perms || $hide) {
         return;
     }
     $metaKey = 'dup-wpnotice01';
     if (isset($_GET[$metaKey]) && $_GET[$metaKey] == '1') {
         self::SaveViewState($metaKey, true);
     }
     if (!self::GetViewStateValue($metaKey, false)) {
         if (DUP_Server::InstallerFilesFound()) {
             $queryStr = $_SERVER['QUERY_STRING'];
             echo '<div class="updated"><p>';
             @printf("%s <br/> <a href='admin.php?page=duplicator-tools&tab=cleanup&action=installer'>%s</a> | <a href='?{$queryStr}&{$metaKey}=1'>%s</a>", __('Reserved Duplicator install file(s) still exists in the root directory.  Please delete these file(s) to avoid possible security issues.'), __('Remove file(s) now'), __('Dismiss this notice'));
             echo "</p></div>";
         } else {
             self::SaveViewState($metaKey, true);
         }
     }
 }
Ejemplo n.º 7
0
        case 'duplicator_package_active':
            $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}
Ejemplo n.º 8
0
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; }
	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;}
Ejemplo n.º 9
0
 /**
  * Shows a display message in the wp-admin if any researved files are found
  * @return type void
  */
 public static function ShowReservedFilesNotice()
 {
     //Show only on Duplicator pages and Dashboard when plugin is active
     $dup_active = is_plugin_active('duplicator/duplicator.php');
     $dup_perm = current_user_can('manage_options');
     if (!$dup_active || !$dup_perm) {
         return;
     }
     if (DUP_Server::InstallerFilesFound()) {
         $screen = get_current_screen();
         $on_active_tab = isset($_GET['tab']) && $_GET['tab'] == 'cleanup' ? true : false;
         echo '<div class="error" id="dup-global-error-reserved-files"><p>';
         if ($screen->id == 'duplicator_page_duplicator-tools' && $on_active_tab) {
             DUP_Util::_e('Reserved Duplicator install files have been detected in the root directory.  Please delete these reserved files to avoid security issues.');
         } else {
             $duplicator_nonce = wp_create_nonce('duplicator_cleanup_page');
             DUP_Util::_e('Reserved Duplicator install files have been detected in the root directory.  Please delete these reserved files to avoid security issues.');
             @printf("<br/><a href='admin.php?page=duplicator-tools&tab=cleanup&_wpnonce=%s'>%s</a>", $duplicator_nonce, DUP_Util::__('Take me to the cleanup page!'));
         }
         echo "</p></div>";
     }
 }