示例#1
0
 /**
  *
  * Called on job stop makes cleanup and terminates the script
  *
  */
 private function end()
 {
     $this->step_working = 'END';
     $this->substeps_todo = 1;
     if (!file_exists(BackWPup::get_plugin_data('running_file'))) {
         $this->log(__('Aborted by user!', 'backwpup'), E_USER_ERROR);
     }
     //delete old logs
     if (get_site_option('backwpup_cfg_maxlogs')) {
         $log_file_list = array();
         $log_folder = trailingslashit(dirname($this->logfile));
         if (is_readable($log_folder) && ($dir = opendir($log_folder))) {
             //make file list
             while (($file = readdir($dir)) !== false) {
                 if (strpos($file, 'backwpup_log_') == 0 && false !== strpos($file, '.html')) {
                     $log_file_list[filemtime($log_folder . $file)] = $file;
                 }
             }
             closedir($dir);
         }
         if (sizeof($log_file_list) > 0) {
             krsort($log_file_list, SORT_NUMERIC);
             $num_delete_files = 0;
             $i = -1;
             foreach ($log_file_list as $log_file) {
                 $i++;
                 if ($i < get_site_option('backwpup_cfg_maxlogs')) {
                     continue;
                 }
                 unlink($log_folder . $log_file);
                 $num_delete_files++;
             }
             if ($num_delete_files > 0) {
                 $this->log(sprintf(_n('One old log deleted', '%d old logs deleted', $num_delete_files, 'backwpup'), $num_delete_files));
             }
         }
     }
     //Display job working time
     if ($this->errors > 0) {
         $this->log(sprintf(__('Job has ended with errors in %s seconds. You must resolve the errors for correct execution.', 'backwpup'), current_time('timestamp') - $this->start_time), E_USER_ERROR);
     } elseif ($this->warnings > 0) {
         $this->log(sprintf(__('Job finished with warnings in %s seconds. Please resolve them for correct execution.', 'backwpup'), current_time('timestamp') - $this->start_time), E_USER_WARNING);
     } else {
         $this->log(sprintf(__('Job done in %s seconds.', 'backwpup'), current_time('timestamp') - $this->start_time));
     }
     //Update job options
     $this->job['lastruntime'] = current_time('timestamp') - $this->start_time;
     BackWPup_Option::update($this->job['jobid'], 'lastruntime', $this->job['lastruntime']);
     //write header info
     if (!empty($this->logfile)) {
         if ($fd = fopen($this->logfile, 'r+')) {
             $filepos = ftell($fd);
             $found = 0;
             while (!feof($fd)) {
                 $line = fgets($fd);
                 if (stripos($line, '<meta name="backwpup_jobruntime"') !== false) {
                     fseek($fd, $filepos);
                     fwrite($fd, str_pad('<meta name="backwpup_jobruntime" content="' . $this->job['lastruntime'] . '" />', 100) . PHP_EOL);
                     $found++;
                 }
                 if (stripos($line, '<meta name="backwpup_backupfilesize"') !== false) {
                     fseek($fd, $filepos);
                     fwrite($fd, str_pad('<meta name="backwpup_backupfilesize" content="' . $this->backup_filesize . '" />', 100) . PHP_EOL);
                     $found++;
                 }
                 if ($found >= 2) {
                     break;
                 }
                 $filepos = ftell($fd);
             }
             fclose($fd);
         }
         //Send mail with log
         $sendmail = false;
         if ($this->job['mailaddresslog']) {
             $sendmail = true;
         }
         if ($this->errors === 0 && $this->job['mailerroronly']) {
             $sendmail = false;
         }
         if ($sendmail) {
             //special subject
             $status = __('SUCCESSFUL', 'backwpup');
             if ($this->warnings > 0) {
                 $status = __('WARNING', 'backwpup');
             }
             if ($this->errors > 0) {
                 $status = __('ERROR', 'backwpup');
             }
             $subject = sprintf(__('[%3$s] BackWPup log %1$s: %2$s', 'backwpup'), date_i18n('d-M-Y H:i', $this->start_time, true), esc_attr($this->job['name']), $status);
             $headers = array();
             $headers[] = 'Content-Type: text/html; charset=' . get_bloginfo('charset');
             if ($this->job['mailaddresssenderlog']) {
                 $this->job['mailaddresssenderlog'] = str_replace(array('&lt;', '&gt;'), array('<', '>'), $this->job['mailaddresssenderlog']);
                 $bracket_pos = strpos($this->job['mailaddresssenderlog'], '<');
                 $at_pos = strpos($this->job['mailaddresssenderlog'], '@');
                 if ($bracket_pos === false || $at_pos === false) {
                     $this->job['mailaddresssenderlog'] = str_replace(array('<', '>'), '', $this->job['mailaddresssenderlog']) . ' <' . get_bloginfo('admin_email') . '>';
                 }
                 $headers[] = 'From: ' . $this->job['mailaddresssenderlog'];
             }
             wp_mail($this->job['mailaddresslog'], $subject, file_get_contents($this->logfile), $headers);
         }
     }
     //set done
     $this->substeps_done = 1;
     $this->steps_done[] = 'END';
     //clean up temp
     self::clean_temp_folder();
     //remove shutdown action
     remove_action('shutdown', array($this, 'shutdown'));
     restore_exception_handler();
     restore_error_handler();
     //logfile end
     file_put_contents($this->logfile, "</body>" . PHP_EOL . "</html>", FILE_APPEND);
     BackWPup_Cron::check_cleanup();
     exit;
 }
 /**
  * @static
  *
  * @param string $args
  *
  * @return mixed
  */
 public static function ajax_cron_text($args = '')
 {
     if (is_array($args)) {
         extract($args);
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         if (empty($_POST['cronminutes']) || $_POST['cronminutes'][0] == '*') {
             if (!empty($_POST['cronminutes'][1])) {
                 $_POST['cronminutes'] = array('*/' . $_POST['cronminutes'][1]);
             } else {
                 $_POST['cronminutes'] = array('*');
             }
         }
         if (empty($_POST['cronhours']) || $_POST['cronhours'][0] == '*') {
             if (!empty($_POST['cronhours'][1])) {
                 $_POST['cronhours'] = array('*/' . $_POST['cronhours'][1]);
             } else {
                 $_POST['cronhours'] = array('*');
             }
         }
         if (empty($_POST['cronmday']) || $_POST['cronmday'][0] == '*') {
             if (!empty($_POST['cronmday'][1])) {
                 $_POST['cronmday'] = array('*/' . $_POST['cronmday'][1]);
             } else {
                 $_POST['cronmday'] = array('*');
             }
         }
         if (empty($_POST['cronmon']) || $_POST['cronmon'][0] == '*') {
             if (!empty($_POST['cronmon'][1])) {
                 $_POST['cronmon'] = array('*/' . $_POST['cronmon'][1]);
             } else {
                 $_POST['cronmon'] = array('*');
             }
         }
         if (empty($_POST['cronwday']) || $_POST['cronwday'][0] == '*') {
             if (!empty($_POST['cronwday'][1])) {
                 $_POST['cronwday'] = array('*/' . $_POST['cronwday'][1]);
             } else {
                 $_POST['cronwday'] = array('*');
             }
         }
         $crontype = $_POST['crontype'];
         $cronstamp = implode(",", $_POST['cronminutes']) . ' ' . implode(",", $_POST['cronhours']) . ' ' . implode(",", $_POST['cronmday']) . ' ' . implode(",", $_POST['cronmon']) . ' ' . implode(",", $_POST['cronwday']);
         $ajax = TRUE;
     }
     echo '<p class="wpcron" id="schedulecron">';
     if ($crontype == 'advanced') {
         echo str_replace('\\"', '"', __('Working as <a href="http://wikipedia.org/wiki/Cron">Cron</a> schedule:', 'backwpup'));
         echo ' <i><b>' . esc_attr($cronstamp) . '</b></i><br />';
     }
     list($cronstr['minutes'], $cronstr['hours'], $cronstr['mday'], $cronstr['mon'], $cronstr['wday']) = explode(' ', $cronstamp, 5);
     if (FALSE !== strpos($cronstr['minutes'], '*/') || $cronstr['minutes'] == '*') {
         $repeatmins = str_replace('*/', '', $cronstr['minutes']);
         if ($repeatmins == '*' || empty($repeatmins)) {
             $repeatmins = 5;
         }
         echo '<span style="color:red;">' . sprintf(__('ATTENTION: Job runs every %d minutes!', 'backwpup'), $repeatmins) . '</span><br />';
     }
     if (FALSE !== strpos($cronstr['hours'], '*/') || $cronstr['hours'] == '*') {
         $repeathouer = str_replace('*/', '', $cronstr['hours']);
         if ($repeathouer == '*' || empty($repeathouer)) {
             $repeathouer = 1;
         }
         echo '<span style="color:red;">' . sprintf(__('ATTENTION: Job runs every %d hours!', 'backwpup'), $repeathouer) . '</span><br />';
     }
     $cron_next = BackWPup_Cron::cron_next($cronstamp) + get_option('gmt_offset') * 3600;
     if (2147483647 == $cron_next) {
         echo '<span style="color:red;">' . __('ATTENTION: Can\'t calculate cron!', 'backwpup') . '</span><br />';
     } else {
         _e('Next runtime:', 'backwpup');
         echo ' <b>' . date_i18n('D, j M Y, H:i', $cron_next, TRUE) . '</b>';
     }
     echo "</p>";
     if ($ajax) {
         die;
     } else {
         return;
     }
 }
示例#3
0
 /**
  * Creates DB und updates settings
  */
 public static function activate()
 {
     //convert inactive version to active
     if ($incative_version = get_site_option('backwpup_version')) {
         update_site_option('backwpup_version', str_replace('-inactive', '', $incative_version));
     }
     //changes for version before 3.0.0
     if (!get_site_option('backwpup_version') && get_option('backwpup') && get_option('backwpup_jobs')) {
         self::upgrade_from_version_two();
     }
     //changes for version before 3.0.14
     if (version_compare('3.0.13', get_site_option('backwpup_version'), '>') && version_compare('3.0', get_site_option('backwpup_version'), '<')) {
         $upload_dir = wp_upload_dir();
         $logfolder = get_site_option('backwpup_cfg_logfolder');
         if (empty($logfolder)) {
             $old_log_folder = trailingslashit(str_replace('\\', '/', $upload_dir['basedir'])) . 'backwpup-' . substr(md5(md5(SECURE_AUTH_KEY)), 9, 5) . '-logs/';
             update_site_option('backwpup_cfg_logfolder', $old_log_folder);
         }
     }
     //changes for 3.2
     $no_translation = get_site_option('backwpup_cfg_jobnotranslate');
     if ($no_translation) {
         update_site_option('backwpup_cfg_loglevel', 'normal');
         delete_site_option('backwpup_cfg_jobnotranslate');
     }
     //create new options
     if (is_multisite()) {
         add_site_option('backwpup_jobs', array());
     } else {
         add_option('backwpup_jobs', array(), NULL, 'no');
     }
     //remove old schedule
     wp_clear_scheduled_hook('backwpup_cron');
     //make new schedule
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($id, 'cron'));
             wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $id));
         }
     }
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'easycron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             BackWPup_EasyCron::update($id);
         }
     }
     //add check Cleanup schedule
     wp_clear_scheduled_hook('backwpup_check_cleanup');
     wp_schedule_event(time(), 'twicedaily', 'backwpup_check_cleanup');
     //add capabilities to administrator role
     $role = get_role('administrator');
     if (is_object($role) && method_exists($role, 'add_cap')) {
         $role->add_cap('backwpup');
         $role->add_cap('backwpup_jobs');
         $role->add_cap('backwpup_jobs_edit');
         $role->add_cap('backwpup_jobs_start');
         $role->add_cap('backwpup_backups');
         $role->add_cap('backwpup_backups_download');
         $role->add_cap('backwpup_backups_delete');
         $role->add_cap('backwpup_logs');
         $role->add_cap('backwpup_logs_delete');
         $role->add_cap('backwpup_settings');
     }
     //add/overwrite roles
     add_role('backwpup_admin', __('BackWPup Admin', 'backwpup'), array('read' => TRUE, 'backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => TRUE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => TRUE));
     add_role('backwpup_check', __('BackWPup jobs checker', 'backwpup'), array('read' => TRUE, 'backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => FALSE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => FALSE, 'backwpup_backups_delete' => FALSE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => FALSE, 'backwpup_settings' => FALSE));
     add_role('backwpup_helper', __('BackWPup jobs helper', 'backwpup'), array('read' => TRUE, 'backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => FALSE));
     //add default options
     BackWPup_Option::default_site_options();
     //update version
     update_site_option('backwpup_version', BackWPup::get_plugin_data('Version'));
 }
示例#4
0
 /**
  * The next Column
  *
  * @param $item
  * @return string
  */
 function column_next($item)
 {
     $r = '';
     $job_normal_hide = '';
     if (is_object($this->job_object)) {
         $job_normal_hide = ' style="display:none;"';
     }
     if (is_object($this->job_object) && $this->job_object->job['jobid'] == $item) {
         $runtime = current_time('timestamp') - $this->job_object->start_time;
         $r .= '<div class="job-run">' . sprintf(esc_html__('Running for: %s seconds', 'backwpup'), '<span id="runtime">' . $runtime . '</span>') . '</div>';
     }
     if (is_object($this->job_object) && $this->job_object->job['jobid'] == $item) {
         $r .= '<div class="job-normal"' . $job_normal_hide . '>';
     }
     if (BackWPup_Option::get($item, 'activetype') == 'wpcron') {
         if ($nextrun = wp_next_scheduled('backwpup_cron', array('id' => $item)) + get_option('gmt_offset') * 3600) {
             $r .= '<span title="' . sprintf(esc_html__('Cron: %s', 'backwpup'), BackWPup_Option::get($item, 'cron')) . '">' . sprintf(__('%1$s at %2$s by WP-Cron', 'backwpup'), date_i18n(get_option('date_format'), $nextrun, TRUE), date_i18n(get_option('time_format'), $nextrun, TRUE)) . '</span><br />';
         } else {
             $r .= __('Not scheduled!', 'backwpup') . '<br />';
         }
     } elseif (BackWPup_Option::get($item, 'activetype') == 'easycron') {
         $easycron_status = BackWPup_EasyCron::status($item);
         if (!empty($easycron_status)) {
             $nextrun = BackWPup_Cron::cron_next($easycron_status['cron_expression']) + get_option('gmt_offset') * 3600;
             $r .= '<span title="' . sprintf(esc_html__('Cron: %s', 'backwpup'), $easycron_status['cron_expression']) . '">' . sprintf(__('%1$s at %2$s by EasyCron', 'backwpup'), date_i18n(get_option('date_format'), $nextrun, TRUE), date_i18n(get_option('time_format'), $nextrun, TRUE)) . '</span><br />';
         } else {
             $r .= __('Not scheduled!', 'backwpup') . '<br />';
         }
     } elseif (BackWPup_Option::get($item, 'activetype') == 'link') {
         $r .= __('External link', 'backwpup') . '<br />';
     } else {
         $r .= __('Inactive', 'backwpup');
     }
     if (is_object($this->job_object) && $this->job_object->job['jobid'] == $item) {
         $r .= '</div>';
     }
     return $r;
 }
示例#5
0
 /**
  * Check Jobs worked and Cleanup logs and so on
  */
 public static function check_cleanup()
 {
     $job_object = BackWPup_Job::get_working_data();
     // check aborted jobs for longer than a tow hours, abort them courtly and send mail
     if (is_object($job_object) && !empty($job_object->logfile)) {
         $not_worked_time = microtime(TRUE) - $job_object->timestamp_last_update;
         if ($not_worked_time > 3600) {
             $job_object->log(E_USER_ERROR, __('Aborted, because no progress for one hour!', 'backwpup'), __FILE__, __LINE__);
             $job_object->end();
         }
     }
     //Compress not compressed logs
     if (function_exists('gzopen') && get_site_option('backwpup_cfg_gzlogs') && !is_object($job_object)) {
         //Compress old not compressed logs
         if ($dir = opendir(get_site_option('backwpup_cfg_logfolder'))) {
             $jobids = BackWPup_Option::get_job_ids();
             while (FALSE !== ($file = readdir($dir))) {
                 if (is_writeable(get_site_option('backwpup_cfg_logfolder') . $file) && '.html' == substr($file, -5)) {
                     $compress = new BackWPup_Create_Archive(get_site_option('backwpup_cfg_logfolder') . $file . '.gz');
                     if ($compress->add_file(get_site_option('backwpup_cfg_logfolder') . $file)) {
                         unlink(get_site_option('backwpup_cfg_logfolder') . $file);
                         //change last logfile in jobs
                         foreach ($jobids as $jobid) {
                             $job_logfile = BackWPup_Option::get($jobid, 'logfile');
                             if (!empty($job_logfile) && $job_logfile == get_site_option('backwpup_cfg_logfolder') . $file) {
                                 BackWPup_Option::update($jobid, 'logfile', get_site_option('backwpup_cfg_logfolder') . $file . '.gz');
                             }
                         }
                     }
                     unset($compress);
                 }
             }
             closedir($dir);
         }
     }
     //Jobs cleanings
     if (!is_object($job_object)) {
         //remove restart cron
         wp_clear_scheduled_hook('backwpup_cron', array('id' => 'restart'));
         //temp cleanup
         BackWPup_Job::clean_temp_folder();
     }
     //check scheduling jobs that not found will removed because there are single scheduled
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $jobid) {
             $cron_next = wp_next_scheduled('backwpup_cron', array('id' => $jobid));
             if (!$cron_next || $cron_next < time()) {
                 wp_unschedule_event($cron_next, 'backwpup_cron', array('id' => $jobid));
                 $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($jobid, 'cron'));
                 wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $jobid));
             }
         }
     }
 }
示例#6
0
 /**
  *
  * Called on job stop makes cleanup and terminates the script
  *
  */
 private function end()
 {
     $this->step_working = 'END';
     $this->substeps_todo = 1;
     $abort = FALSE;
     if (!file_exists(BackWPup::get_plugin_data('running_file'))) {
         if (!$this->user_abort) {
             $abort = TRUE;
         }
         $this->log(__('Aborted by user!', 'backwpup'), E_USER_ERROR);
     }
     //delete old logs
     if (get_site_option('backwpup_cfg_maxlogs')) {
         $log_file_list = array();
         $log_folder = trailingslashit(dirname($this->logfile));
         if (is_readable($log_folder) && ($dir = opendir($log_folder))) {
             //make file list
             while (($file = readdir($dir)) !== FALSE) {
                 if (strpos($file, 'backwpup_log_') == 0 && FALSE !== strpos($file, '.html')) {
                     $log_file_list[filemtime($log_folder . $file)] = $file;
                 }
             }
             closedir($dir);
         }
         if (sizeof($log_file_list) > 0) {
             krsort($log_file_list, SORT_NUMERIC);
             $num_delete_files = 0;
             $i = -1;
             foreach ($log_file_list as $log_file) {
                 $i++;
                 if ($i < get_site_option('backwpup_cfg_maxlogs')) {
                     continue;
                 }
                 unlink($log_folder . $log_file);
                 $num_delete_files++;
             }
             if ($num_delete_files > 0) {
                 $this->log(sprintf(_n('One old log deleted', '%d old logs deleted', $num_delete_files, 'backwpup'), $num_delete_files));
             }
         }
     }
     //Display job working time
     if ($this->errors > 0) {
         $this->log(sprintf(__('Job has ended with errors in %s seconds. You must resolve the errors for correct execution.', 'backwpup'), current_time('timestamp') - $this->start_time), E_USER_ERROR);
     } elseif ($this->warnings > 0) {
         $this->log(sprintf(__('Job finished with warnings in %s seconds. Please resolve them for correct execution.', 'backwpup'), current_time('timestamp') - $this->start_time), E_USER_WARNING);
     } else {
         $this->log(sprintf(__('Job done in %s seconds.', 'backwpup'), current_time('timestamp') - $this->start_time, E_USER_NOTICE));
     }
     //Update job options
     if (!empty($this->job['jobid'])) {
         $this->job['lastruntime'] = current_time('timestamp') - $this->start_time;
         BackWPup_Option::update($this->job['jobid'], 'lastruntime', $this->job['lastruntime']);
     }
     //write header info
     if (!empty($this->logfile)) {
         if ($fd = fopen($this->logfile, 'r+')) {
             $filepos = ftell($fd);
             $found = 0;
             while (!feof($fd)) {
                 $line = fgets($fd);
                 if (stripos($line, '<meta name="backwpup_jobruntime"') !== FALSE) {
                     fseek($fd, $filepos);
                     fwrite($fd, str_pad('<meta name="backwpup_jobruntime" content="' . $this->job['lastruntime'] . '" />', 100) . PHP_EOL);
                     $found++;
                 }
                 if (stripos($line, '<meta name="backwpup_backupfilesize"') !== FALSE) {
                     fseek($fd, $filepos);
                     fwrite($fd, str_pad('<meta name="backwpup_backupfilesize" content="' . $this->backup_filesize . '" />', 100) . PHP_EOL);
                     $found++;
                 }
                 if ($found >= 2) {
                     break;
                 }
                 $filepos = ftell($fd);
             }
             fclose($fd);
         }
         //logfile end
         file_put_contents($this->logfile, "</body>" . PHP_EOL . "</html>", FILE_APPEND);
         //Send mail with log
         $sendmail = FALSE;
         if ($this->errors > 0 && !empty($this->job['mailerroronly']) && !empty($this->job['mailaddresslog'])) {
             $sendmail = TRUE;
         }
         if (empty($this->job['mailerroronly']) && !empty($this->job['mailaddresslog'])) {
             $sendmail = TRUE;
         }
         if ($sendmail) {
             //special subject
             $status = __('SUCCESSFUL', 'backwpup');
             $priority = 3;
             //Normal
             if ($this->warnings > 0) {
                 $status = __('WARNING', 'backwpup');
                 $priority = 2;
                 //High
             }
             if ($this->errors > 0) {
                 $status = __('ERROR', 'backwpup');
                 $priority = 1;
                 //Highest
             }
             $subject = sprintf(__('[%3$s] BackWPup log %1$s: %2$s', 'backwpup'), date_i18n('d-M-Y H:i', $this->start_time, TRUE), esc_attr($this->job['name']), $status);
             $headers = array();
             $headers[] = 'Content-Type: text/html; charset=' . get_bloginfo('charset');
             /* $headers[] = 'X-Priority: ' . $priority; */
             // Priority not working with header setting
             if (!empty($this->job['mailaddresssenderlog'])) {
                 if (FALSE === ($start_mail = strpos($this->job['mailaddresssenderlog'], '<'))) {
                     if (FALSE === strpos($this->job['mailaddresssenderlog'], '@')) {
                         $this->job['mailaddresssenderlog'] = '"' . str_replace(array('<', '>', '@'), '', $this->job['mailaddresssenderlog']) . '" <' . get_bloginfo('admin_email') . '>';
                     }
                 } elseif (FALSE === strpos($this->job['mailaddresssenderlog'], '>', $start_mail)) {
                     $this->job['mailaddresssenderlog'] = '"' . str_replace(array('<', '>', '@'), '', substr($this->job['mailaddresssenderlog'], 0, $start_mail)) . '" <' . get_bloginfo('admin_email') . '>';
                 }
                 $headers[] = 'From: ' . $this->job['mailaddresssenderlog'];
             }
             wp_mail($this->job['mailaddresslog'], $subject, file_get_contents($this->logfile), $headers);
         }
     }
     //set done
     $this->substeps_done = 1;
     $this->steps_done[] = 'END';
     //clean up temp
     self::clean_temp_folder();
     //remove shutdown action
     remove_action('shutdown', array($this, 'shutdown'));
     restore_exception_handler();
     restore_error_handler();
     if (!empty($this->run['PHP'])) {
         @ini_set('log_errors', $this->run['PHP']['INI']['LOG_ERRORS']);
         @ini_set('error_log', $this->run['PHP']['INI']['ERROR_LOG']);
         @ini_set('display_errors', $this->run['PHP']['INI']['DISPLAY_ERRORS']);
         @ini_set('html_errors', $this->run['PHP']['INI']['HTML_ERRORS']);
         @ini_set('zlib.output_compression', $this->run['PHP']['INI']['ZLIB_OUTPUT_COMPRESSION']);
         @ini_set('implicit_flush', $this->run['PHP']['INI']['IMPLICIT_FLUSH']);
         @ini_set('error_reporting', $this->run['PHP']['INI']['ERROR_REPORTING']);
         @ini_set('report_memleaks', $this->run['PHP']['INI']['REPORT_MEMLEAKS']);
         if (!empty($this->run['PHP']['ENV']['TEMPDIR'])) {
             @putenv('TMPDIR=' . $this->run['PHP']['ENV']['TEMPDIR']);
         }
     }
     BackWPup_Cron::check_cleanup();
     if ($abort) {
         exit;
     }
 }
示例#7
0
 /**
  * Creates DB und updates settings
  */
 public static function activate()
 {
     //do upgrade from version 2.x
     if (!get_site_option('backwpup_version') && get_option('backwpup') && get_option('backwpup_jobs')) {
         self::upgrade_from_version_two();
     }
     //changes for 3.0.14
     remove_all_filters('default_site_option_backwpup_cfg_logfolder', 10);
     if (get_site_option('backwpup_version') != BackWPup::get_plugin_data('version') && version_compare('3.0.13', get_site_option('backwpup_version'), '>') && version_compare('3.0', get_site_option('backwpup_version'), '<')) {
         $upload_dir = wp_upload_dir();
         $logfolder = get_site_option('backwpup_cfg_logfolder');
         if (empty($logfolder)) {
             $old_log_folder = trailingslashit(str_replace('\\', '/', $upload_dir['basedir'])) . 'backwpup-' . substr(md5(md5(SECURE_AUTH_KEY)), 9, 5) . '-logs/';
             update_site_option('backwpup_cfg_logfolder', $old_log_folder);
         }
     }
     //create new option on not ms blogs
     if (!is_multisite() && !get_option('backwpup_jobs', FALSE)) {
         add_option('backwpup_jobs', array(), NULL, 'no');
     }
     //remove old schedule
     wp_clear_scheduled_hook('backwpup_cron');
     //make new schedule
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($id, 'cron'));
             wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $id));
         }
     }
     //add check Cleanup schedule
     wp_clear_scheduled_hook('backwpup_check_cleanup');
     wp_schedule_event(time(), 'twicedaily', 'backwpup_check_cleanup');
     //remove old roles pre v.3.0.9
     $role = get_role('administrator');
     $role->remove_cap('backwpup');
     $role->remove_cap('backwpup_jobs');
     $role->remove_cap('backwpup_jobs_edit');
     $role->remove_cap('backwpup_jobs_start');
     $role->remove_cap('backwpup_backups');
     $role->remove_cap('backwpup_backups_download');
     $role->remove_cap('backwpup_backups_delete');
     $role->remove_cap('backwpup_logs');
     $role->remove_cap('backwpup_logs_delete');
     $role->remove_cap('backwpup_settings');
     //add/overwrite roles
     add_role('backwpup_admin', __('BackWPup Admin', 'backwpup'), array('backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => TRUE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => TRUE));
     add_role('backwpup_check', __('BackWPup jobs checker', 'backwpup'), array('backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => FALSE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => FALSE, 'backwpup_backups_delete' => FALSE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => FALSE, 'backwpup_settings' => FALSE));
     add_role('backwpup_helper', __('BackWPup jobs helper', 'backwpup'), array('backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => FALSE));
     //add role to admin user if no one
     $users_backwpup = get_users(array('blog_id' => 1, 'role' => 'backwpup_admin'));
     if (empty($users_backwpup)) {
         /* @var WP_User $user */
         $users = get_users(array('blog_id' => 1, 'role' => 'administrator', 'fields' => 'all_with_meta'));
         foreach ($users as $user) {
             $user->add_role('backwpup_admin');
         }
     }
     //update version
     update_site_option('backwpup_version', BackWPup::get_plugin_data('Version'));
 }