Ejemplo n.º 1
0
 /**
  *
  * This starts or restarts the job working
  *
  * @param string $start_type Start types are 'runnow', 'runnowalt', 'cronrun', 'runext', 'runcli'
  * @param array|int $job_id The id of job of a job to start
  */
 private function create($start_type, $job_id = 0)
 {
     global $wpdb;
     /* @var wpdb $wpdb */
     //check startype
     if (!in_array($start_type, array('runnow', 'runnowalt', 'cronrun', 'runext', 'runcli'), true)) {
         return;
     }
     if ($job_id) {
         $this->job = BackWPup_Option::get_job($job_id);
     } else {
         return;
     }
     $this->start_time = current_time('timestamp');
     $this->lastmsg = __('Starting job', 'backwpup');
     //set Logfile
     $log_folder = get_site_option('backwpup_cfg_logfolder');
     $log_folder = BackWPup_File::get_absolute_path($log_folder);
     $this->logfile = $log_folder . 'backwpup_log_' . BackWPup::get_plugin_data('hash') . '_' . date('Y-m-d_H-i-s', current_time('timestamp')) . '.html';
     //write settings to job
     BackWPup_Option::update($this->job['jobid'], 'lastrun', $this->start_time);
     BackWPup_Option::update($this->job['jobid'], 'logfile', $this->logfile);
     //Set current logfile
     BackWPup_Option::update($this->job['jobid'], 'lastbackupdownloadurl', '');
     //Set needed job values
     $this->timestamp_last_update = microtime(true);
     $this->exclude_from_backup = explode(',', trim($this->job['fileexclude']));
     $this->exclude_from_backup = array_unique($this->exclude_from_backup);
     //setup job steps
     $this->steps_data['CREATE']['CALLBACK'] = '';
     $this->steps_data['CREATE']['NAME'] = __('Job Start', 'backwpup');
     $this->steps_data['CREATE']['STEP_TRY'] = 0;
     //ADD Job types file
     /* @var $job_type_class BackWPup_JobTypes */
     $job_need_dest = false;
     if ($job_types = BackWPup::get_job_types()) {
         foreach ($job_types as $id => $job_type_class) {
             if (in_array($id, $this->job['type'], true) && $job_type_class->creates_file()) {
                 $this->steps_todo[] = 'JOB_' . $id;
                 $this->steps_data['JOB_' . $id]['NAME'] = $job_type_class->info['description'];
                 $this->steps_data['JOB_' . $id]['STEP_TRY'] = 0;
                 $this->steps_data['JOB_' . $id]['SAVE_STEP_TRY'] = 0;
                 $job_need_dest = true;
             }
         }
     }
     //add destinations and create archive if a job where files to backup
     if ($job_need_dest) {
         //Create manifest file
         $this->steps_todo[] = 'CREATE_MANIFEST';
         $this->steps_data['CREATE_MANIFEST']['NAME'] = __('Creates manifest file', 'backwpup');
         $this->steps_data['CREATE_MANIFEST']['STEP_TRY'] = 0;
         $this->steps_data['CREATE_MANIFEST']['SAVE_STEP_TRY'] = 0;
         //Add archive creation and backup filename on backup type archive
         if ($this->job['backuptype'] == 'archive') {
             //get Backup folder if destination folder set
             if (in_array('FOLDER', $this->job['destinations'], true)) {
                 $this->backup_folder = $this->job['backupdir'];
                 //check backup folder
                 if (!empty($this->backup_folder)) {
                     $this->backup_folder = BackWPup_File::get_absolute_path($this->backup_folder);
                     $this->job['backupdir'] = $this->backup_folder;
                 }
             }
             //set temp folder to backup folder if not set because we need one
             if (!$this->backup_folder || $this->backup_folder == '/') {
                 $this->backup_folder = BackWPup::get_plugin_data('TEMP');
             }
             //Create backup archive full file name
             $this->backup_file = $this->generate_filename($this->job['archivename'], $this->job['archiveformat']);
             //add archive create
             $this->steps_todo[] = 'CREATE_ARCHIVE';
             $this->steps_data['CREATE_ARCHIVE']['NAME'] = __('Creates archive', 'backwpup');
             $this->steps_data['CREATE_ARCHIVE']['STEP_TRY'] = 0;
             $this->steps_data['CREATE_ARCHIVE']['SAVE_STEP_TRY'] = 0;
         }
         //ADD Destinations
         /* @var BackWPup_Destinations $dest_class */
         foreach (BackWPup::get_registered_destinations() as $id => $dest) {
             if (!in_array($id, $this->job['destinations'], true) || empty($dest['class'])) {
                 continue;
             }
             $dest_class = BackWPup::get_destination($id);
             if ($dest_class->can_run($this->job)) {
                 if ($this->job['backuptype'] == 'sync') {
                     if ($dest['can_sync']) {
                         $this->steps_todo[] = 'DEST_SYNC_' . $id;
                         $this->steps_data['DEST_SYNC_' . $id]['NAME'] = $dest['info']['description'];
                         $this->steps_data['DEST_SYNC_' . $id]['STEP_TRY'] = 0;
                         $this->steps_data['DEST_SYNC_' . $id]['SAVE_STEP_TRY'] = 0;
                     }
                 } else {
                     $this->steps_todo[] = 'DEST_' . $id;
                     $this->steps_data['DEST_' . $id]['NAME'] = $dest['info']['description'];
                     $this->steps_data['DEST_' . $id]['STEP_TRY'] = 0;
                     $this->steps_data['DEST_' . $id]['SAVE_STEP_TRY'] = 0;
                 }
             }
         }
     }
     //ADD Job type no file
     if ($job_types = BackWPup::get_job_types()) {
         foreach ($job_types as $id => $job_type_class) {
             if (in_array($id, $this->job['type'], true) && !$job_type_class->creates_file()) {
                 $this->steps_todo[] = 'JOB_' . $id;
                 $this->steps_data['JOB_' . $id]['NAME'] = $job_type_class->info['description'];
                 $this->steps_data['JOB_' . $id]['STEP_TRY'] = 0;
                 $this->steps_data['JOB_' . $id]['SAVE_STEP_TRY'] = 0;
             }
         }
     }
     $this->steps_todo[] = 'END';
     $this->steps_data['END']['NAME'] = __('End of Job', 'backwpup');
     $this->steps_data['END']['STEP_TRY'] = 1;
     //must write working data
     $this->write_running_file();
     //set log level
     $this->log_level = get_site_option('backwpup_cfg_loglevel', 'normal_translated');
     if (!in_array($this->log_level, array('normal_translated', 'normal', 'debug_translated', 'debug'), true)) {
         $this->log_level = 'normal_translated';
     }
     //create log file
     $head = '';
     $info = '';
     $head .= "<!DOCTYPE html>" . PHP_EOL;
     $head .= "<html lang=\"" . str_replace('_', '-', get_locale()) . "\">" . PHP_EOL;
     $head .= "<head>" . PHP_EOL;
     $head .= "<meta charset=\"" . get_bloginfo('charset') . "\" />" . PHP_EOL;
     $head .= "<title>" . sprintf(__('BackWPup log for %1$s from %2$s at %3$s', 'backwpup'), $this->job['name'], date_i18n(get_option('date_format')), date_i18n(get_option('time_format'))) . "</title>" . PHP_EOL;
     $head .= "<meta name=\"robots\" content=\"noindex, nofollow\" />" . PHP_EOL;
     $head .= "<meta name=\"copyright\" content=\"Copyright &copy; 2012 - " . date('Y') . " Inpsyde GmbH\" />" . PHP_EOL;
     $head .= "<meta name=\"author\" content=\"Inpsyde GmbH\" />" . PHP_EOL;
     $head .= "<meta name=\"generator\" content=\"BackWPup " . BackWPup::get_plugin_data('Version') . "\" />" . PHP_EOL;
     $head .= "<meta http-equiv=\"cache-control\" content=\"no-cache\" />" . PHP_EOL;
     $head .= "<meta http-equiv=\"pragma\" content=\"no-cache\" />" . PHP_EOL;
     $head .= "<meta name=\"date\" content=\"" . date('c') . "\" />" . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_errors" content="0" />', 100) . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_warnings" content="0" />', 100) . PHP_EOL;
     $head .= "<meta name=\"backwpup_jobid\" content=\"" . $this->job['jobid'] . "\" />" . PHP_EOL;
     $head .= "<meta name=\"backwpup_jobname\" content=\"" . esc_attr($this->job['name']) . "\" />" . PHP_EOL;
     $head .= "<meta name=\"backwpup_jobtype\" content=\"" . implode('+', $this->job['type']) . "\" />" . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_backupfilesize" content="0" />', 100) . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_jobruntime" content="0" />', 100) . PHP_EOL;
     $head .= '</head>' . PHP_EOL;
     $head .= '<body style="margin:0;padding:3px;font-family:monospace;font-size:12px;line-height:15px;background-color:black;color:#c0c0c0;white-space:nowrap;">' . PHP_EOL;
     $info .= sprintf(_x('[INFO] %1$s %2$s; A project of Inpsyde GmbH', 'Plugin name; Plugin Version; plugin url', 'backwpup'), BackWPup::get_plugin_data('name'), BackWPup::get_plugin_data('Version'), __('http://backwpup.com', 'backwpup')) . '<br />' . PHP_EOL;
     $info .= sprintf(_x('[INFO] WordPress %1$s on %2$s', 'WordPress Version; Blog url', 'backwpup'), BackWPup::get_plugin_data('wp_version'), esc_attr(site_url('/'))) . '<br />' . PHP_EOL;
     $level = __('Normal', 'backwpup');
     $translated = '';
     if ($this->is_debug()) {
         $level = __('Debug', 'backwpup');
     }
     if (is_textdomain_loaded('backwpup')) {
         $translated = __('(translated)', 'backwpup');
     }
     $info .= sprintf(__('[INFO] Log Level: %1$s %2$s', 'backwpup'), $level, $translated) . '<br />' . PHP_EOL;
     $job_name = esc_attr($this->job['name']);
     if ($this->is_debug()) {
         $job_name .= '; ' . implode('+', $this->job['type']);
     }
     $info .= sprintf(__('[INFO] BackWPup job: %1$s', 'backwpup'), $job_name) . '<br />' . PHP_EOL;
     if ($this->is_debug()) {
         $current_user = wp_get_current_user();
         $info .= sprintf(__('[INFO] Runs with user: %1$s (%2$d) ', 'backwpup'), $current_user->user_login, $current_user->ID) . '<br />' . PHP_EOL;
     }
     if ($this->job['activetype'] === 'wpcron') {
         //check next run
         $cron_next = wp_next_scheduled('backwpup_cron', array('id' => $this->job['jobid']));
         if (!$cron_next || $cron_next < time()) {
             wp_unschedule_event($cron_next, 'backwpup_cron', array('id' => $this->job['jobid']));
             $cron_next = BackWPup_Cron::cron_next($this->job['cron']);
             wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $this->job['jobid']));
             $cron_next = wp_next_scheduled('backwpup_cron', array('id' => $this->job['jobid']));
         }
         //output scheduling
         if ($this->is_debug()) {
             if (!$cron_next) {
                 $cron_next = __('Not scheduled!', 'backwpup');
             } else {
                 $cron_next = date_i18n('D, j M Y @ H:i', $cron_next + get_option('gmt_offset') * 3600, true);
             }
             $info .= sprintf(__('[INFO] Cron: %s; Next: %s ', 'backwpup'), $this->job['cron'], $cron_next) . '<br />' . PHP_EOL;
         }
     } elseif ($this->job['activetype'] == 'link' && $this->is_debug()) {
         $info .= __('[INFO] BackWPup job start with link is active', 'backwpup') . '<br />' . PHP_EOL;
     } elseif ($this->job['activetype'] == 'easycron' && $this->is_debug()) {
         $info .= __('[INFO] BackWPup job start with EasyCron.com', 'backwpup') . '<br />' . PHP_EOL;
         //output scheduling
         if ($this->is_debug()) {
             $cron_next = BackWPup_Cron::cron_next($this->job['cron']);
             $cron_next = date_i18n('D, j M Y @ H:i', $cron_next + get_option('gmt_offset') * 3600, true);
             $info .= sprintf(__('[INFO] Cron: %s; Next: %s ', 'backwpup'), $this->job['cron'], $cron_next) . '<br />' . PHP_EOL;
         }
     } elseif ($this->is_debug()) {
         $info .= __('[INFO] BackWPup no automatic job start configured', 'backwpup') . '<br />' . PHP_EOL;
     }
     if ($this->is_debug()) {
         if ($start_type == 'cronrun') {
             $info .= __('[INFO] BackWPup job started from wp-cron', 'backwpup') . '<br />' . PHP_EOL;
         } elseif ($start_type == 'runnow' || $start_type == 'runnowalt') {
             $info .= __('[INFO] BackWPup job started manually', 'backwpup') . '<br />' . PHP_EOL;
         } elseif ($start_type == 'runext') {
             $info .= __('[INFO] BackWPup job started from external url', 'backwpup') . '<br />' . PHP_EOL;
         } elseif ($start_type == 'runcli') {
             $info .= __('[INFO] BackWPup job started form commandline interface', 'backwpup') . '<br />' . PHP_EOL;
         }
         $bit = '';
         if (PHP_INT_SIZE === 4) {
             $bit = ' (32bit)';
         }
         if (PHP_INT_SIZE === 8) {
             $bit = ' (64bit)';
         }
         $info .= __('[INFO] PHP ver.:', 'backwpup') . ' ' . PHP_VERSION . $bit . '; ' . PHP_SAPI . '; ' . PHP_OS . '<br />' . PHP_EOL;
         $info .= sprintf(__('[INFO] Maximum PHP script execution time is %1$d seconds', 'backwpup'), ini_get('max_execution_time')) . '<br />' . PHP_EOL;
         if (php_sapi_name() != 'cli') {
             $job_max_execution_time = get_site_option('backwpup_cfg_jobmaxexecutiontime');
             if (!empty($job_max_execution_time)) {
                 $info .= sprintf(__('[INFO] Script restart time is configured to %1$d seconds', 'backwpup'), $job_max_execution_time) . '<br />' . PHP_EOL;
             }
         }
         $info .= sprintf(__('[INFO] MySQL ver.: %s', 'backwpup'), $wpdb->get_var("SELECT VERSION() AS version")) . '<br />' . PHP_EOL;
         if (isset($_SERVER['SERVER_SOFTWARE'])) {
             $info .= sprintf(__('[INFO] Web Server: %s', 'backwpup'), $_SERVER['SERVER_SOFTWARE']) . '<br />' . PHP_EOL;
         }
         if (function_exists('curl_init')) {
             $curlversion = curl_version();
             $info .= sprintf(__('[INFO] curl ver.: %1$s; %2$s', 'backwpup'), $curlversion['version'], $curlversion['ssl_version']) . '<br />' . PHP_EOL;
         }
         $info .= sprintf(__('[INFO] Temp folder is: %s', 'backwpup'), BackWPup::get_plugin_data('TEMP')) . '<br />' . PHP_EOL;
     }
     if ($this->is_debug()) {
         $logfile = $this->logfile;
     } else {
         $logfile = basename($this->logfile);
     }
     $info .= sprintf(__('[INFO] Logfile is: %s', 'backwpup'), $logfile) . '<br />' . PHP_EOL;
     if (!empty($this->backup_file) && $this->job['backuptype'] === 'archive') {
         if ($this->is_debug()) {
             $backupfile = $this->backup_folder . $this->backup_file;
         } else {
             $backupfile = $this->backup_file;
         }
         $info .= sprintf(__('[INFO] Backup file is: %s', 'backwpup'), $backupfile) . '<br />' . PHP_EOL;
     } else {
         $info .= sprintf(__('[INFO] Backup type is: %s', 'backwpup'), $this->job['backuptype']) . '<br />' . PHP_EOL;
     }
     //output info on cli
     if (php_sapi_name() == 'cli' && defined('STDOUT')) {
         fwrite(STDOUT, strip_tags($info));
     }
     if (!file_put_contents($this->logfile, $head . $info, FILE_APPEND)) {
         $this->logfile = '';
         $this->log(__('Could not write log file', 'backwpup'), E_USER_ERROR);
     }
     //test for destinations
     if ($job_need_dest) {
         $desttest = false;
         foreach ($this->steps_todo as $deststeptest) {
             if (substr($deststeptest, 0, 5) == 'DEST_') {
                 $desttest = true;
                 break;
             }
         }
         if (!$desttest) {
             $this->log(__('No destination correctly defined for backup! Please correct job settings.', 'backwpup'), E_USER_ERROR);
             $this->steps_todo = array('END');
         }
     }
     //test backup folder
     if (!empty($this->backup_folder)) {
         $folder_message = BackWPup_File::check_folder($this->backup_folder, true);
         if (!empty($folder_message)) {
             $this->log($folder_message, E_USER_ERROR);
             $this->steps_todo = array('END');
         }
     }
     //Set start as done
     $this->steps_done[] = 'CREATE';
 }
Ejemplo n.º 2
0
 /**
  *
  */
 public static function load()
 {
     //Create Table
     self::$listtable = new self();
     switch (self::$listtable->current_action()) {
         case 'delete':
             //Delete Job
             if (!current_user_can('backwpup_jobs_edit')) {
                 break;
             }
             if (is_array($_GET['jobs'])) {
                 check_admin_referer('bulk-jobs');
                 foreach ($_GET['jobs'] as $jobid) {
                     wp_clear_scheduled_hook('backwpup_cron', array('id' => absint($jobid)));
                     BackWPup_Option::delete_job(absint($jobid));
                 }
             }
             break;
         case 'copy':
             //Copy Job
             if (!current_user_can('backwpup_jobs_edit')) {
                 break;
             }
             $old_job_id = absint($_GET['jobid']);
             check_admin_referer('copy-job_' . $old_job_id);
             //create new
             $newjobid = BackWPup_Option::get_job_ids();
             sort($newjobid);
             $newjobid = end($newjobid) + 1;
             $old_options = BackWPup_Option::get_job($old_job_id);
             foreach ($old_options as $key => $option) {
                 if ($key === "jobid") {
                     $option = $newjobid;
                 }
                 if ($key === "name") {
                     $option = __('Copy of', 'backwpup') . ' ' . $option;
                 }
                 if ($key === "activetype") {
                     $option = '';
                 }
                 if ($key === "archivename") {
                     $option = str_replace($old_job_id, $newjobid, $option);
                 }
                 if ($key === "logfile" || $key === "lastbackupdownloadurl" || $key === "lastruntime" || $key === "lastrun") {
                     continue;
                 }
                 BackWPup_Option::update($newjobid, $key, $option);
             }
             break;
         case 'runnow':
             $jobid = absint($_GET['jobid']);
             if ($jobid) {
                 if (!current_user_can('backwpup_jobs_start')) {
                     wp_die(__('Sorry, you don\'t have permissions to do that.', 'backwpup'));
                 }
                 check_admin_referer('backwpup_job_run-runnowlink');
                 //check temp folder
                 $temp_folder_message = BackWPup_File::check_folder(BackWPup::get_plugin_data('TEMP'), TRUE);
                 BackWPup_Admin::message($temp_folder_message, TRUE);
                 //check log folder
                 $log_folder = get_site_option('backwpup_cfg_logfolder');
                 $log_folder = BackWPup_File::get_absolute_path($log_folder);
                 $log_folder_message = BackWPup_File::check_folder($log_folder);
                 BackWPup_Admin::message($log_folder_message, TRUE);
                 //check backup destinations
                 $job_types = BackWPup::get_job_types();
                 $job_conf_types = BackWPup_Option::get($jobid, 'type');
                 $creates_file = FALSE;
                 foreach ($job_types as $id => $job_type_class) {
                     if (in_array($id, $job_conf_types, true) && $job_type_class->creates_file()) {
                         $creates_file = TRUE;
                         break;
                     }
                 }
                 if ($creates_file) {
                     $job_conf_dests = BackWPup_Option::get($jobid, 'destinations');
                     $destinations = 0;
                     /* @var BackWPup_Destinations $dest_class */
                     foreach (BackWPup::get_registered_destinations() as $id => $dest) {
                         if (!in_array($id, $job_conf_dests, true) || empty($dest['class'])) {
                             continue;
                         }
                         $dest_class = BackWPup::get_destination($id);
                         $job_settings = BackWPup_Option::get_job($jobid);
                         if (!$dest_class->can_run($job_settings)) {
                             BackWPup_Admin::message(sprintf(__('The job "%s" destination "%s" is not configured properly', 'backwpup'), esc_attr(BackWPup_Option::get($jobid, 'name')), $id), TRUE);
                         }
                         $destinations++;
                     }
                     if ($destinations < 1) {
                         BackWPup_Admin::message(sprintf(__('The job "%s" needs properly configured destinations to run!', 'backwpup'), esc_attr(BackWPup_Option::get($jobid, 'name'))), TRUE);
                     }
                 }
                 //only start job if messages empty
                 $log_messages = BackWPup_Admin::get_messages();
                 if (empty($log_messages)) {
                     $old_log_file = BackWPup_Option::get($jobid, 'logfile');
                     BackWPup_Job::get_jobrun_url('runnow', $jobid);
                     usleep(250000);
                     //wait a quarter second
                     $new_log_file = BackWPup_Option::get($jobid, 'logfile', null, false);
                     //sleep as long as job not started
                     $i = 0;
                     while ($old_log_file === $new_log_file) {
                         usleep(250000);
                         //wait a quarter second for next try
                         $new_log_file = BackWPup_Option::get($jobid, 'logfile', null, false);
                         //wait maximal 10 sec.
                         if ($i >= 40) {
                             BackWPup_Admin::message(sprintf(__('Job "%s" has started, but not responded for 10 seconds. Please check <a href="%s">information</a>.', 'backwpup'), esc_attr(BackWPup_Option::get($jobid, 'name')), network_admin_url('admin.php') . '?page=backwpupsettings#backwpup-tab-information'), true);
                             break 2;
                         }
                         $i++;
                     }
                     BackWPup_Admin::message(sprintf(__('Job "%s" started.', 'backwpup'), esc_attr(BackWPup_Option::get($jobid, 'name'))));
                 }
             }
             break;
         case 'abort':
             //Abort Job
             if (!current_user_can('backwpup_jobs_start')) {
                 break;
             }
             check_admin_referer('abort-job');
             if (!file_exists(BackWPup::get_plugin_data('running_file'))) {
                 break;
             }
             //abort
             BackWPup_Job::user_abort();
             BackWPup_Admin::message(__('Job will be terminated.', 'backwpup'));
             break;
         default:
             do_action('backwpup_page_jobs_load', self::$listtable->current_action());
             break;
     }
     self::$listtable->prepare_items();
 }
Ejemplo n.º 3
0
 /**
  *
  */
 public static function load()
 {
     //Create Table
     self::$listtable = new self();
     switch (self::$listtable->current_action()) {
         case 'delete':
             //Delete Job
             if (!current_user_can('backwpup_jobs_edit')) {
                 break;
             }
             if (is_array($_GET['jobs'])) {
                 check_admin_referer('bulk-jobs');
                 foreach ($_GET['jobs'] as $jobid) {
                     wp_clear_scheduled_hook('backwpup_cron', array('id' => $jobid));
                     BackWPup_Option::delete_job($jobid);
                 }
             }
             break;
         case 'copy':
             //Copy Job
             if (!current_user_can('backwpup_jobs_edit')) {
                 break;
             }
             $old_job_id = (int) $_GET['jobid'];
             check_admin_referer('copy-job_' . $_GET['jobid']);
             //create new
             $newjobid = BackWPup_Option::get_job_ids();
             sort($newjobid);
             $newjobid = end($newjobid) + 1;
             $old_options = BackWPup_Option::get_job($old_job_id);
             foreach ($old_options as $key => $option) {
                 if ($key == "jobid") {
                     $option = $newjobid;
                 }
                 if ($key == "name") {
                     $option = __('Copy of', 'backwpup') . ' ' . $option;
                 }
                 if ($key == "activetype") {
                     $option = '';
                 }
                 if ($key == "archivename") {
                     $option = str_replace($_GET['jobid'], $newjobid, $option);
                 }
                 if ($key == "logfile" || $key == "lastbackupdownloadurl" || $key == "lastruntime" || $key == "lastrun") {
                     continue;
                 }
                 BackWPup_Option::update($newjobid, $key, $option);
             }
             break;
         case 'start_cli':
             //Get cmd start file
             if (!current_user_can('backwpup_jobs_start')) {
                 break;
             }
             check_admin_referer('start_cli');
             if (empty($_GET['jobid'])) {
                 break;
             }
             if (FALSE === strpos(PHP_OS, "WIN")) {
                 header("Pragma: public");
                 header("Expires: 0");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Type: application/octet-stream");
                 header("Content-Disposition: attachment; filename=BackWPup_cmd_start_job_" . $_GET['jobid'] . ".sh;");
                 if (defined('PHP_BINDIR')) {
                     echo "#!/bin/sh" . PHP_EOL;
                 }
                 echo "@\$1php -c \"" . php_ini_loaded_file() . "\" -r \"\$_SERVER[ 'SERVER_ADDR' ] = '" . $_SERVER['SERVER_ADDR'] . "'; \$_SERVER[ 'REMOTE_ADDR' ] = '" . $_SERVER['REMOTE_ADDR'] . "'; \$_SERVER[ 'HTTP_HOST' ] = '" . $_SERVER['HTTP_HOST'] . "'; \$_SERVER[ 'HTTP_USER_AGENT' ] = '" . BackWPup::get_plugin_data('name') . "'; define( 'DOING_CRON', TRUE ); require '" . ABSPATH . "wp-load.php'; if( class_exists( 'BackWPup_Job' ) ) BackWPup_Job::start_cli( " . $_GET['jobid'] . " );\"";
                 die;
             } else {
                 header("Pragma: public");
                 header("Expires: 0");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Type: application/octet-stream");
                 header("Content-Disposition: attachment; filename=BackWPup_cmd_start_job_" . $_GET['jobid'] . ".cmd;");
                 echo "@%1php.exe -c \"" . php_ini_loaded_file() . "\" -r \"\$_SERVER[ 'SERVER_ADDR' ] = '" . $_SERVER['SERVER_ADDR'] . "'; \$_SERVER[ 'REMOTE_ADDR' ] = '" . $_SERVER['REMOTE_ADDR'] . "'; \$_SERVER[ 'HTTP_HOST' ] = '" . $_SERVER['HTTP_HOST'] . "'; \$_SERVER[ 'HTTP_USER_AGENT' ] = '" . BackWPup::get_plugin_data('name') . "'; define( 'DOING_CRON', TRUE ); require '" . ABSPATH . "wp-load.php'; if( class_exists( 'BackWPup_Job' ) ) BackWPup_Job::start_cli( " . $_GET['jobid'] . " );\"";
                 die;
             }
             break;
         case 'runnow':
             if (!empty($_GET['jobid'])) {
                 if (!current_user_can('backwpup_jobs_start')) {
                     wp_die(__('Sorry, you don\'t have permissions to do that.', 'backwpup'));
                 }
                 check_admin_referer('backwpup_job_run-runnowlink');
                 //check temp folder
                 BackWPup_Job::check_folder(BackWPup::get_plugin_data('TEMP'), TRUE);
                 //check log folder
                 BackWPup_Job::check_folder(get_site_option('backwpup_cfg_logfolder'));
                 //check server callback
                 $raw_response = BackWPup_Job::get_jobrun_url('test');
                 $test_result = '';
                 if (is_wp_error($raw_response)) {
                     $test_result .= sprintf(__('The HTTP response test get an error "%s"', 'backwpup'), $raw_response->get_error_message());
                 } elseif (200 != wp_remote_retrieve_response_code($raw_response) && 204 != wp_remote_retrieve_response_code($raw_response)) {
                     $test_result .= sprintf(__('The HTTP response test get a false http status (%s)', 'backwpup'), wp_remote_retrieve_response_code($raw_response));
                 }
                 if (!empty($test_result)) {
                     BackWPup_Admin::message($test_result, TRUE);
                 }
                 //only start job if messages empty
                 $log_messages = BackWPup_Admin::get_messages();
                 if (empty($log_messages)) {
                     $old_log_file = BackWPup_Option::get($_GET['jobid'], 'logfile');
                     BackWPup_Job::get_jobrun_url('runnow', $_GET['jobid']);
                     usleep(250000);
                     //wait a quarter second
                     $new_log_file = BackWPup_Option::get($_GET['jobid'], 'logfile', NULL, FALSE);
                     //sleep as long as job not started
                     $i = 0;
                     while ($old_log_file == $new_log_file) {
                         usleep(250000);
                         //wait a quarter second for next try
                         $new_log_file = BackWPup_Option::get($_GET['jobid'], 'logfile', NULL, FALSE);
                         //wait maximal 10 sec.
                         if ($i >= 40) {
                             BackWPup_Admin::message(sprintf(__('Job start for "%s" not answered after 10 seconds.', 'backwpup'), esc_attr(BackWPup_Option::get($_GET['jobid'], 'name'))), TRUE);
                             break 2;
                         }
                         $i++;
                     }
                     BackWPup_Admin::message(sprintf(__('Job "%s" started.', 'backwpup'), esc_attr(BackWPup_Option::get($_GET['jobid'], 'name'))));
                 }
             }
             break;
         case 'abort':
             //Abort Job
             if (!current_user_can('backwpup_jobs_start')) {
                 break;
             }
             check_admin_referer('abort-job');
             if (!file_exists(BackWPup::get_plugin_data('running_file'))) {
                 break;
             }
             //abort
             BackWPup_Job::user_abort();
             BackWPup_Admin::message(__('Job will be terminated.', 'backwpup'));
             break;
         default:
             do_action('backwpup_page_jobs_load', self::$listtable->current_action());
             break;
     }
     self::$listtable->prepare_items();
 }
 /**
  *
  */
 public static function load()
 {
     //Create Table
     self::$listtable = new self();
     switch (self::$listtable->current_action()) {
         case 'delete':
             //Delete Job
             if (!current_user_can('backwpup_jobs_edit')) {
                 break;
             }
             if (is_array($_GET['jobs'])) {
                 check_admin_referer('bulk-jobs');
                 foreach ($_GET['jobs'] as $jobid) {
                     wp_clear_scheduled_hook('backwpup_cron', array('id' => $jobid));
                     BackWPup_Option::delete_job($jobid);
                 }
             }
             break;
         case 'copy':
             //Copy Job
             if (!current_user_can('backwpup_jobs_edit')) {
                 break;
             }
             $old_job_id = (int) $_GET['jobid'];
             check_admin_referer('copy-job_' . $_GET['jobid']);
             //create new
             $newjobid = BackWPup_Option::get_job_ids();
             sort($newjobid);
             $newjobid = end($newjobid) + 1;
             $old_options = BackWPup_Option::get_job($old_job_id);
             foreach ($old_options as $key => $option) {
                 if ($key == "jobid") {
                     $option = $newjobid;
                 }
                 if ($key == "name") {
                     $option = __('Copy of', 'backwpup') . ' ' . $option;
                 }
                 if ($key == "activetype") {
                     $option = '';
                 }
                 if ($key == "archivename") {
                     $option = str_replace($_GET['jobid'], $newjobid, $option);
                 }
                 if ($key == "logfile" || $key == "lastbackupdownloadurl" || $key == "lastruntime" || $key == "lastrun") {
                     continue;
                 }
                 BackWPup_Option::update($newjobid, $key, $option);
             }
             break;
         case 'runnow':
             $_GET['jobid'] = (int) $_GET['jobid'];
             if (!empty($_GET['jobid'])) {
                 if (!current_user_can('backwpup_jobs_start')) {
                     wp_die(__('Sorry, you don\'t have permissions to do that.', 'backwpup'));
                 }
                 check_admin_referer('backwpup_job_run-runnowlink');
                 //check temp folder
                 $temp_folder_message = BackWPup_File::check_folder(BackWPup::get_plugin_data('TEMP'), TRUE);
                 BackWPup_Admin::message($temp_folder_message, TRUE);
                 //check log folder
                 $log_folder = get_site_option('backwpup_cfg_logfolder');
                 $log_folder = BackWPup_File::get_absolute_path($log_folder);
                 $log_folder_message = BackWPup_File::check_folder($log_folder);
                 BackWPup_Admin::message($log_folder_message, TRUE);
                 //check backup destinations
                 $job_types = BackWPup::get_job_types();
                 $job_conf_types = BackWPup_Option::get($_GET['jobid'], 'type');
                 $creates_file = FALSE;
                 foreach ($job_types as $id => $job_type_class) {
                     if (in_array($id, $job_conf_types) && $job_type_class->creates_file()) {
                         $creates_file = TRUE;
                         break;
                     }
                 }
                 if ($creates_file) {
                     $job_conf_dests = BackWPup_Option::get($_GET['jobid'], 'destinations');
                     $destinations = 0;
                     /* @var BackWPup_Destinations $dest_class */
                     foreach (BackWPup::get_registered_destinations() as $id => $dest) {
                         if (!in_array($id, $job_conf_dests) || empty($dest['class'])) {
                             continue;
                         }
                         $dest_class = BackWPup::get_destination($id);
                         $job_settings = BackWPup_Option::get_job($_GET['jobid']);
                         if (!$dest_class->can_run($job_settings)) {
                             BackWPup_Admin::message(sprintf(__('The job "%s" destination "%s" is not configured properly', 'backwpup'), esc_attr(BackWPup_Option::get($_GET['jobid'], 'name')), $id), TRUE);
                         }
                         $destinations++;
                     }
                     if ($destinations < 1) {
                         BackWPup_Admin::message(sprintf(__('The job "%s" needs properly configured destinations to run!', 'backwpup'), esc_attr(BackWPup_Option::get($_GET['jobid'], 'name'))), TRUE);
                     }
                 }
                 //check server callback
                 $raw_response = BackWPup_Job::get_jobrun_url('test');
                 $test_result = '';
                 if (is_wp_error($raw_response)) {
                     $test_result .= sprintf(__('The HTTP response test get an error "%s"', 'backwpup'), $raw_response->get_error_message());
                 }
                 $response_code = wp_remote_retrieve_response_code($raw_response);
                 if ($response_code < 200 && $response_code > 204) {
                     $test_result .= sprintf(__('The HTTP response test get a false http status (%s)', 'backwpup'), wp_remote_retrieve_response_code($raw_response));
                 } else {
                     $response_body = wp_remote_retrieve_body($raw_response);
                     if (FALSE === strstr($response_body, 'BackWPup Test')) {
                         $test_result .= sprintf(__('Not expected HTTP response body: %s', 'backwpup'), esc_attr(strip_tags($response_body)));
                     }
                 }
                 if (!empty($test_result)) {
                     BackWPup_Admin::message($test_result, TRUE);
                 }
                 //only start job if messages empty
                 $log_messages = BackWPup_Admin::get_messages();
                 if (empty($log_messages)) {
                     $old_log_file = BackWPup_Option::get($_GET['jobid'], 'logfile');
                     BackWPup_Job::get_jobrun_url('runnow', $_GET['jobid']);
                     usleep(250000);
                     //wait a quarter second
                     $new_log_file = BackWPup_Option::get($_GET['jobid'], 'logfile', NULL, FALSE);
                     //sleep as long as job not started
                     $i = 0;
                     while ($old_log_file == $new_log_file) {
                         usleep(250000);
                         //wait a quarter second for next try
                         $new_log_file = BackWPup_Option::get($_GET['jobid'], 'logfile', NULL, FALSE);
                         //wait maximal 10 sec.
                         if ($i >= 40) {
                             BackWPup_Admin::message(sprintf(__('Job “%s” has started, but not responded for 10 seconds.', 'backwpup'), esc_attr(BackWPup_Option::get($_GET['jobid'], 'name'))), TRUE);
                             break 2;
                         }
                         $i++;
                     }
                     BackWPup_Admin::message(sprintf(__('Job "%s" started.', 'backwpup'), esc_attr(BackWPup_Option::get($_GET['jobid'], 'name'))));
                 }
             }
             break;
         case 'abort':
             //Abort Job
             if (!current_user_can('backwpup_jobs_start')) {
                 break;
             }
             check_admin_referer('abort-job');
             if (!file_exists(BackWPup::get_plugin_data('running_file'))) {
                 break;
             }
             //abort
             BackWPup_Job::user_abort();
             BackWPup_Admin::message(__('Job will be terminated.', 'backwpup'));
             break;
         default:
             do_action('backwpup_page_jobs_load', self::$listtable->current_action());
             break;
     }
     self::$listtable->prepare_items();
 }
Ejemplo n.º 5
0
 /**
  *
  * This starts or restarts the job working
  *
  * @param string $start_type Start types are 'runnow', 'runnowalt', 'cronrun', 'runext', 'runcli'
  * @param array|int $job_settings The id of job or the settings of a job to start
  */
 private function create($start_type, $job_settings = 0)
 {
     global $wpdb;
     /* @var wpdb $wpdb */
     //check startype
     if (!in_array($start_type, array('runnow', 'runnowalt', 'cronrun', 'runext', 'runcli'))) {
         return;
     }
     if (is_int($job_settings)) {
         $this->job = BackWPup_Option::get_job($job_settings);
     } elseif (is_array($job_settings)) {
         $this->job = $job_settings;
     } else {
         return;
     }
     $this->start_time = current_time('timestamp');
     $this->lastmsg = '<samp>' . __('Starting job', 'backwpup') . '</samp>';
     //set Logfile
     $this->logfile = get_site_option('backwpup_cfg_logfolder') . 'backwpup_log_' . BackWPup::get_plugin_data('hash') . '_' . date_i18n('Y-m-d_H-i-s') . '.html';
     //write settings to job
     if (!empty($this->job['jobid'])) {
         BackWPup_Option::update($this->job['jobid'], 'lastrun', $this->start_time);
         BackWPup_Option::update($this->job['jobid'], 'logfile', $this->logfile);
         //Set current logfile
         BackWPup_Option::update($this->job['jobid'], 'lastbackupdownloadurl', '');
     }
     //Set needed job values
     $this->timestamp_last_update = microtime(TRUE);
     $this->exclude_from_backup = explode(',', trim($this->job['fileexclude']));
     $this->exclude_from_backup = array_unique($this->exclude_from_backup);
     //create path to remove
     $this->remove_path = trailingslashit(str_replace('\\', '/', realpath(ABSPATH)));
     if ($this->remove_path == '/') {
         $this->remove_path = '';
     }
     //setup job steps
     $this->steps_data['CREATE']['CALLBACK'] = '';
     $this->steps_data['CREATE']['NAME'] = __('Job Start', 'backwpup');
     $this->steps_data['CREATE']['STEP_TRY'] = 0;
     //ADD Job types file
     /* @var $job_type_class BackWPup_JobTypes */
     $job_need_dest = FALSE;
     if ($job_types = BackWPup::get_job_types()) {
         foreach ($job_types as $id => $job_type_class) {
             if (in_array($id, $this->job['type']) && $job_type_class->creates_file()) {
                 $this->steps_todo[] = 'JOB_' . $id;
                 $this->steps_data['JOB_' . $id]['NAME'] = $job_type_class->info['description'];
                 $this->steps_data['JOB_' . $id]['STEP_TRY'] = 0;
                 $this->steps_data['JOB_' . $id]['SAVE_STEP_TRY'] = 0;
                 $job_need_dest = TRUE;
             }
         }
     }
     //add destinations and create archive if a job where files to backup
     if ($job_need_dest) {
         //Create manifest file
         $this->steps_todo[] = 'CREATE_MANIFEST';
         $this->steps_data['CREATE_MANIFEST']['NAME'] = __('Creates manifest file', 'backwpup');
         $this->steps_data['CREATE_MANIFEST']['STEP_TRY'] = 0;
         $this->steps_data['CREATE_MANIFEST']['SAVE_STEP_TRY'] = 0;
         //Add archive creation and backup filename on backup type archive
         if ($this->job['backuptype'] == 'archive') {
             //get Backup folder if destination folder set
             if (in_array('FOLDER', $this->job['destinations'])) {
                 $this->backup_folder = $this->job['backupdir'];
                 //check backup folder
                 if (!empty($this->backup_folder)) {
                     self::check_folder($this->backup_folder, TRUE);
                 }
             }
             //set temp folder to backup folder if not set because we need one
             if (!$this->backup_folder || $this->backup_folder == '/') {
                 $this->backup_folder = BackWPup::get_plugin_data('TEMP');
             }
             //Create backup archive full file name
             $this->backup_file = $this->generate_filename($this->job['archivename'], $this->job['archiveformat']);
             //add archive create
             $this->steps_todo[] = 'CREATE_ARCHIVE';
             $this->steps_data['CREATE_ARCHIVE']['NAME'] = __('Creates archive', 'backwpup');
             $this->steps_data['CREATE_ARCHIVE']['STEP_TRY'] = 0;
             $this->steps_data['CREATE_ARCHIVE']['SAVE_STEP_TRY'] = 0;
         }
         //ADD Destinations
         /* @var BackWPup_Destinations $dest_class */
         foreach (BackWPup::get_registered_destinations() as $id => $dest) {
             if (!in_array($id, $this->job['destinations']) || empty($dest['class'])) {
                 continue;
             }
             $dest_class = BackWPup::get_destination($id);
             if ($dest_class->can_run($this)) {
                 if ($this->job['backuptype'] == 'sync') {
                     if ($dest['can_sync']) {
                         $this->steps_todo[] = 'DEST_SYNC_' . $id;
                         $this->steps_data['DEST_SYNC_' . $id]['NAME'] = $dest['info']['description'];
                         $this->steps_data['DEST_SYNC_' . $id]['STEP_TRY'] = 0;
                         $this->steps_data['DEST_SYNC_' . $id]['SAVE_STEP_TRY'] = 0;
                     }
                 } else {
                     $this->steps_todo[] = 'DEST_' . $id;
                     $this->steps_data['DEST_' . $id]['NAME'] = $dest['info']['description'];
                     $this->steps_data['DEST_' . $id]['STEP_TRY'] = 0;
                     $this->steps_data['DEST_' . $id]['SAVE_STEP_TRY'] = 0;
                 }
             }
         }
     }
     //ADD Job type no file
     if ($job_types = BackWPup::get_job_types()) {
         foreach ($job_types as $id => $job_type_class) {
             if (in_array($id, $this->job['type']) && !$job_type_class->creates_file()) {
                 $this->steps_todo[] = 'JOB_' . $id;
                 $this->steps_data['JOB_' . $id]['NAME'] = $job_type_class->info['description'];
                 $this->steps_data['JOB_' . $id]['STEP_TRY'] = 0;
                 $this->steps_data['JOB_' . $id]['SAVE_STEP_TRY'] = 0;
             }
         }
     }
     $this->steps_todo[] = 'END';
     $this->steps_data['END']['NAME'] = __('End of Job', 'backwpup');
     $this->steps_data['END']['STEP_TRY'] = 0;
     //create log file
     $head = '';
     $head .= "<!DOCTYPE html>" . PHP_EOL;
     $head .= "<html lang=\"" . str_replace('_', '-', get_locale()) . "\">" . PHP_EOL;
     $head .= "<head>" . PHP_EOL;
     $head .= "<meta charset=\"" . get_bloginfo('charset') . "\" />" . PHP_EOL;
     $head .= "<title>" . sprintf(__('BackWPup log for %1$s from %2$s at %3$s', 'backwpup'), $this->job['name'], date_i18n(get_option('date_format')), date_i18n(get_option('time_format'))) . "</title>" . PHP_EOL;
     $head .= "<meta name=\"robots\" content=\"noindex, nofollow\" />" . PHP_EOL;
     $head .= "<meta name=\"copyright\" content=\"Copyright &copy; 2012 - " . date_i18n('Y') . " Inpsyde GmbH\" />" . PHP_EOL;
     $head .= "<meta name=\"author\" content=\"Inpsyde GmbH\" />" . PHP_EOL;
     $head .= "<meta name=\"generator\" content=\"BackWPup " . BackWPup::get_plugin_data('Version') . "\" />" . PHP_EOL;
     $head .= "<meta http-equiv=\"cache-control\" content=\"no-cache\" />" . PHP_EOL;
     $head .= "<meta http-equiv=\"pragma\" content=\"no-cache\" />" . PHP_EOL;
     $head .= "<meta name=\"date\" content=\"" . date('c') . "\" />" . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_errors" content="0" />', 100) . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_warnings" content="0" />', 100) . PHP_EOL;
     if (!empty($this->job['jobid'])) {
         $head .= "<meta name=\"backwpup_jobid\" content=\"" . $this->job['jobid'] . "\" />" . PHP_EOL;
     }
     $head .= "<meta name=\"backwpup_jobname\" content=\"" . esc_attr($this->job['name']) . "\" />" . PHP_EOL;
     $head .= "<meta name=\"backwpup_jobtype\" content=\"" . implode('+', $this->job['type']) . "\" />" . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_backupfilesize" content="0" />', 100) . PHP_EOL;
     $head .= str_pad('<meta name="backwpup_jobruntime" content="0" />', 100) . PHP_EOL;
     $head .= "</head>" . PHP_EOL;
     $head .= "<body style=\"margin:0;padding:3px;font-family:Fixedsys,Courier,monospace;font-size:12px;line-height:15px;background-color:#000;color:#fff;white-space:pre;\">" . PHP_EOL;
     $head .= sprintf(_x('[INFO] %1$s version %2$s; A project of Inpsyde GmbH', 'Plugin name; Plugin Version', 'backwpup'), BackWPup::get_plugin_data('name'), BackWPup::get_plugin_data('Version')) . PHP_EOL;
     $head .= sprintf(_x('[INFO] WordPress version %s', 'WordPress Version', 'backwpup'), BackWPup::get_plugin_data('wp_version')) . PHP_EOL;
     $head .= sprintf(__('[INFO] Blog url: %s', 'backwpup'), esc_attr(site_url('/'))) . PHP_EOL;
     $head .= sprintf(__('[INFO] BackWPup job: %1$s; %2$s', 'backwpup'), esc_attr($this->job['name']), implode('+', $this->job['type'])) . PHP_EOL;
     if ($this->job['activetype'] == 'wpcron') {
         //check next run
         $cron_next = wp_next_scheduled('backwpup_cron', array('id' => $this->job['jobid']));
         if (!$cron_next || $cron_next < time()) {
             wp_unschedule_event($cron_next, 'backwpup_cron', array('id' => $this->job['jobid']));
             $cron_next = BackWPup_Cron::cron_next($this->job['cron']);
             wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $this->job['jobid']));
             $cron_next = wp_next_scheduled('backwpup_cron', array('id' => $this->job['jobid']));
         }
         //output scheduling
         if (!$cron_next) {
             $cron_next = __('Not scheduled!', 'backwpup');
         } else {
             $cron_next = date_i18n('D, j M Y @ H:i', $cron_next + get_option('gmt_offset') * 3600, TRUE);
         }
         $head .= sprintf(__('[INFO] BackWPup cron: %s; Next: %s ', 'backwpup'), $this->job['cron'], $cron_next) . PHP_EOL;
     } elseif ($this->job['activetype'] == 'link') {
         $head .= __('[INFO] BackWPup job start with link is active', 'backwpup') . PHP_EOL;
     } else {
         $head .= __('[INFO] BackWPup no automatic job start configured', 'backwpup') . PHP_EOL;
     }
     if ($start_type == 'cronrun') {
         $head .= __('[INFO] BackWPup job started from wp-cron', 'backwpup') . PHP_EOL;
     } elseif ($start_type == 'runnow' or $start_type == 'runnowalt') {
         $head .= __('[INFO] BackWPup job started manually', 'backwpup') . PHP_EOL;
     } elseif ($start_type == 'runext') {
         $head .= __('[INFO] BackWPup job started from external url', 'backwpup') . PHP_EOL;
     } elseif ($start_type == 'runcli') {
         $head .= __('[INFO] BackWPup job started form commandline interface', 'backwpup') . PHP_EOL;
     }
     $head .= __('[INFO] PHP ver.:', 'backwpup') . ' ' . PHP_VERSION . '; ' . PHP_SAPI . '; ' . PHP_OS . PHP_EOL;
     $head .= sprintf(__('[INFO] Maximum PHP script execution time is %1$d seconds', 'backwpup'), ini_get('max_execution_time')) . PHP_EOL;
     $job_max_execution_time = get_site_option('backwpup_cfg_jobmaxexecutiontime');
     if (!empty($job_max_execution_time)) {
         $head .= sprintf(__('[INFO] Script restart time is configured to %1$d seconds', 'backwpup'), $job_max_execution_time) . PHP_EOL;
     }
     if (get_site_option('backwpup_cfg_jobsteprestart')) {
         $head .= __('[INFO] Script restarts on every main step is activated', 'backwpup') . PHP_EOL;
     }
     $head .= sprintf(__('[INFO] MySQL ver.: %s', 'backwpup'), $wpdb->get_var("SELECT VERSION() AS version")) . PHP_EOL;
     if (function_exists('curl_init')) {
         $curlversion = curl_version();
         $head .= sprintf(__('[INFO] curl ver.: %1$s; %2$s', 'backwpup'), $curlversion['version'], $curlversion['ssl_version']) . PHP_EOL;
     }
     $head .= sprintf(__('[INFO] Temp folder is: %s', 'backwpup'), BackWPup::get_plugin_data('TEMP')) . PHP_EOL;
     $head .= sprintf(__('[INFO] Logfile is: %s', 'backwpup'), $this->logfile) . PHP_EOL;
     $head .= sprintf(__('[INFO] Backup type is: %s', 'backwpup'), $this->job['backuptype']) . PHP_EOL;
     if (!empty($this->backup_file) && $this->job['backuptype'] == 'archive') {
         $head .= sprintf(__('[INFO] Backup file is: %s', 'backwpup'), $this->backup_folder . $this->backup_file) . PHP_EOL;
     }
     file_put_contents($this->logfile, $head, FILE_APPEND);
     //output info on cli
     if (defined('STDIN') && defined('STDOUT')) {
         fwrite(STDOUT, strip_tags($head));
     }
     //test for destinations
     if ($job_need_dest) {
         $desttest = FALSE;
         foreach ($this->steps_todo as $deststeptest) {
             if (substr($deststeptest, 0, 5) == 'DEST_') {
                 $desttest = TRUE;
                 break;
             }
         }
         if (!$desttest) {
             $this->log(__('No destination correctly defined for backup! Please correct job settings.', 'backwpup'), E_USER_ERROR);
         }
     }
     //Set start as done
     $this->steps_done[] = 'CREATE';
     //must write working data
     file_put_contents(BackWPup::get_plugin_data('running_file'), '<?php return ' . var_export($this, true) . ';');
 }