log_ident = (defined('UPDRAFTPLUS_LOG_IDENT')) ? UPDRAFTPLUS_LOG_IDENT : 'updraftplus'; $this->log_facility = (defined('UPDRAFTPLUS_LOG_FACILITY')) ? UPDRAFTPLUS_LOG_FACILITY : LOG_USER; } /** * Runs upon the WordPress action 'init' */ public function init() { if (!class_exists('UpdraftPlus_Options')) return; if (!UpdraftPlus_Options::get_updraft_option('updraft_log_syslog', false) || !function_exists('openlog') || !function_exists('syslog')) return; if (false !== ($this->syslog = openlog($this->log_ident, LOG_ODELAY|LOG_PID, $this->log_facility))) add_filter('updraftplus_logline', array($this, 'logline'), 10, 3); } public function showbackup_date($date, $backup, $jobdata, $key, $simple_format) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. if (!is_array($backup) || empty($backup['label'])) return $date; if ($simple_format) { return $date.' - '.htmlspecialchars($backup['label']); } else { return $date.''.htmlspecialchars($backup['label']).''; } } /** * Runs upon the WP filter updraft_backupnow_modal_afteroptions * * @param String $ret - unfiltered value to return * @param String $prefix - prefix to use * * @return String */ public function backupnow_modal_afteroptions($ret, $prefix) { $ret .= '

'; return $ret; } /** * Adjust the backup-now options based on the incoming request * * @param Array $options - the current options * @param Array $request - the incoming request * * @return Array - the filtered options */ public function backupnow_options($options, $request) { if (!is_array($options)) return $options; // See: https://trello.com/c/NH83ZCnj/494 if (!empty($request['backupnow_label']) && is_string($request['backupnow_label'])) $options['label'] = substr($request['backupnow_label'], 0, 40); return $options; } public function logline($line, $nonce, $level) { // See https://php.net/manual/en/function.syslog.php for descriptions of the log level meanings if ('error' == $level) { $pri = LOG_WARNING; } elseif ('warning' == $level) { $pri = LOG_NOTICE; } else { $pri = LOG_INFO; } @syslog($pri, "($nonce) $line");// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Silenced to suppress errors that may arise because of the function. return $line; } public function final_backup_history($history) { $this->history = $history; } public function updraft_report_attachments($attachments) { // Always attach the log file global $updraftplus; $attachments[0] = $updraftplus->logfile_name; return $attachments; } /** * TODO: Jobdata is passed in, rather than live, because the live jobdata may have moved on from the time which the point should reflectg (e.g. an incremental backup was subsequently started) * * @param string $report * @param string $final_message * @param string $contains * @param string $errors * @param string $warnings * @param array $jobdata * @return string */ public function updraft_report_body($report, $final_message, $contains, $errors, $warnings, $jobdata) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. global $updraftplus; $error_count = 0; foreach ($errors as $err) { if ((is_string($err) || is_wp_error($err)) || (is_array($err) && 'error' == $err['level'])) { $error_count++; } } $warning_count = count($warnings); $history = $this->history; $debug = UpdraftPlus_Options::get_updraft_option('updraft_debug_mode'); $errors_and_warns = sprintf(__('%d errors, %d warnings', 'updraftplus'), $error_count, $warning_count); $file_entities = $updraftplus->get_backupable_file_entities(true, true); $backup_time = empty($jobdata['incremental_run_start']) ? $jobdata['backup_time'] : $jobdata['incremental_run_start']; $date = get_date_from_gmt(gmdate('Y-m-d H:i:s', $backup_time), 'Y-m-d H:i'); $time_taken = time() - $backup_time; $hrs = floor($time_taken/3600); $mins = floor(($time_taken-3600*$hrs)/60); $secs = $time_taken - 3600*$hrs - 60*$mins; $services = empty($jobdata['service']) ? array('none') : $jobdata['service']; if (!is_array($services)) $services = array('none'); $time_taken = sprintf(__("%d hours, %d minutes, %d seconds", 'updraftplus'), $hrs, $mins, $secs); ob_start(); ?>

UpdraftPlus '.esc_html($updraftplus->version)); ?>

do_notice(false, 'report', false); $backup_type = __('Manual backup began:', 'updraftplus'); if (!empty($jobdata['is_scheduled_backup'])) $backup_type = __('Scheduled backup began:', 'updraftplus'); if (!empty($jobdata['is_autobackup'])) $backup_type = __('Automatic backup began:', 'updraftplus'); if ('incremental' === $jobdata['job_type']) $backup_type = __('Incremental backup began:', 'updraftplus'); ?>
error_count() > 0) { echo '

'.esc_html__('Errors', 'updraftplus')."

\n\n"; } if (is_array($warnings) && count($warnings) >0) { echo '

'.esc_html__('Warnings', 'updraftplus')."

\n\n"; echo '

'.esc_html(__('Note that warning messages are advisory - the backup process does not stop for them.', 'updraftplus').' '.__('Instead, they provide information that you might find useful, or that may indicate the source of a problem if the backup did not succeed.', 'updraftplus')).'

'; } ?>

backup_methods[$serv])) { $show_services .= ($show_services) ? ', '.$updraftplus->backup_methods[$serv] : $updraftplus->backup_methods[$serv]; } else { $show_services .= ($show_services) ? ', '.$serv : $serv; } if (isset($jobdata['remotestorage_extrainfo']) && !empty($jobdata['remotestorage_extrainfo'][$serv])) { $show_services .= ' ('.$jobdata['remotestorage_extrainfo'][$serv]['pretty'].')'; } } } if ('' == $show_services && $add_none) $show_services .= __('None', 'updraftplus'); echo wp_kses_post($show_services)."

\n\n"; $checksums = $updraftplus->which_checksums(); if (!empty($file_entities)) { foreach ($file_entities as $entity => $info) { echo $updraftplus->printfile($info['description'], $history, $entity, $checksums, $jobdata);// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- needs to be presented in html } } if (!empty($history)) { foreach ($history as $key => $val) { if ('db' == strtolower(substr($key, 0, 2)) && '-size' != substr($key, -5, 5) && 'incremental' !== $jobdata['job_type']) { echo $updraftplus->printfile(__('Database', 'updraftplus'), $history, $key, $checksums, $jobdata);// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- needs to be presented in html } } } echo '

'.esc_html__('The log file has been attached to this email.', 'updraftplus')."

\n\n"; if ($debug) { echo '

'.esc_html__('Debugging information', 'updraftplus')."

\n
";
	print esc_html(chunk_split(base64_encode(serialize($jobdata)), 76, "\n"));
	print "\n";
	print esc_html(chunk_split(base64_encode(serialize($history)), 76, "\n"));
	echo "
"; } $this->html = ob_get_contents(); ob_end_clean(); // Lower priority: get there before other plugins which apply templates add_filter('wp_mail_content_type', array($this, 'wp_mail_content_type'), 8); $report_body = $this->html; return str_replace("\n", "\r\n", strip_tags(preg_replace('#\]*)\>.*\#', '', $report_body))); } public function wp_mail_content_type($content_type) { // Only convert if the message is text/plain and the template is ok if ('text/plain' == $content_type && !empty($this->html)) { static $added_phpmailer_init_action; if (empty($added_phpmailer_init_action)) { $added_phpmailer_init_action = true; add_action('phpmailer_init', array($this, 'phpmailer_init')); } return 'text/html'; } return $content_type; } public function phpmailer_init($phpmailer) { if (empty($this->html)) return; $phpmailer->AltBody = wp_specialchars_decode($phpmailer->Body, ENT_QUOTES); $phpmailer->Body = $this->html; } public function report_finished() { global $phpmailer; remove_filter('wp_mail_content_type', array($this, 'wp_mail_content_type'), 8); remove_action('phpmail_init', array($this, 'phpmailer_init')); if (empty($this->html)) return; if (is_object($phpmailer) && (is_a($phpmailer, 'PHPMailer') || is_a($phpmailer, 'PHPMailer\PHPMailer\PHPMailer'))) { // $phpmailer->AltBody = ''; // $phpmailer->Body = ''; // $phpmailer->ContentType = 'text/plain'; // Best just to force WP to get the whole thing again from the beginning $phpmailer = null; } unset($this->html); } public function updraft_report_subject($subject, $error_count, $warning_count) { $count = 0; if ($error_count > 0) { $count = $error_count; } elseif ($warning_count >0) { $count = $warning_count; } if ($count) $subject .= sprintf(' (%s)', $count); return $subject; } public function updraft_report_sendto($send, $addr, $error_count, $warning_count, $ind) { if (null === $this->emails) { $this->emails = UpdraftPlus_Options::get_updraft_option('updraft_email', array()); if (is_string($this->emails)) $this->emails = array($this->emails); } if (null === $this->warningsonly) { $this->warningsonly = UpdraftPlus_Options::get_updraft_option('updraft_report_warningsonly', array()); if (!is_array($this->warningsonly)) $this->warningsonly = array(); } if (0 == $error_count + $warning_count && isset($this->emails[$ind]) && !empty($this->warningsonly[$ind])) { $send = false; global $updraftplus; $updraftplus->log("No report will be sent to this address, as it is configured to receive them only when there are errors or warnings: ".substr($addr, 0, 5).'...'); } return $send; } /** * Function for filter updraftplus_email_backup * * @param boolean $doit filter value of updraftplus_email_backup * @param string $addr email address * @param integer $ind index of report box * @param string $type backup entity types * @return boolean filtered value */ public function email_backup($doit, $addr, $ind, $type) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. $wholebackup = UpdraftPlus_Options::get_updraft_option('updraft_report_wholebackup', null); $dbbackup = UpdraftPlus_Options::get_updraft_option('updraft_report_dbbackup', null); if (is_array($wholebackup) && !empty($wholebackup[$ind]) && empty($dbbackup[$ind])) { return true; } if ('db' == strtolower(substr($type, 0, 2)) && is_array($dbbackup) && !empty($dbbackup[$ind])) { return true; } return false; } /** * Function for filter updraftplus_backup_skip_log_message * * @param string $log_message default log message of updraftplus_backup_skip_log_message filter * @param string $addr email address * @param integer $ind index of report box * @param string $descrip_type backup entity types * @return string log message */ public function backup_skip_log_message($log_message, $addr, $ind, $descrip_type) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. $wholebackup = UpdraftPlus_Options::get_updraft_option('updraft_report_wholebackup', null); if (!is_array($wholebackup) || empty($wholebackup[$ind])) { return 'You have chosen to not send the backup via the email remote storage option for '.$addr.'. '.$descrip_type.' will not be sent.'; } else { return 'You have chosen to only send the database via the email remote storage option for '.$addr.'. '.$descrip_type.' will not be sent.'; } } public function email_whichaddresses() { return __('Use the "Reporting" section to configure the email addresses to be used.', 'updraftplus'); } public function admin_footer() { ?> '.__('Send reports', 'updraftplus').': '; // Could be multiple (separated by commas) $updraft_email = UpdraftPlus_Options::get_updraft_option('updraft_email'); $updraft_report_warningsonly = UpdraftPlus_Options::get_updraft_option('updraft_report_warningsonly'); $updraft_report_wholebackup = UpdraftPlus_Options::get_updraft_option('updraft_report_wholebackup'); $updraft_report_dbbackup = UpdraftPlus_Options::get_updraft_option('updraft_report_dbbackup'); if (is_string($updraft_email)) { $utmp = $updraft_email; $updraft_email = array(); $updraft_report_warningsonly = array(); $updraft_report_wholebackup = array(); foreach (explode(',', $utmp) as $email) { // Whole backup only takes effect if 'Email' is chosen as a storage option $updraft_email[] = $email; $updraft_report_warningsonly[] = false; $updraft_report_wholebackup[] = true; } } elseif (!is_array($updraft_email)) { $updraft_email = array(); $updraft_report_warningsonly = array(); $updraft_report_wholebackup = array(); } $out .= '

'.__('Enter addresses here to have a report sent to them when a backup job finishes.', 'updraftplus').'

'; $ind = 0; foreach ($updraft_email as $ikey => $destination) { $warningsonly = empty($updraft_report_warningsonly[$ikey]) ? false : true; $wholebackup = empty($updraft_report_wholebackup[$ikey]) ? false : true; $dbbackup = empty($updraft_report_dbbackup[$ikey]) ? false : true; if (!empty($destination)) { $ind++; $out .= $this->report_box_generator($destination, $ind, $warningsonly, $wholebackup, $dbbackup); } } if (0 === $ind) $out .= $this->report_box_generator('', 0, false, false, false); $out .= '

'.__('Add another address...', 'updraftplus').'

'; $out .= ' '; return $out; } /** * Renders reporting expert settings */ public function configprint_expertoptions() { ?> : >
'; $out .= ''; $out .= ''; $out .= ''; $out .= '
'; $out .= '
'; $out .= ''; return $out; } /** * Generate a downloadable backup link * * @param String $link the unfiltered backup file name in plain text format * @param String $entity the backup entity (db, uploads, plugins, etc..) * @param Integer $index the index number of the backup file * @param Array $jobdata the jobdata for the currently running backup * @return String the filtered backup file name with its HTML link text attached */ public function generate_downloadable_file_link($link, $entity, $index, $jobdata) { global $updraftplus; $jobdata['service'] = empty($jobdata['service']) ? array() : $updraftplus->get_canonical_service_list($jobdata['service']); // I was thinking not to check the the nonce first, but at this point I believe we should only generate a valid link $download_link = is_array($jobdata) && !empty($jobdata['backup_time']) && !empty($this->file_nonce) && empty($jobdata['service']); if ($download_link) { $link = ''.$link.''; } return $link; } }