Example #1
0
/**
 *  DUPLICATOR_CREATE
 *  Creates the zip file, database entry, and installer file for the
 *  new culmination of a 'Package Set'
 *
 *  @return string   A message about the action
 *		- log:act__create=>done
 */
function duplicator_create()
{
    global $wp_version;
    global $wpdb;
    global $current_user;
    $packname = isset($_POST['package_name']) ? trim($_POST['package_name']) : null;
    $secure_token = uniqid() . mt_rand(1000, 9999);
    $uniquename = "{$secure_token}_{$packname}";
    foreach (glob(DUPLICATOR_SSDIR_PATH . '/*.log') as $log_file) {
        @unlink($log_file);
    }
    $logfilename = "{$uniquename}.log";
    $GLOBALS['duplicator_package_log_handle'] = @fopen(DUPLICATOR_SSDIR_PATH . "/{$logfilename}", "c+");
    duplicator_log("*********************************************************");
    duplicator_log("PACKAGE-LOG: ");
    duplicator_log("*********************************************************");
    duplicator_log("duplicator: " . DUPLICATOR_VERSION);
    duplicator_log("wordpress: {$wp_version}");
    duplicator_log("php: " . phpversion());
    duplicator_log("php sapi: " . php_sapi_name());
    duplicator_log("server: {$_SERVER['SERVER_SOFTWARE']}");
    duplicator_log("browser: {$_SERVER['HTTP_USER_AGENT']}");
    duplicator_log("package name: {$packname}");
    if ($packname) {
        $max_time = @ini_set("max_execution_time", $GLOBALS['duplicator_opts']['max_time']);
        $max_memory = @ini_set('memory_limit', $GLOBALS['duplicator_opts']['max_memory']);
        $max_time = $max_time === false ? "Unabled to set max_execution_time" : "from={$max_time} to={$GLOBALS['duplicator_opts']['max_time']}";
        $max_memory = $max_memory === false ? "Unabled to set memory_limit" : "from={$max_memory} to={$GLOBALS['duplicator_opts']['max_memory']}";
        @set_time_limit(0);
        duplicator_log("max_time: {$max_time}");
        duplicator_log("max_memory: {$max_memory}");
        $zipfilename = "{$uniquename}_package.zip";
        $sqlfilename = "{$uniquename}_database.sql";
        $exefilename = "{$uniquename}_installer.php";
        $zipfilepath = DUPLICATOR_SSDIR_PATH . "/{$zipfilename}";
        $sqlfilepath = DUPLICATOR_SSDIR_PATH . "/{$sqlfilename}";
        $exefilepath = DUPLICATOR_SSDIR_PATH . "/{$exefilename}";
        $zipsize = 0;
        duplicator_log("mysql wait_timeout: {$GLOBALS['duplicator_opts']['max_time']}");
        $wpdb->query("SET session wait_timeout = {$GLOBALS['duplicator_opts']['max_time']}");
        duplicator_log("*********************************************************");
        duplicator_log("SQL SCRIPT");
        duplicator_log("*********************************************************");
        duplicator_create_dbscript($sqlfilepath);
        //CREATE ZIP ARCHIVE
        duplicator_log("*********************************************************");
        duplicator_log("ZIP ARCHIVE");
        duplicator_log("*********************************************************");
        $zip = new Duplicator_Zip($zipfilepath, rtrim(DUPLICATOR_WPROOTPATH, '/'), $sqlfilepath);
        $zipsize = filesize($zipfilepath);
        $zipsize == false ? duplicator_log("log:act__create=>warning: zipsize is unknown.") : duplicator_log("log:act__create=>zip file size is: " . duplicator_bytesize($zipsize));
        duplicator_log("log:act__create=>zip archive complete.", 2);
        //Serlized settings
        $settings = array('plugin_version' => DUPLICATOR_VERSION, 'type' => 'Manual');
        $serialized_settings = serialize($settings);
        //Record archive info to database
        $results = $wpdb->insert($wpdb->prefix . "duplicator", array('token' => $secure_token, 'packname' => $packname, 'zipname' => $zipfilename, 'zipsize' => $zipsize, 'created' => current_time('mysql', get_option('gmt_offset')), 'owner' => $current_user->user_login, 'settings' => "{$serialized_settings}"));
        if ($wpdb->insert_id) {
            duplicator_log("log:act__create=>recorded archieve id: " . $wpdb->insert_id);
        } else {
            duplicator_log("log:act__create=>unable to record to database.");
        }
        $wpdb->flush();
        //UPDATE INSTALL FILE
        duplicator_log("*********************************************************");
        duplicator_log("UPDATE INSTALLER FILE");
        duplicator_log("*********************************************************");
        duplicator_build_installerFile();
        duplicator_create_installerFile($uniquename);
        //SEND EMAIL
        //TODO: Send only SQL File via mail.  Zip files can get too large
        if ($GLOBALS['duplicator_opts']['email-me'] == "1") {
            duplicator_log("log:act__create=>email started");
            $status = $zipsize ? 'Success' : 'Failure';
            $attachments = "";
            //array(DUPLICATOR_SSDIR_PATH . '/' . $packname .'.zip');
            $headers = 'From: Duplicator Plugin <no-reply@lifeinthegrid.com>' . "\r\n";
            $subject = "Package '{$packname}' completed";
            $message = "Run Status: {$status}\n\rSite Name: " . get_bloginfo('name') . "\n\rPackage Name: {$packname} \n\rCompleted at: " . current_time('mysql', get_option('gmt_offset'));
            wp_mail($current_user->user_email, $subject, $message, $headers, $attachments);
            duplicator_log("log:act__create=>sent email to: {$current_user->user_email}");
            $other_emails = @preg_split("/[,;]/", $GLOBALS['duplicator_opts']['email_others']);
            if (count($other_emails)) {
                wp_mail($other_emails, $subject, $message, $headers, $attachments);
                duplicator_log("log:act__create=>other emails sent: {$GLOBALS['duplicator_opts']['email_others']}");
            }
            duplicator_log("log:act__create=>email finished");
        }
    }
    duplicator_log("*********************************************************");
    duplicator_log("DONE PROCESSING => {$packname}");
    duplicator_log("*********************************************************");
    @fclose($GLOBALS['duplicator_package_log_handle']);
    die;
}
Example #2
0
/**
 *  DUPLICATOR_CREATE
 *  Creates the zip file, database entry, and installer file for the
 *  new culmination of a 'Package Set'  
 *
 *  @return string   A message about the action
 * 		- log:act__create=>done
 */
function duplicator_create()
{
    global $wp_version;
    global $wpdb;
    global $current_user;
    $error_level = error_reporting();
    error_reporting(E_ERROR);
    $fulltime_start = DuplicatorUtils::GetMicrotime();
    $packname = isset($_POST['package_name']) ? trim($_POST['package_name']) : null;
    $secure_token = uniqid() . mt_rand(1000, 9999);
    $uniquename = "{$secure_token}_{$packname}";
    foreach (glob(DUPLICATOR_SSDIR_PATH . '/*.log') as $log_file) {
        @unlink($log_file);
    }
    $logfilename = "{$uniquename}.log";
    $GLOBALS['duplicator_package_log_handle'] = @fopen(DUPLICATOR_SSDIR_PATH . "/{$logfilename}", "c+");
    duplicator_log("********************************************************************************");
    duplicator_log("PACKAGE-LOG: " . @date('h:i:s'));
    duplicator_log("NOTICE: Do not post to public sites or forums");
    duplicator_log("********************************************************************************");
    duplicator_log("duplicator: " . DUPLICATOR_VERSION);
    duplicator_log("wordpress: {$wp_version}");
    duplicator_log("php: " . phpversion());
    duplicator_log("php sapi: " . php_sapi_name());
    duplicator_log("server: {$_SERVER['SERVER_SOFTWARE']}");
    duplicator_log("browser: {$_SERVER['HTTP_USER_AGENT']}");
    duplicator_log("package name: {$packname}");
    if ($packname) {
        $php_max_time = @ini_set("max_execution_time", DUPLICATOR_PHP_MAX_TIME);
        $php_max_memory = @ini_set('memory_limit', DUPLICATOR_PHP_MAX_MEMORY);
        $php_max_time = $php_max_time === false ? "Unabled to set php max_execution_time" : "from={$php_max_time} to=" . DUPLICATOR_PHP_MAX_TIME;
        $php_max_memory = $php_max_memory === false ? "Unabled to set php memory_limit" : "from={$php_max_memory} to=" . DUPLICATOR_PHP_MAX_MEMORY;
        @set_time_limit(0);
        duplicator_log("php_max_time: {$php_max_time}");
        duplicator_log("php_max_memory: {$php_max_memory}");
        duplicator_log("mysql wait_timeout:" . DUPLICATOR_PHP_MAX_TIME);
        $zipfilename = "{$uniquename}_package.zip";
        $sqlfilename = "{$uniquename}_database.sql";
        $exefilename = "{$uniquename}_installer.php";
        $zipfilepath = DUPLICATOR_SSDIR_PATH . "/{$zipfilename}";
        $sqlfilepath = DUPLICATOR_SSDIR_PATH . "/{$sqlfilename}";
        $exefilepath = DUPLICATOR_SSDIR_PATH . "/{$exefilename}";
        $zipsize = 0;
        $wpdb->query("SET session wait_timeout = " . DUPLICATOR_DB_MAX_TIME);
        duplicator_log("********************************************************************************");
        duplicator_log("SQL SCRIPT");
        duplicator_log("********************************************************************************");
        duplicator_create_dbscript($sqlfilepath);
        //CREATE ZIP ARCHIVE
        duplicator_log("********************************************************************************");
        duplicator_log("ZIP ARCHIVE:");
        duplicator_log("********************************************************************************");
        $zip = new Duplicator_Zip($zipfilepath, rtrim(DUPLICATOR_WPROOTPATH, '/'), $sqlfilepath);
        $zipsize = filesize($zipfilepath);
        $zipsize == false ? duplicator_log("WARNING: ZIPSIZE IS UNKNOWN.") : duplicator_log("ZIP FILE SIZE: " . duplicator_bytesize($zipsize));
        //Serlized settings
        $settings = array('plugin_version' => DUPLICATOR_VERSION, 'type' => 'Manual');
        $serialized_settings = serialize($settings);
        //Record archive info to database
        $results = $wpdb->insert($wpdb->prefix . "duplicator", array('token' => $secure_token, 'packname' => $packname, 'zipname' => $zipfilename, 'zipsize' => $zipsize, 'created' => current_time('mysql', get_option('gmt_offset')), 'owner' => $current_user->user_login, 'settings' => "{$serialized_settings}"));
        if ($wpdb->insert_id) {
            duplicator_log("RECORDED ARCHIVE ID: " . $wpdb->insert_id);
        } else {
            duplicator_log("WARNING: UNABLE TO RECORD TO DATABASE");
        }
        $wpdb->flush();
        //UPDATE INSTALL FILE
        duplicator_log("********************************************************************************");
        duplicator_log("FINALIZATION ROUTINES:");
        duplicator_log("********************************************************************************");
        duplicator_build_installerFile();
        duplicator_create_installerFile($uniquename);
        //SEND EMAIL
        //TODO: Send only SQL File via mail.  Zip files can get too large
        if ($GLOBALS['duplicator_opts']['email-me'] == "1") {
            duplicator_log("log:act__create=>email started");
            $status = $zipsize ? 'Success' : 'Failure';
            $attachments = "";
            //array(DUPLICATOR_SSDIR_PATH . '/' . $packname .'.zip');
            $headers = 'From: Duplicator Plugin <no-reply@lifeinthegrid.com>' . "\r\n";
            $subject = "Package '{$packname}' completed";
            $message = "Run Status: {$status}\n\rSite Name: " . get_bloginfo('name') . "\n\rPackage Name: {$packname} \n\rCompleted at: " . current_time('mysql', get_option('gmt_offset'));
            wp_mail($current_user->user_email, $subject, $message, $headers, $attachments);
            duplicator_log("log:act__create=>sent email to: {$current_user->user_email}");
            $other_emails = @preg_split("/[,;]/", $GLOBALS['duplicator_opts']['email_others']);
            if (count($other_emails)) {
                wp_mail($other_emails, $subject, $message, $headers, $attachments);
                duplicator_log("log:act__create=>other emails sent: {$GLOBALS['duplicator_opts']['email_others']}");
            }
            duplicator_log("log:act__create=>email finished");
        }
    }
    $fulltime_end = DuplicatorUtils::GetMicrotime();
    $fulltime_sum = DuplicatorUtils::ElapsedTime($fulltime_end, $fulltime_start);
    duplicator_log("COMPLETE PACKAGE RUNTIME: {$fulltime_sum}");
    duplicator_log("********************************************************************************");
    duplicator_log("DONE PROCESSING => {$packname} " . @date('h:i:s'));
    duplicator_log("********************************************************************************");
    @fclose($GLOBALS['duplicator_package_log_handle']);
    error_reporting($error_level);
    die;
}
/**
 *  DUPLICATOR_CREATE
 *  Creates the zip file, database entry, and installer file for the
 *  new culmination of a 'Package Set'  
 *
 *  @return string   A message/waring/error about the action
 */
function duplicator_create()
{
    global $wp_version;
    global $wpdb;
    global $current_user;
    //post data un-stripped, as WP magic quotes _POST for some reason...
    $post = stripslashes_deep($_POST);
    $error_level = error_reporting();
    error_reporting(E_ERROR);
    $fulltime_start = DuplicatorUtils::GetMicrotime();
    $packname = isset($post['package_name']) ? trim($post['package_name']) : 'package';
    $packnotes = isset($post['package_notes']) ? trim(esc_html($post['package_notes'])) : '';
    $secure_token = uniqid() . mt_rand(1000, 9999);
    $uniquename = "{$secure_token}_{$packname}";
    $logfilename = "{$uniquename}.log";
    $table_id = null;
    $GLOBALS['duplicator_package_log_handle'] = @fopen(DUPLICATOR_SSDIR_PATH . "/{$logfilename}", "c+");
    duplicator_log("********************************************************************************");
    duplicator_log("PACKAGE-LOG: " . @date('h:i:s'));
    duplicator_log("NOTICE: Do not post to public sites or forums");
    duplicator_log("********************************************************************************");
    duplicator_log("duplicator: " . DUPLICATOR_VERSION);
    duplicator_log("wordpress: {$wp_version}");
    duplicator_log("php: " . phpversion());
    duplicator_log("php sapi: " . php_sapi_name());
    duplicator_log("server: {$_SERVER['SERVER_SOFTWARE']}");
    duplicator_log("browser: {$_SERVER['HTTP_USER_AGENT']}");
    duplicator_log("package name: {$packname}");
    $php_max_time = @ini_set("max_execution_time", DUPLICATOR_PHP_MAX_TIME);
    $php_max_memory = @ini_set('memory_limit', DUPLICATOR_PHP_MAX_MEMORY);
    $php_max_time = $php_max_time === false ? "Unabled to set php max_execution_time" : "set from={$php_max_time} to=" . DUPLICATOR_PHP_MAX_TIME;
    $php_max_memory = $php_max_memory === false ? "Unabled to set php memory_limit" : "set from={$php_max_memory} to=" . DUPLICATOR_PHP_MAX_MEMORY;
    duplicator_log("php_max_time: {$php_max_time}");
    duplicator_log("php_max_memory: {$php_max_memory}");
    duplicator_log("mysql wait_timeout:" . DUPLICATOR_PHP_MAX_TIME);
    $zipfilename = "{$uniquename}_package.zip";
    $sqlfilename = "{$uniquename}_database.sql";
    $exefilename = "{$uniquename}_installer.php";
    $zipfilepath = DUPLICATOR_SSDIR_PATH . "/{$zipfilename}";
    $sqlfilepath = DUPLICATOR_SSDIR_PATH . "/{$sqlfilename}";
    $exefilepath = DUPLICATOR_SSDIR_PATH . "/{$exefilename}";
    @set_time_limit(0);
    $wpdb->query("SET session wait_timeout = " . DUPLICATOR_DB_MAX_TIME);
    //=====================================================
    //START: RECORD TRANSACTION
    $pack_settings = serialize(array('plugin_version' => DUPLICATOR_VERSION, 'type' => 'Manual', 'status' => 'Error', 'notes' => "{$packnotes}"));
    $results = $wpdb->insert($wpdb->prefix . "duplicator", array('token' => $secure_token, 'packname' => $packname, 'zipname' => $zipfilename, 'zipsize' => 0, 'created' => current_time('mysql', get_option('gmt_offset')), 'owner' => $current_user->user_login, 'settings' => "{$pack_settings}"));
    if ($wpdb->insert_id) {
        duplicator_log("recorded table id: " . $wpdb->insert_id);
        $table_id = $wpdb->insert_id;
    } else {
        $error_result = $wpdb->print_error();
        duplicator_error("ERROR: Unable to insert into database table. \nERROR INFO: '{$error_result}'");
    }
    duplicator_log("********************************************************************************");
    duplicator_log("BUILD SQL SCRIPT:");
    duplicator_log("********************************************************************************");
    duplicator_create_dbscript($sqlfilepath);
    duplicator_log("********************************************************************************");
    duplicator_log("BUILD ZIP PACKAGE:");
    duplicator_log("********************************************************************************");
    $zip = new Duplicator_Zip($zipfilepath, rtrim(DUPLICATOR_WPROOTPATH, '/'), $sqlfilepath);
    duplicator_log("********************************************************************************");
    duplicator_log("BUILD INSTALLER FILE:");
    duplicator_log("********************************************************************************");
    duplicator_build_installerFile();
    duplicator_create_installerFile($uniquename, $table_id);
    //VALIDATE FILE SIZE
    $zip_filesize = @filesize($zipfilepath);
    $sql_filesize = @filesize($sqlfilepath);
    $exe_filesize = @filesize($exefilepath);
    $zip_basicsize = duplicator_bytesize($zip_filesize);
    $sql_basicsize = duplicator_bytesize($sql_filesize);
    $exe_basicsize = duplicator_bytesize($exe_filesize);
    if ($zip_filesize && $sql_filesize && $sql_filesize) {
        $msg_complete_stats = "FILE SIZE: Zip:{$zip_basicsize} | SQL:{$sql_basicsize} | Installer:{$exe_basicsize}";
    } else {
        duplicator_error("ERROR: A required file contains zero bytes. \nERROR INFO: Zip Size:{$zip_basicsize} | SQL Size:{$sql_basicsize} | Installer Size:{$exe_basicsize}");
    }
    //SEND EMAIL
    //TODO: Send only SQL File via mail.  Zip files can get too large
    if ($GLOBALS['duplicator_opts']['email-me'] == "1") {
        duplicator_log("---------------------------------");
        duplicator_log("SENDING EMAIL");
        $status = $zip->zipFileSize ? 'Success' : 'Failure';
        $attachments = "";
        //array(DUPLICATOR_SSDIR_PATH . '/' . $packname .'.zip');
        $headers = 'From: Duplicator Plugin <no-reply@lifeinthegrid.com>' . "\r\n";
        $subject = "Package '{$packname}' completed";
        $message = "Run Status: {$status}\n\rSite Name: " . get_bloginfo('name') . "\n\rPackage Name: {$packname} \n\rCompleted at: " . current_time('mysql', get_option('gmt_offset'));
        $result = wp_mail($current_user->user_email, $subject, $message, $headers, $attachments);
        duplicator_log("EMAIL SENT TO: {$current_user->user_email}");
        duplicator_log("EMAIL SEND STATUS: {$result}");
        $other_emails = @preg_split("/[,;]/", $GLOBALS['duplicator_opts']['email_others']);
        if (count($other_emails)) {
            $result = wp_mail($other_emails, $subject, $message, $headers, $attachments);
            duplicator_log("OTHER EMAILS SENT: {$GLOBALS['duplicator_opts']['email_others']}");
            duplicator_log("OTHER EMAIL SEND STATUS: {$result}");
        }
        duplicator_log("EMAIL FINISHED");
    }
    $fulltime_end = DuplicatorUtils::GetMicrotime();
    $fulltime_sum = DuplicatorUtils::ElapsedTime($fulltime_end, $fulltime_start);
    duplicator_log("********************************************************************************");
    duplicator_log($msg_complete_stats);
    duplicator_log("TOTAL PROCESS RUNTIME: {$fulltime_sum}");
    duplicator_log("DONE PROCESSING => {$packname} " . @date('h:i:s'));
    duplicator_log("********************************************************************************");
    @fclose($GLOBALS['duplicator_package_log_handle']);
    error_reporting($error_level);
    //=====================================================
    //DONE: UPDATE TRANSACTION
    $pack_settings = serialize(array('plugin_version' => DUPLICATOR_VERSION, 'type' => 'Manual', 'status' => 'Pass', 'notes' => "{$packnotes}"));
    $result = $wpdb->update($wpdb->prefix . "duplicator", array('zipsize' => $zip->zipFileSize, 'created' => current_time('mysql', get_option('gmt_offset')), 'owner' => $current_user->user_login, 'settings' => "{$pack_settings}"), array('id' => $table_id));
    if ($result == false) {
        $error_result = $wpdb->print_error();
        duplicator_error("ERROR: Unable to update database table. \nERROR INFO: '{$error_result}'");
    } else {
        $add1_passcount = get_option('duplicator_add1_passcount', 0);
        $pack_passcount = get_option('duplicator_pack_passcount', 0);
        update_option('duplicator_add1_passcount', $add1_passcount + 1);
        update_option('duplicator_pack_passcount', $pack_passcount + 1);
    }
    die;
}