function backwpup_jobedit_metabox_backupfile($jobvalue) { ?> <b><?php _e('File Prefix:', 'backwpup'); ?> </b><br /> <input name="fileprefix" type="text" value="<?php echo $jobvalue['fileprefix']; ?> " class="large-text" /><br /> <b><?php _e('File Formart:', 'backwpup'); ?> </b><br /> <?php if (function_exists('gzopen') or class_exists('ZipArchive')) { echo '<input class="radio" type="radio"' . checked('.zip', $jobvalue['fileformart'], false) . ' name="fileformart" value=".zip" />' . __('Zip', 'backwpup') . '<br />'; } else { echo '<input class="radio" type="radio"' . checked('.zip', $jobvalue['fileformart'], false) . ' name="fileformart" value=".zip" disabled="disabled" />' . __('Zip', 'backwpup') . '<br />'; } echo '<input class="radio" type="radio"' . checked('.tar', $jobvalue['fileformart'], false) . ' name="fileformart" value=".tar" />' . __('Tar', 'backwpup') . '<br />'; if (function_exists('gzopen')) { echo '<input class="radio" type="radio"' . checked('.tar.gz', $jobvalue['fileformart'], false) . ' name="fileformart" value=".tar.gz" />' . __('Tar GZip', 'backwpup') . '<br />'; } else { echo '<input class="radio" type="radio"' . checked('.tar.gz', $jobvalue['fileformart'], false) . ' name="fileformart" value=".tar.gz" disabled="disabled" />' . __('Tar GZip', 'backwpup') . '<br />'; } if (function_exists('bzopen')) { echo '<input class="radio" type="radio"' . checked('.tar.bz2', $jobvalue['fileformart'], false) . ' name="fileformart" value=".tar.bz2" />' . __('Tar BZip2', 'backwpup') . '<br />'; } else { echo '<input class="radio" type="radio"' . checked('.tar.bz2', $jobvalue['fileformart'], false) . ' name="fileformart" value=".tar.bz2" disabled="disabled" />' . __('Tar BZip2', 'backwpup') . '<br />'; } _e('Preview:', 'backwpup'); echo '<br /><i><span id="backupfileprefix">' . $jobvalue['fileprefix'] . '</span>' . backwpup_date_i18n('Y-m-d_H-i-s') . '<span id="backupfileformart">' . $jobvalue['fileformart'] . '</span></i>'; }
function single_row($logfile, $logdata, $style = '') { list($columns, $hidden, $sortable) = $this->get_column_info(); $r = "<tr id='" . basename($logfile) . "'{$style}>"; foreach ($columns as $column_name => $column_display_name) { $class = "class=\"{$column_name} column-{$column_name}\""; $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = "{$class}{$style}"; switch ($column_name) { case 'cb': $r .= '<th scope="row" class="check-column"><input type="checkbox" name="logfiles[]" value="' . esc_attr(basename($logfile)) . '" /></th>'; break; case 'id': $r .= "<td {$attributes}>" . $logdata['jobid'] . "</td>"; break; case 'type': $r .= "<td {$attributes}>"; $r .= backwpup_backup_types($logdata['type'], false); $r .= "</td>"; break; case 'log': $r .= "<td {$attributes}><strong><a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupworking&logfile=' . $logfile, 'view-log_' . basename($logfile)) . "\" title=\"" . __('View log', 'backwpup') . "\">" . backwpup_date_i18n(get_option('date_format') . " @ " . get_option('time_format'), $logdata['logtime']) . ": <i>" . $logdata['name'] . "</i></a></strong>"; $actions = array(); $actions['view'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupworking&logfile=' . $logfile, 'view-log_' . basename($logfile)) . "\">" . __('View', 'backwpup') . "</a>"; $actions['delete'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpuplogs&action=delete&paged=' . $this->get_pagenum() . '&logfiles[]=' . basename($logfile), 'bulk-logs') . "\" onclick=\"return showNotice.warn();\">" . __('Delete') . "</a>"; $actions['download'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpuplogs&action=download&file=' . $logfile, 'download-backup_' . basename($logfile)) . "\">" . __('Download', 'backwpup') . "</a>"; $r .= $this->row_actions($actions); $r .= "</td>"; break; case 'status': $r .= "<td {$attributes}>"; if ($logdata['errors'] > 0) { $r .= str_replace('%d', $logdata['errors'], '<span style="color:red;font-weight:bold;">' . _n("%d ERROR", "%d ERRORS", $logdata['errors'], 'backwpup') . '</span><br />'); } if ($logdata['warnings'] > 0) { $r .= str_replace('%d', $logdata['warnings'], '<span style="color:#e66f00;font-weight:bold;">' . _n("%d WARNING", "%d WARNINGS", $logdata['warnings'], 'backwpup') . '</span><br />'); } if ($logdata['errors'] == 0 and $logdata['warnings'] == 0) { $r .= '<span style="color:green;font-weight:bold;">' . __('O.K.', 'backwpup') . '</span>'; } $r .= "</td>"; break; case 'size': $r .= "<td {$attributes}>"; if (!empty($logdata['backupfilesize'])) { $r .= backwpup_formatBytes($logdata['backupfilesize']); } else { $r .= __('only Log', 'backwpup'); } $r .= "</td>"; break; case 'runtime': $r .= "<td {$attributes}>"; $r .= $logdata['runtime'] . ' ' . __('sec.', 'backwpup'); $r .= "</td>"; break; } } $r .= '</tr>'; return $r; }
function backwpup_jobstart($jobid = '', $cronstart = false) { global $wpdb, $wp_version; $jobid = (int) trim($jobid); if (empty($jobid) or !is_integer($jobid)) { return false; } //check if a job running if ($infile = backwpup_get_working_file()) { trigger_error(__("A job already running!", "backwpup"), E_USER_WARNING); return false; } //clean var $backwpup_static = array(); $backwpup_working = array(); //get temp dir $backwpup_static['TEMPDIR'] = backwpup_get_temp(); if (!is_writable($backwpup_static['TEMPDIR'])) { trigger_error(__("Temp dir not writeable", "backwpup"), E_USER_ERROR); return false; } else { //clean up old temp files if ($dir = opendir($backwpup_static['TEMPDIR'])) { while (($file = readdir($dir)) !== false) { if (is_readable($backwpup_static['TEMPDIR'] . $file) and is_file($backwpup_static['TEMPDIR'] . $file)) { if ($file != '.' and $file != '..') { unlink($backwpup_static['TEMPDIR'] . $file); } } } closedir($dir); } //create .htaccess for apache and index.php for folder security if (!is_file($backwpup_static['TEMPDIR'] . '.htaccess')) { file_put_contents($backwpup_static['TEMPDIR'] . '.htaccess', "<Files \"*\">\n<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n</Files>"); } if (!is_file($backwpup_static['TEMPDIR'] . 'index.php')) { file_put_contents($backwpup_static['TEMPDIR'] . 'index.php', "\n"); } } //Write running file to prevent dobble runnging file_put_contents($backwpup_static['TEMPDIR'] . '.running', serialize(array('timestamp' => time(), 'JOBID' => $jobid, 'LOGFILE' => '', 'STEPSPERSENT' => 0, 'STEPPERSENT' => 0, 'WORKING' => array('PID' => 0)))); //Set needed WP vars $backwpup_static['WP']['DB_NAME'] = DB_NAME; $backwpup_static['WP']['DB_USER'] = DB_USER; $backwpup_static['WP']['DB_PASSWORD'] = DB_PASSWORD; $backwpup_static['WP']['DB_HOST'] = DB_HOST; $backwpup_static['WP']['DB_CHARSET'] = DB_CHARSET; $backwpup_static['WP']['DB_COLLATE'] = DB_COLLATE; $backwpup_static['WP']['OPTIONS_TABLE'] = $wpdb->options; $backwpup_static['WP']['TABLE_PREFIX'] = $wpdb->prefix; $backwpup_static['WP']['BLOGNAME'] = get_bloginfo('name'); if (defined('WP_SITEURL')) { $backwpup_static['WP']['SITEURL'] = trailingslashit(WP_SITEURL); } else { $backwpup_static['WP']['SITEURL'] = trailingslashit(get_option('siteurl')); } $backwpup_static['WP']['TIMEDIFF'] = get_option('gmt_offset') * 3600; $backwpup_static['WP']['WPLANG'] = WPLANG; $backwpup_static['WP']['VERSION'] = $wp_version; $backwpup_static['WP']['CHARSET'] = get_option('blog_charset'); $backwpup_static['WP']['MEMORY_LIMIT'] = WP_MEMORY_LIMIT; if (defined('ALTERNATE_WP_CRON')) { $backwpup_static['WP']['ALTERNATE_CRON'] = ALTERNATE_WP_CRON; } else { $backwpup_static['WP']['ALTERNATE_CRON'] = false; } //WP folder $backwpup_static['WP']['ABSPATH'] = rtrim(str_replace('\\', '/', ABSPATH), '/') . '/'; $backwpup_static['WP']['WP_CONTENT_DIR'] = rtrim(str_replace('\\', '/', WP_CONTENT_DIR), '/') . '/'; $backwpup_static['WP']['WP_PLUGIN_DIR'] = rtrim(str_replace('\\', '/', WP_PLUGIN_DIR), '/') . '/'; $backwpup_static['WP']['WP_THEMES_DIR'] = rtrim(str_replace('\\', '/', trailingslashit(WP_CONTENT_DIR) . 'themes/'), '/') . '/'; $backwpup_static['WP']['WP_UPLOAD_DIR'] = backwpup_get_upload_dir(); $backwpup_static['WP']['WPINC'] = WPINC; $backwpup_static['WP']['MULTISITE'] = is_multisite(); $backwpup_static['WP']['ADMINURL'] = backwpup_admin_url('admin.php'); //Set plugin data $backwpup_static['BACKWPUP']['PLUGIN_BASEDIR'] = BACKWPUP_PLUGIN_BASEDIR; $backwpup_static['BACKWPUP']['VERSION'] = BACKWPUP_VERSION; $backwpup_static['BACKWPUP']['BACKWPUP_DESTS'] = BACKWPUP_DESTS; //Set config data $backwpup_static['CFG'] = get_option('backwpup'); //check exists gzip functions if (!function_exists('gzopen')) { $backwpup_static['CFG']['gzlogs'] = false; } if (!class_exists('ZipArchive')) { $backwpup_static['CFG']['phpzip'] = false; } //Check working times if (empty($backwpup_static['CFG']['jobstepretry']) or !is_int($backwpup_static['CFG']['jobstepretry']) or $backwpup_static['CFG']['jobstepretry'] > 100) { $backwpup_static['CFG']['jobstepretry'] = 3; } if (empty($backwpup_static['CFG']['jobscriptretry']) or !is_int($backwpup_static['CFG']['jobscriptretry']) or $backwpup_static['CFG']['jobscriptretry'] > 100) { $backwpup_static['CFG']['jobscriptretry'] = 5; } if (empty($backwpup_static['CFG']['jobscriptruntime']) or !is_int($backwpup_static['CFG']['jobscriptruntime']) or $backwpup_static['CFG']['jobscriptruntime'] > 100) { $backwpup_static['CFG']['jobscriptruntime'] = ini_get('max_execution_time'); } if (empty($backwpup_static['CFG']['jobscriptruntimelong']) or !is_int($backwpup_static['CFG']['jobscriptruntimelong']) or $backwpup_static['CFG']['jobscriptruntimelong'] > 1000) { $backwpup_static['CFG']['jobscriptruntimelong'] = 300; } //Set job data $backwpup_static['JOB'] = backwpup_get_job_vars($jobid); //STATIC data $backwpup_static['JOBRUNURL'] = BACKWPUP_PLUGIN_BASEURL . '/job/job_run.php'; //Setup Logs dir $backwpup_static['CFG']['dirlogs'] = rtrim(str_replace('\\', '/', $backwpup_static['CFG']['dirlogs']), '/') . '/'; if (!is_dir($backwpup_static['CFG']['dirlogs'])) { if (!mkdir(rtrim($backwpup_static['CFG']['dirlogs'], '/'), 0777, true)) { trigger_error(printf(__('Can not create folder for log files: %s', 'backwpup'), $backwpup_static['CFG']['dirlogs']), E_USER_ERROR); return false; } } //create .htaccess for apache and index.php for folder security if (!is_file($backwpup_static['CFG']['dirlogs'] . '.htaccess')) { file_put_contents($backwpup_static['CFG']['dirlogs'] . '.htaccess', "<Files \"*\">\n<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n</Files>"); } if (!is_file($backwpup_static['CFG']['dirlogs'] . 'index.php')) { file_put_contents($backwpup_static['CFG']['dirlogs'] . 'index.php', "\n"); } if (!is_writable($backwpup_static['CFG']['dirlogs'])) { trigger_error(__("Log folder not writeable!", "backwpup"), E_USER_ERROR); return false; } //set Logfile $backwpup_static['LOGFILE'] = $backwpup_static['CFG']['dirlogs'] . 'backwpup_log_' . backwpup_date_i18n('Y-m-d_H-i-s') . '.html'; //create log file $fd = fopen($backwpup_static['LOGFILE'], 'w'); //Create log file header fwrite($fd, "<html>\n<head>\n"); fwrite($fd, "<meta name=\"robots\" content=\"noindex, nofollow\" />\n"); fwrite($fd, "<meta name=\"backwpup_version\" content=\"" . BACKWPUP_VERSION . "\" />\n"); fwrite($fd, "<meta name=\"backwpup_logtime\" content=\"" . time() . "\" />\n"); fwrite($fd, str_pad("<meta name=\"backwpup_errors\" content=\"0\" />", 100) . "\n"); fwrite($fd, str_pad("<meta name=\"backwpup_warnings\" content=\"0\" />", 100) . "\n"); fwrite($fd, "<meta name=\"backwpup_jobid\" content=\"" . $backwpup_static['JOB']['jobid'] . "\" />\n"); fwrite($fd, "<meta name=\"backwpup_jobname\" content=\"" . $backwpup_static['JOB']['name'] . "\" />\n"); fwrite($fd, "<meta name=\"backwpup_jobtype\" content=\"" . $backwpup_static['JOB']['type'] . "\" />\n"); fwrite($fd, str_pad("<meta name=\"backwpup_backupfilesize\" content=\"0\" />", 100) . "\n"); fwrite($fd, str_pad("<meta name=\"backwpup_jobruntime\" content=\"0\" />", 100) . "\n"); fwrite($fd, "<style type=\"text/css\">\n"); fwrite($fd, ".timestamp {background-color:grey;}\n"); fwrite($fd, ".warning {background-color:yellow;}\n"); fwrite($fd, ".error {background-color:red;}\n"); fwrite($fd, "#body {font-family:monospace;font-size:12px;white-space:nowrap;}\n"); fwrite($fd, "</style>\n"); fwrite($fd, "<title>" . sprintf(__('BackWPup log for %1$s from %2$s at %3$s', 'backwpup'), $backwpup_static['JOB']['name'], backwpup_date_i18n(get_option('date_format')), backwpup_date_i18n(get_option('time_format'))) . "</title>\n</head>\n<body id=\"body\">\n"); fclose($fd); //Set job start settings $jobs = get_option('backwpup_jobs'); $jobs[$backwpup_static['JOB']['jobid']]['starttime'] = time(); //set start time for job $backwpup_static['JOB']['starttime'] = $jobs[$backwpup_static['JOB']['jobid']]['starttime']; $jobs[$backwpup_static['JOB']['jobid']]['logfile'] = $backwpup_static['LOGFILE']; //Set current logfile $jobs[$backwpup_static['JOB']['jobid']]['cronnextrun'] = backwpup_cron_next($jobs[$backwpup_static['JOB']['jobid']]['cron']); //set next run $backwpup_static['JOB']['cronnextrun'] = $jobs[$backwpup_static['JOB']['jobid']]['cronnextrun']; $jobs[$backwpup_static['JOB']['jobid']]['lastbackupdownloadurl'] = ''; $backwpup_static['JOB']['lastbackupdownloadurl'] = ''; update_option('backwpup_jobs', $jobs); //Save job Settings //Set todo $backwpup_static['TODO'] = explode('+', $backwpup_static['JOB']['type']); //only for jos that makes backups if (in_array('FILE', $backwpup_static['TODO']) or in_array('DB', $backwpup_static['TODO']) or in_array('WPEXP', $backwpup_static['TODO'])) { //make emty file list $backwpup_working['FILELIST'] = array(); $backwpup_working['ALLFILESIZE'] = 0; //set Backup Dir if not set if (empty($backwpup_static['JOB']['backupdir'])) { $backwpup_static['JOB']['backupdir'] = $backwpup_static['TEMPDIR']; } else { //clear path $backwpup_static['JOB']['backupdir'] = rtrim(str_replace('\\', '/', $backwpup_static['JOB']['backupdir']), '/') . '/'; //create backup dir if it not exists if (!is_dir($backwpup_static['JOB']['backupdir'])) { if (!mkdir(rtrim($backwpup_static['JOB']['backupdir'], '/'), 0777, true)) { trigger_error(sprintf(__('Can not create folder for backups: %1$s', 'backwpup'), $backwpup_static['JOB']['backupdir']), E_USER_ERROR); return false; } } //create .htaccess and index.php for folder security if (!is_file($backwpup_static['JOB']['backupdir'] . '.htaccess')) { file_put_contents($backwpup_static['JOB']['backupdir'] . '.htaccess', "<Files \"*\">\n<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n</Files>"); } if (!is_file($backwpup_static['JOB']['backupdir'] . 'index.php')) { file_put_contents($backwpup_static['JOB']['backupdir'] . 'index.php', "\n"); } } //check backup dir if (!is_writable($backwpup_static['JOB']['backupdir'])) { trigger_error(__("Backup folder not writeable!", "backwpup"), E_USER_ERROR); return false; } //set Backup file Name $backwpup_static['backupfile'] = $backwpup_static['JOB']['fileprefix'] . backwpup_date_i18n('Y-m-d_H-i-s') . $backwpup_static['JOB']['fileformart']; } $backwpup_static['CRONSTART'] = $cronstart; $backwpup_working['NONCE'] = wp_create_nonce('BackWPupJob'); $backwpup_working['PID'] = 0; $backwpup_working['WARNING'] = 0; $backwpup_working['ERROR'] = 0; $backwpup_working['RESTART'] = 0; $backwpup_working['STEPSDONE'] = array(); $backwpup_working['STEPTODO'] = 0; $backwpup_working['STEPDONE'] = 0; //build working steps $backwpup_working['STEPS'] = array(); //setup job steps if (in_array('DB', $backwpup_static['TODO'])) { $backwpup_working['STEPS'][] = 'DB_DUMP'; } if (in_array('WPEXP', $backwpup_static['TODO'])) { $backwpup_working['STEPS'][] = 'WP_EXPORT'; } if (in_array('FILE', $backwpup_static['TODO'])) { $backwpup_working['STEPS'][] = 'FILE_LIST'; } if (in_array('DB', $backwpup_static['TODO']) or in_array('WPEXP', $backwpup_static['TODO']) or in_array('FILE', $backwpup_static['TODO'])) { $backwpup_working['STEPS'][] = 'BACKUP_CREATE'; //ADD Destinations if (!empty($backwpup_static['JOB']['backupdir']) and $backwpup_static['JOB']['backupdir'] != '/' and $backwpup_static['JOB']['backupdir'] != $backwpup_static['TEMPDIR']) { $backwpup_working['STEPS'][] = 'DEST_FOLDER'; } if (!empty($backwpup_static['JOB']['mailaddress'])) { $backwpup_working['STEPS'][] = 'DEST_MAIL'; } if (!empty($backwpup_static['JOB']['ftphost']) and !empty($backwpup_static['JOB']['ftpuser']) and !empty($backwpup_static['JOB']['ftppass']) and in_array('FTP', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_FTP'; } if (!empty($backwpup_static['JOB']['dropetoken']) and !empty($backwpup_static['JOB']['dropesecret']) and in_array('DROPBOX', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_DROPBOX'; } if (!empty($backwpup_static['JOB']['sugarrefreshtoken']) and !empty($backwpup_static['JOB']['sugarroot']) and in_array('SUGARSYNC', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_SUGARSYNC'; } if (!empty($backwpup_static['JOB']['awsAccessKey']) and !empty($backwpup_static['JOB']['awsSecretKey']) and !empty($backwpup_static['JOB']['awsBucket']) and in_array('S3', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_S3'; } if (!empty($backwpup_static['JOB']['GStorageAccessKey']) and !empty($backwpup_static['JOB']['GStorageSecret']) and !empty($backwpup_static['JOB']['GStorageBucket']) and in_array('GSTORAGE', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_GSTORAGE'; } if (!empty($backwpup_static['JOB']['rscUsername']) and !empty($backwpup_static['JOB']['rscAPIKey']) and !empty($backwpup_static['JOB']['rscContainer']) and in_array('RSC', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_RSC'; } if (!empty($backwpup_static['JOB']['msazureHost']) and !empty($backwpup_static['JOB']['msazureAccName']) and !empty($backwpup_static['JOB']['msazureKey']) and !empty($backwpup_static['JOB']['msazureContainer']) and in_array('MSAZURE', explode(',', strtoupper(BACKWPUP_DESTS)))) { $backwpup_working['STEPS'][] = 'DEST_MSAZURE'; } } if (in_array('CHECK', $backwpup_static['TODO'])) { $backwpup_working['STEPS'][] = 'DB_CHECK'; } if (in_array('OPTIMIZE', $backwpup_static['TODO'])) { $backwpup_working['STEPS'][] = 'DB_OPTIMIZE'; } $backwpup_working['STEPS'][] = 'JOB_END'; //mark all as not done foreach ($backwpup_working['STEPS'] as $step) { $backwpup_working[$step]['DONE'] = false; } //write working file file_put_contents($backwpup_static['TEMPDIR'] . '.running', serialize(array('timestamp' => time(), 'JOBID' => $backwpup_static['JOB']['jobid'], 'LOGFILE' => $backwpup_static['LOGFILE'], 'STEPSPERSENT' => 0, 'STEPPERSENT' => 0, 'WORKING' => $backwpup_working))); //write static file file_put_contents($backwpup_static['TEMPDIR'] . '.static', serialize($backwpup_static)); //Run job $httpauthheader = ''; if (!empty($backwpup_static['CFG']['httpauthuser']) and !empty($backwpup_static['CFG']['httpauthpassword'])) { $httpauthheader = array('Authorization' => 'Basic ' . base64_encode($backwpup_static['CFG']['httpauthuser'] . ':' . backwpup_base64($backwpup_static['CFG']['httpauthpassword']))); } if (!$backwpup_static['WP']['ALTERNATE_CRON']) { wp_remote_post($backwpup_static['JOBRUNURL'], array('timeout' => 3, 'blocking' => false, 'sslverify' => false, 'headers' => $httpauthheader, 'body' => array('nonce' => $backwpup_working['NONCE'], 'type' => 'start'), 'user-agent' => 'BackWPup')); } return $backwpup_static['LOGFILE']; }
function single_row($jobvalue, $runningfile, $style = '') { global $mode; list($columns, $hidden, $sortable) = $this->get_column_info(); $r = "<tr id=\"jodid-" . $jobvalue["jobid"] . "\"" . $style . ">"; foreach ($columns as $column_name => $column_display_name) { $class = "class=\"{$column_name} column-{$column_name}\""; $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = "{$class}{$style}"; switch ($column_name) { case 'cb': $r .= '<th scope="row" class="check-column"><input type="checkbox" name="jobs[]" value="' . esc_attr($jobvalue["jobid"]) . '" /></th>'; break; case 'id': $r .= "<td {$attributes}>" . $jobvalue["jobid"] . "</td>"; break; case 'jobname': $r .= "<td {$attributes}><strong><a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupeditjob&jobid=' . $jobvalue["jobid"], 'edit-job') . "\" title=\"" . __('Edit:', 'backwpup') . esc_html($jobvalue['name']) . "\">" . esc_html($jobvalue['name']) . "</a></strong>"; $actions = array(); if ($runningfile == false) { $actions['edit'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupeditjob&jobid=' . $jobvalue["jobid"], 'edit-job') . "\">" . __('Edit', 'backwpup') . "</a>"; $actions['copy'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpup&action=copy&jobid=' . $jobvalue["jobid"], 'copy-job_' . $jobvalue["jobid"]) . "\">" . __('Copy', 'backwpup') . "</a>"; $actions['export'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpup&action=export&jobs[]=' . $jobvalue["jobid"], 'bulk-jobs') . "\">" . __('Export', 'backwpup') . "</a>"; $actions['delete'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpup&action=delete&jobs[]=' . $jobvalue["jobid"], 'bulk-jobs') . "\" onclick=\"return showNotice.warn();\">" . __('Delete', 'backwpup') . "</a>"; $actions['runnow'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupworking&action=runnow&jobid=' . $jobvalue["jobid"], 'runnow-job_' . $jobvalue["jobid"]) . "\">" . __('Run Now', 'backwpup') . "</a>"; } else { if ($runningfile['JOBID'] == $jobvalue["jobid"]) { $actions['working'] = "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupworking', '') . "\">" . __('View!', 'backwpup') . "</a>"; $actions['abort'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpup&action=abort', 'abort-job') . "\">" . __('Abort!', 'backwpup') . "</a>"; } } $r .= $this->row_actions($actions); $r .= '</td>'; break; case 'type': $r .= "<td {$attributes}>"; $r .= backwpup_backup_types($jobvalue['type'], false); $r .= "</td>"; break; case 'info': $r .= "<td {$attributes}>"; $r .= "<img class=\"waiting\" src=\"" . esc_url(backwpup_admin_url('images/wpspin_light.gif')) . "\" id=\"image-wait-" . $jobvalue["jobid"] . "\" />"; $r .= "</td>"; break; case 'next': $r .= "<td {$attributes}>"; if ($runningfile['JOBID'] == $jobvalue["jobid"] and $runningfile != false) { $runtime = time() - $jobvalue['starttime']; $r .= __('Running since:', 'backwpup') . ' ' . $runtime . ' ' . __('sec.', 'backwpup'); } elseif ($jobvalue['activated']) { $r .= date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $jobvalue['cronnextrun']); } else { $r .= __('Inactive', 'backwpup'); } if ('excerpt' == $mode) { $r .= '<br />' . __('<a href="http://wikipedia.org/wiki/Cron" target="_blank">Cron</a>:', 'backwpup') . ' ' . $jobvalue['cron']; } $r .= "</td>"; break; case 'last': $r .= "<td {$attributes}>"; if (isset($jobvalue['lastrun']) && $jobvalue['lastrun']) { $r .= backwpup_date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $jobvalue['lastrun']); if (isset($jobvalue['lastruntime'])) { $r .= '<br />' . __('Runtime:', 'backwpup') . ' ' . $jobvalue['lastruntime'] . ' ' . __('sec.', 'backwpup') . '<br />'; } } else { $r .= __('None', 'backwpup'); } if (!empty($jobvalue['lastbackupdownloadurl'])) { $r .= "<a href=\"" . wp_nonce_url($jobvalue['lastbackupdownloadurl'], 'download-backup') . "\" title=\"" . __('Download last Backup', 'backwpup') . "\">" . __('Download', 'backwpup') . "</a> | "; } if (!empty($jobvalue['logfile'])) { $r .= "<a href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupworking&logfile=' . $jobvalue['logfile'], 'view-log_' . basename($jobvalue['logfile'])) . "\" title=\"" . __('View last Log', 'backwpup') . "\">" . __('Log', 'backwpup') . "</a><br />"; } $r .= "</td>"; break; } } $r .= '</tr>'; return $r; }
function backwpup_dashboard_logs() { $cfg = get_option('backwpup'); $widgets = get_option('dashboard_widget_options'); if (!isset($widgets['backwpup_dashboard_logs']) or $widgets['backwpup_dashboard_logs'] < 1 or $widgets['backwpup_dashboard_logs'] > 20) { $widgets['backwpup_dashboard_logs'] = 5; } //get log files $logfiles = array(); if ($dir = @opendir($cfg['dirlogs'])) { while (($file = readdir($dir)) !== false) { if (is_file($cfg['dirlogs'] . '/' . $file) and 'backwpup_log_' == substr($file, 0, strlen('backwpup_log_')) and ('.html' == substr($file, -5) or '.html.gz' == substr($file, -8))) { $logfiles[] = $file; } } closedir($dir); rsort($logfiles); } echo '<ul>'; if (count($logfiles) > 0) { $count = 0; foreach ($logfiles as $logfile) { $logdata = backwpup_read_logheader($cfg['dirlogs'] . '/' . $logfile); echo '<li>'; echo '<span>' . backwpup_date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $logdata['logtime']) . '</span> '; echo '<a href="' . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupworking&logfile=' . $cfg['dirlogs'] . '/' . $logfile, 'view-log_' . $logfile) . '" title="' . __('View Log:', 'backwpup') . ' ' . basename($logfile) . '">' . $logdata['name'] . '</i></a>'; if ($logdata['errors'] > 0) { printf(' <span style="color:red;font-weight:bold;">' . _n("%d ERROR", "%d ERRORS", $logdata['errors'], 'backwpup') . '</span>', $logdata['errors']); } if ($logdata['warnings'] > 0) { printf(' <span style="color:#e66f00;font-weight:bold;">' . _n("%d WARNING", "%d WARNINGS", $logdata['warnings'], 'backwpup') . '</span>', $logdata['warnings']); } if ($logdata['errors'] == 0 and $logdata['warnings'] == 0) { echo ' <span style="color:green;font-weight:bold;">' . __('O.K.', 'backwpup') . '</span>'; } echo '</li>'; $count++; if ($count >= $widgets['backwpup_dashboard_logs']) { break; } } echo '</ul>'; } else { echo '<i>' . __('none', 'backwpup') . '</i>'; } }
function single_row($backup, $jobvalue, $style = '') { list($columns, $hidden, $sortable) = $this->get_column_info(); $r = "<tr {$style}>"; foreach ($columns as $column_name => $column_display_name) { $class = "class=\"{$column_name} column-{$column_name}\""; $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = "{$class}{$style}"; switch ($column_name) { case 'cb': $r .= '<th scope="row" class="check-column"><input type="checkbox" name="backupfiles[]" value="' . esc_attr($backup['file']) . '" /></th>'; break; case 'file': $r .= "<td {$attributes}><strong>" . $backup['filename'] . "</strong>"; $actions = array(); $actions['delete'] = "<a class=\"submitdelete\" href=\"" . wp_nonce_url(backwpup_admin_url('admin.php') . '?page=backwpupbackups&action=delete&jobdest=' . $this->jobid . ',' . $this->dest . '&paged=' . $this->get_pagenum() . '&backupfiles[]=' . esc_attr($backup['file']), 'bulk-backups') . "\" onclick=\"if ( confirm('" . esc_js(__("You are about to delete this Backup Archive. \n 'Cancel' to stop, 'OK' to delete.", "backwpup")) . "') ) { return true;}return false;\">" . __('Delete', 'backwpup') . "</a>"; $actions['download'] = "<a href=\"" . wp_nonce_url($backup['downloadurl'], 'download-backup') . "\">" . __('Download', 'backwpup') . "</a>"; $r .= $this->row_actions($actions); $r .= "</td>"; break; case 'folder': $r .= "<td {$attributes}>"; $r .= $backup['folder']; $r .= "</td>"; break; case 'size': $r .= "<td {$attributes}>"; if (!empty($backup['filesize']) and $backup['filesize'] != -1) { $r .= backwpup_formatBytes($backup['filesize']); } else { $r .= __('?', 'backwpup'); } $r .= "</td>"; break; case 'time': $r .= "<td {$attributes}>"; $r .= backwpup_date_i18n(get_option('date_format'), $backup['time']) . '<br />' . backwpup_date_i18n(get_option('time_format'), $backup['time']); $r .= "</td>"; break; } } $r .= '</tr>'; return $r; }
//clean up temp if (is_dir($tempdir)) { if ($dir = opendir($tempdir)) { while (($file = readdir($dir)) !== false) { if (is_readable($tempdir . $file) and is_file($tempdir . $file)) { if ($file != '.' and $file != '..') { unlink($tempdir . $file); } } } closedir($dir); } } clearstatcache(); if (!empty($runningfile['LOGFILE'])) { file_put_contents($runningfile['LOGFILE'], "<span class=\"timestamp\">" . backwpup_date_i18n('Y/m/d H:i.s') . ":</span> <span class=\"error\">[ERROR]" . __('Aborted by user!!!', 'backwpup') . "</span><br />\n", FILE_APPEND); //write new log header $runningfile['WORKING']['ERROR']++; $fd = fopen($runningfile['LOGFILE'], 'r+'); while (!feof($fd)) { $line = fgets($fd); if (stripos($line, "<meta name=\"backwpup_errors\"") !== false) { fseek($fd, $filepos); fwrite($fd, str_pad("<meta name=\"backwpup_errors\" content=\"" . $runningfile['WORKING']['ERROR'] . "\" />", 100) . "\n"); break; } $filepos = ftell($fd); } fclose($fd); } $backwpup_message = __('Job will be terminated.', 'backwpup') . '<br />';