コード例 #1
0
 /**
  *
  */
 function prepare_items()
 {
     $this->job_types = BackWPup::get_job_types();
     $per_page = $this->get_items_per_page('backwpuplogs_per_page');
     if (empty($per_page) || $per_page < 1) {
         $per_page = 20;
     }
     //load logs
     $logfiles = array();
     if (is_readable($this->log_folder) && ($dir = opendir($this->log_folder))) {
         while (($file = readdir($dir)) !== FALSE) {
             $log_file = $this->log_folder . '/' . $file;
             if (is_file($log_file) && is_readable($log_file) && FALSE !== strpos($file, 'backwpup_log_') && FALSE !== strpos($file, '.html')) {
                 $logfiles[] = $file;
             }
         }
         closedir($dir);
     }
     //ordering
     $order = isset($_GET['order']) ? $_GET['order'] : 'desc';
     $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'time';
     if ($orderby == 'time') {
         if ($order == 'asc') {
             sort($logfiles);
         } else {
             rsort($logfiles);
         }
     }
     //by page
     $start = intval(($this->get_pagenum() - 1) * $per_page);
     $end = $start + $per_page;
     if ($end > count($logfiles)) {
         $end = count($logfiles);
     }
     $this->items = array();
     $i = -1;
     foreach ($logfiles as $mtime => $logfile) {
         $i++;
         if ($i < $start) {
             continue;
         }
         if ($i >= $end) {
             break;
         }
         $this->items[$mtime] = BackWPup_Job::read_logheader($this->log_folder . '/' . $logfile);
         $this->items[$mtime]['file'] = $logfile;
     }
     $this->set_pagination_args(array('total_items' => count($logfiles), 'per_page' => $per_page, 'orderby' => $orderby, 'order' => $order));
 }
コード例 #2
0
    /**
     * Displaying last logs
     */
    private static function mb_last_logs()
    {
        if (!current_user_can('backwpup_logs')) {
            return;
        }
        ?>
		<table class="wp-list-table widefat" cellspacing="0">
			<caption><?php 
        _e('Last logs', 'backwpup');
        ?>
</caption>
			<thead>
			<tr><th style="width:30%"><?php 
        _e('Time', 'backwpup');
        ?>
</th><th style="width:55%"><?php 
        _e('Job', 'backwpup');
        ?>
</th><th style="width:20%"><?php 
        _e('Result', 'backwpup');
        ?>
</th></tr>
			</thead>
			<?php 
        //get log files
        $logfiles = array();
        $log_folder = get_site_option('backwpup_cfg_logfolder');
        $log_folder = BackWPup_File::get_absolute_path($log_folder);
        if (is_readable($log_folder) && ($dir = opendir($log_folder))) {
            while (($file = readdir($dir)) !== FALSE) {
                if (is_readable($log_folder . $file) && is_file($log_folder . $file) && FALSE !== strpos($file, 'backwpup_log_') && FALSE !== strpos($file, '.html')) {
                    $logfiles[filemtime($log_folder . $file)] = $file;
                }
            }
            closedir($dir);
            krsort($logfiles, SORT_NUMERIC);
        }
        if (count($logfiles) > 0) {
            $count = 0;
            $alternate = TRUE;
            foreach ($logfiles as $logfile) {
                $logdata = BackWPup_Job::read_logheader($log_folder . $logfile);
                if (!$alternate) {
                    echo '<tr>';
                    $alternate = TRUE;
                } else {
                    echo '<tr class="alternate">';
                    $alternate = FALSE;
                }
                echo '<td>' . sprintf(__('%1$s at %2$s', 'backwpup'), date_i18n(get_option('date_format'), $logdata['logtime']), date_i18n(get_option('time_format'), $logdata['logtime'])) . '</td>';
                echo '<td><a class="thickbox" href="' . admin_url('admin-ajax.php') . '?&action=backwpup_view_log&logfile=' . basename($logfile) . '&_ajax_nonce=' . wp_create_nonce('view-logs') . '&amp;TB_iframe=true&amp;width=640&amp;height=440" title="' . esc_attr(basename($logfile)) . '">' . $logdata['name'] . '</i></a></td>';
                echo '<td>';
                if ($logdata['errors'] > 0) {
                    printf('<span style="color:red;font-weight:bold;">' . _n("%d ERROR", "%d ERRORS", $logdata['errors'], 'backwpup') . '</span><br />', $logdata['errors']);
                }
                if ($logdata['warnings'] > 0) {
                    printf('<span style="color:#e66f00;font-weight:bold;">' . _n("%d WARNING", "%d WARNINGS", $logdata['warnings'], 'backwpup') . '</span><br />', $logdata['warnings']);
                }
                if ($logdata['errors'] == 0 && $logdata['warnings'] == 0) {
                    echo '<span style="color:green;font-weight:bold;">' . __('OK', 'backwpup') . '</span>';
                }
                echo '</td></tr>';
                $count++;
                if ($count >= 5) {
                    break;
                }
            }
        } else {
            echo '<tr><td colspan="3">' . __('none', 'backwpup') . '</td></tr>';
        }
        ?>
		</table>
		<?php 
    }
コード例 #3
0
ファイル: class-page-jobs.php プロジェクト: skinnard/FTL-2
 /**
  *
  * Function to generate json data
  *
  */
 public static function ajax_working()
 {
     check_ajax_referer('backwpupworking_ajax_nonce');
     if (!current_user_can('backwpup_jobs_start')) {
         die('-1');
     }
     $log_folder = get_site_option('backwpup_cfg_logfolder');
     $log_folder = BackWPup_File::get_absolute_path($log_folder);
     $logfile = isset($_GET['logfile']) ? $log_folder . basename(trim($_GET['logfile'])) : NULL;
     $logpos = isset($_GET['logpos']) ? absint($_GET['logpos']) : 0;
     $restart_url = '';
     //check if logfile renamed
     if (file_exists($logfile . '.gz')) {
         $logfile .= '.gz';
     }
     if (!is_readable($logfile) || strstr($_GET['logfile'], 'backwpup_log_') === false) {
         die('0');
     }
     $job_object = BackWPup_Job::get_working_data();
     $done = 0;
     if (is_object($job_object)) {
         $warnings = $job_object->warnings;
         $errors = $job_object->errors;
         $step_percent = $job_object->step_percent;
         $substep_percent = $job_object->substep_percent;
         $runtime = current_time('timestamp') - $job_object->start_time;
         $onstep = $job_object->steps_data[$job_object->step_working]['NAME'];
         $lastmsg = $job_object->lastmsg;
         $lasterrormsg = $job_object->lasterrormsg;
     } else {
         $logheader = BackWPup_Job::read_logheader($logfile);
         $warnings = $logheader['warnings'];
         $runtime = $logheader['runtime'];
         $errors = $logheader['errors'];
         $step_percent = 100;
         $substep_percent = 100;
         $onstep = '<div class="backwpup-message backwpup-info"><p>' . esc_html__('Job completed', 'backwpup') . '</p></div>';
         if ($errors > 0) {
             $lastmsg = '<div class="error"><p>' . esc_html__('ERROR:', 'backwpup') . ' ' . sprintf(esc_html__('Job has ended with errors in %s seconds. You must resolve the errors for correct execution.', 'backwpup'), $logheader['runtime']) . '</p></div>';
         } elseif ($warnings > 0) {
             $lastmsg = '<div class="backwpup-message backwpup-warning"><p>' . esc_html__('WARNING:', 'backwpup') . ' ' . sprintf(esc_html__('Job has done with warnings in %s seconds. Please resolve them for correct execution.', 'backwpup'), $logheader['runtime']) . '</p></div>';
         } else {
             $lastmsg = '<div class="updated"><p>' . sprintf(esc_html__('Job done in %s seconds.', 'backwpup'), $logheader['runtime']) . '</p></div>';
         }
         $lasterrormsg = '';
         $done = 1;
     }
     if ('.gz' == substr($logfile, -3)) {
         $logfiledata = file_get_contents('compress.zlib://' . $logfile, FALSE, NULL, $logpos);
     } else {
         $logfiledata = file_get_contents($logfile, FALSE, NULL, $logpos);
     }
     preg_match('/<body[^>]*>/si', $logfiledata, $match);
     if (!empty($match[0])) {
         $startpos = strpos($logfiledata, $match[0]) + strlen($match[0]);
     } else {
         $startpos = 0;
     }
     $endpos = stripos($logfiledata, '</body>');
     if (FALSE === $endpos) {
         $endpos = strlen($logfiledata);
     }
     $length = strlen($logfiledata) - (strlen($logfiledata) - $endpos) - $startpos;
     //check if restart must done on ALTERNATE_WP_CRON
     if (is_object($job_object) && defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
         $restart = BackWPup_Job::get_jobrun_url('restartalt');
         if ($job_object->pid === 0 && $job_object->uniqid === '') {
             $restart_url = $restart['url'];
         }
         $last_update = microtime(TRUE) - $job_object->timestamp_last_update;
         if (empty($job_object->pid) && $last_update > 10) {
             $restart_url = $restart['url'];
         }
     }
     wp_send_json(array('log_pos' => strlen($logfiledata) + $logpos, 'log_text' => substr($logfiledata, $startpos, $length), 'warning_count' => $warnings, 'error_count' => $errors, 'running_time' => $runtime, 'step_percent' => $step_percent, 'on_step' => $onstep, 'last_msg' => $lastmsg, 'last_error_msg' => $lasterrormsg, 'sub_step_percent' => $substep_percent, 'restart_url' => $restart_url, 'job_done' => $done));
 }
コード例 #4
0
ファイル: class-page-jobs.php プロジェクト: kirkov/backwpup
 /**
  *
  * Function to generate json data
  *
  */
 public static function ajax_working()
 {
     check_ajax_referer('backwpupworking_ajax_nonce');
     $logfile = isset($_GET['logfile']) ? get_site_option('backwpup_cfg_logfolder') . trim($_GET['logfile']) : NULL;
     $logpos = isset($_GET['logpos']) ? (int) $_GET['logpos'] : 0;
     //check if logfile renamed
     if (file_exists($logfile . '.gz')) {
         $logfile .= '.gz';
     }
     if (!is_readable($logfile)) {
         die('0');
     }
     $job_object = BackWPup_Job::get_working_data();
     $done = 0;
     if (is_object($job_object)) {
         $warnings = $job_object->warnings;
         $errors = $job_object->errors;
         $step_percent = $job_object->step_percent;
         $substep_percent = $job_object->substep_percent;
         $runtime = current_time('timestamp') - $job_object->start_time;
         $onstep = $job_object->steps_data[$job_object->step_working]['NAME'];
         $lastmsg = $job_object->lastmsg;
         $lasterrormsg = $job_object->lasterrormsg;
     } else {
         $logheader = BackWPup_Job::read_logheader($logfile);
         $warnings = $logheader['warnings'];
         $runtime = $logheader['runtime'];
         $errors = $logheader['errors'];
         $step_percent = 100;
         $substep_percent = 100;
         $onstep = '<div class="backwpup-message backwpup-info"><p>' . __('Job completed', 'backwpup') . '</p></div>';
         if ($errors > 0) {
             $lastmsg = '<div class="error"><p>' . __('ERROR:', 'backwpup') . ' ' . sprintf(__('Job has ended with errors in %s seconds. You must resolve the errors for correct execution.', 'backwpup'), $logheader['runtime']) . '</p></div>';
         } elseif ($warnings > 0) {
             $lastmsg = '<div class="backwpup-message backwpup-warning"><p>' . __('WARNING:', 'backwpup') . ' ' . sprintf(__('Job has done with warnings in %s seconds. Please resolve them for correct execution.', 'backwpup'), $logheader['runtime']) . '</p></div>';
         } else {
             $lastmsg = '<div class="updated"><p>' . sprintf(__('Job done in %s seconds.', 'backwpup'), $logheader['runtime']) . '</p></div>';
         }
         $lasterrormsg = '';
         $done = 1;
     }
     if ('.gz' == substr($logfile, -3)) {
         $logfiledata = file_get_contents('compress.zlib://' . $logfile, FALSE, NULL, $logpos);
     } else {
         $logfiledata = file_get_contents($logfile, FALSE, NULL, $logpos);
     }
     preg_match('/<body[^>]*>/si', $logfiledata, $match);
     if (!empty($match[0])) {
         $startpos = strpos($logfiledata, $match[0]) + strlen($match[0]);
     } else {
         $startpos = 0;
     }
     $endpos = stripos($logfiledata, '</body>');
     if (FALSE === $endpos) {
         $endpos = strlen($logfiledata);
     }
     $length = strlen($logfiledata) - (strlen($logfiledata) - $endpos) - $startpos;
     wp_send_json(array('log_pos' => strlen($logfiledata) + $logpos, 'log_text' => substr($logfiledata, $startpos, $length), 'warning_count' => $warnings, 'error_count' => $errors, 'running_time' => $runtime, 'step_percent' => $step_percent, 'on_step' => $onstep, 'last_msg' => $lastmsg, 'last_error_msg' => $lasterrormsg, 'sub_step_percent' => $substep_percent, 'job_done' => $done));
 }