/**
  * @param string $args
  */
 public function edit_ajax($args = '')
 {
     $error = '';
     if (is_array($args)) {
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         $args['s3accesskey'] = $_POST['s3accesskey'];
         $args['s3secretkey'] = $_POST['s3secretkey'];
         $args['s3bucketselected'] = $_POST['s3bucketselected'];
         $args['s3base_url'] = $_POST['s3base_url'];
         $args['s3region'] = $_POST['s3region'];
         $ajax = TRUE;
     }
     echo '<span id="s3bucketerror" style="color:red;">';
     if (!empty($args['s3accesskey']) && !empty($args['s3secretkey'])) {
         try {
             $s3 = new AmazonS3(array('key' => $args['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($args['s3secretkey']), 'certificate_authority' => TRUE));
             $base_url = $this->get_s3_base_url($args['s3region'], $args['s3base_url']);
             if (stristr($base_url, 'amazonaws.com')) {
                 $s3->set_region(str_replace(array('http://', 'https://'), '', $base_url));
             } else {
                 $s3->set_hostname(str_replace(array('http://', 'https://'), '', $base_url));
                 $s3->allow_hostname_override(FALSE);
                 if (substr($base_url, -1) == '/') {
                     $s3->enable_path_style(TRUE);
                 }
             }
             if (stristr($base_url, 'http://')) {
                 $s3->disable_ssl();
             }
             $buckets = $s3->list_buckets();
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['s3accesskey'])) {
         _e('Missing access key!', 'backwpup');
     } elseif (empty($args['s3secretkey'])) {
         _e('Missing secret access key!', 'backwpup');
     } elseif (!empty($error) && $error == 'Access Denied') {
         echo '<input type="text" name="s3bucket" id="s3bucket" value="' . esc_attr($args['s3bucketselected']) . '" >';
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (!isset($buckets) || count($buckets->body->Buckets->Bucket) < 1) {
         _e('No bucket found!', 'backwpup');
     }
     echo '</span>';
     if (!empty($buckets->body->Buckets->Bucket)) {
         echo '<select name="s3bucket" id="s3bucket">';
         foreach ($buckets->body->Buckets->Bucket as $bucket) {
             echo "<option " . selected($args['s3bucketselected'], esc_attr($bucket->Name), FALSE) . ">" . esc_attr($bucket->Name) . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     }
 }
 /**
  * @param string $boxtype
  * @throws BackWPup_Destination_Dropbox_API_Exception
  */
 public function __construct($boxtype = 'dropbox')
 {
     if ($boxtype == 'dropbox') {
         $this->oauth_app_key = get_site_option('backwpup_cfg_dropboxappkey', base64_decode("dHZkcjk1MnRhZnM1NmZ2"));
         $this->oauth_app_secret = BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_dropboxappsecret', base64_decode("OWV2bDR5MHJvZ2RlYmx1")));
         $this->root = 'dropbox';
     } else {
         $this->oauth_app_key = get_site_option('backwpup_cfg_dropboxsandboxappkey', base64_decode("cHVrZmp1a3JoZHR5OTFk"));
         $this->oauth_app_secret = BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_dropboxsandboxappsecret', base64_decode("eGNoYzhxdTk5eHE0eWdq")));
         $this->root = 'sandbox';
     }
     if (empty($this->oauth_app_key) or empty($this->oauth_app_secret)) {
         throw new BackWPup_Destination_Dropbox_API_Exception("No App key or App Secret specified.");
     }
 }
Example #3
0
 /**
  *
  * Get a url to run a job of BackWPup
  *
  * @param string $starttype Start types are 'runnow', 'runnowlink', 'cronrun', 'runext', 'restart', 'restartalt', 'test'
  * @param int $jobid The id of job to start else 0
  *
  * @return array|object [url] is the job url [header] for auth header or object form wp_remote_get()
  */
 public static function get_jobrun_url($starttype, $jobid = 0)
 {
     $authentication = get_site_option('backwpup_cfg_authentication', array('method' => '', 'basic_user' => '', 'basic_password' => '', 'user_id' => 0, 'query_arg' => ''));
     $url = site_url('wp-cron.php');
     $header = array('Cache-Control' => 'no-cache');
     $authurl = '';
     $query_args = array('_nonce' => substr(wp_hash(wp_nonce_tick() . 'backwpup_job_run-' . $starttype, 'nonce'), -12, 10), 'doing_wp_cron' => sprintf('%.22F', microtime(true)));
     if (in_array($starttype, array('restart', 'runnow', 'cronrun', 'runext', 'test'), true)) {
         $query_args['backwpup_run'] = $starttype;
     }
     if (in_array($starttype, array('runnowlink', 'runnow', 'cronrun', 'runext'), true) && !empty($jobid)) {
         $query_args['jobid'] = $jobid;
     }
     if (!empty($authentication['basic_user']) && !empty($authentication['basic_password']) && $authentication['method'] == 'basic') {
         $header['Authorization'] = 'Basic ' . base64_encode($authentication['basic_user'] . ':' . BackWPup_Encryption::decrypt($authentication['basic_password']));
         $authurl = urlencode($authentication['basic_user']) . ':' . urlencode(BackWPup_Encryption::decrypt($authentication['basic_password'])) . '@';
     }
     if (!empty($authentication['query_arg']) && $authentication['method'] == 'query_arg') {
         $url .= '?' . $authentication['query_arg'];
     }
     if ($starttype === 'runext') {
         $query_args['_nonce'] = get_site_option('backwpup_cfg_jobrunauthkey');
         $query_args['doing_wp_cron'] = null;
         if (!empty($authurl)) {
             $url = str_replace('https://', 'https://' . $authurl, $url);
             $url = str_replace('http://', 'http://' . $authurl, $url);
         }
     }
     if ($starttype === 'runnowlink' && (!defined('ALTERNATE_WP_CRON') || !ALTERNATE_WP_CRON)) {
         $url = wp_nonce_url(network_admin_url('admin.php'), 'backwpup_job_run-' . $starttype);
         $query_args['page'] = 'backwpupjobs';
         $query_args['action'] = 'runnow';
         $query_args['doing_wp_cron'] = null;
         unset($query_args['_nonce']);
     }
     if ($starttype === 'runnowlink' && defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
         $query_args['backwpup_run'] = 'runnowalt';
         $query_args['_nonce'] = substr(wp_hash(wp_nonce_tick() . 'backwpup_job_run-runnowalt', 'nonce'), -12, 10);
         $query_args['doing_wp_cron'] = null;
     }
     if ($starttype === 'restartalt' && defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
         $query_args['backwpup_run'] = 'restart';
         $query_args['_nonce'] = null;
     }
     if ($starttype === 'restart' || $starttype === 'test') {
         $query_args['_nonce'] = null;
     }
     if (!empty($authentication['user_id']) && $authentication['method'] === 'user') {
         //cache cookies for auth some
         $cookies = get_site_transient('backwpup_cookies');
         if (empty($cookies)) {
             $wp_admin_user = get_users(array('role' => 'administrator', 'number' => 1));
             if (empty($wp_admin_user)) {
                 $wp_admin_user = get_users(array('role' => 'backwpup_admin', 'number' => 1));
             }
             if (!empty($wp_admin_user[0]->ID)) {
                 $expiration = time() + 356 * DAY_IN_SECONDS;
                 $manager = WP_Session_Tokens::get_instance($wp_admin_user[0]->ID);
                 $token = $manager->create($expiration);
                 $cookies[LOGGED_IN_COOKIE] = wp_generate_auth_cookie($wp_admin_user[0]->ID, $expiration, 'logged_in', $token);
             }
             set_site_transient('backwpup_cookies', $cookies, HOUR_IN_SECONDS - 30);
         }
     } else {
         $cookies = '';
     }
     $cron_request = array('url' => add_query_arg($query_args, $url), 'key' => $query_args['doing_wp_cron'], 'args' => array('blocking' => false, 'sslverify' => false, 'timeout' => 0.01, 'headers' => $header, 'user-agent' => BackWPup::get_plugin_data('User-Agent')));
     if (!empty($cookies)) {
         foreach ($cookies as $name => $value) {
             $cron_request['args']['cookies'][] = new WP_Http_Cookie(array('name' => $name, 'value' => $value));
         }
     }
     $cron_request = apply_filters('cron_request', $cron_request);
     if ($starttype === 'test') {
         $cron_request['args']['timeout'] = 15;
         $cron_request['args']['blocking'] = true;
     }
     if (!in_array($starttype, array('runnowlink', 'runext', 'restartalt'), true)) {
         delete_transient('doing_cron');
         return wp_remote_post($cron_request['url'], $cron_request['args']);
     }
     return $cron_request;
 }
 /**
  * @param string $args
  */
 public function edit_ajax($args = '')
 {
     $error = '';
     if (is_array($args)) {
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         $args['msazureaccname'] = $_POST['msazureaccname'];
         $args['msazurekey'] = $_POST['msazurekey'];
         $args['msazureselected'] = $_POST['msazureselected'];
         $ajax = TRUE;
     }
     echo '<span id="msazurecontainererror" style="color:red;">';
     if (!empty($args['msazureaccname']) && !empty($args['msazurekey'])) {
         try {
             set_include_path(get_include_path() . PATH_SEPARATOR . BackWPup::get_plugin_data('plugindir') . '/vendor/PEAR/');
             $blobRestProxy = WindowsAzure\Common\ServicesBuilder::getInstance()->createBlobService('DefaultEndpointsProtocol=https;AccountName=' . $args['msazureaccname'] . ';AccountKey=' . BackWPup_Encryption::decrypt($args['msazurekey']));
             $containers = $blobRestProxy->listContainers()->getContainers();
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['msazureaccname'])) {
         _e('Missing account name!', 'backwpup');
     } elseif (empty($args['msazurekey'])) {
         _e('Missing access key!', 'backwpup');
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (empty($containers)) {
         _e('No container found!', 'backwpup');
     }
     echo '</span>';
     if (!empty($containers)) {
         echo '<select name="msazurecontainer" id="msazurecontainer">';
         foreach ($containers as $container) {
             echo "<option " . selected(strtolower($args['msazureselected']), strtolower($container->getName()), FALSE) . ">" . $container->getName() . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     } else {
         return;
     }
 }
Example #5
0
 private static function upgrade_from_version_two()
 {
     //load options
     $cfg = get_option('backwpup');
     //only exists in Version 2
     $jobs = get_option('backwpup_jobs');
     //delete old options
     delete_option('backwpup');
     delete_option('backwpup_jobs');
     //add new option default structure and without auto load cache
     if (!is_multisite()) {
         add_option('backwpup_jobs', array(), NULL, 'no');
     }
     //upgrade cfg
     //if old value switch it to new
     if (!empty($cfg['dirlogs'])) {
         $cfg['logfolder'] = $cfg['dirlogs'];
     }
     if (!empty($cfg['httpauthpassword'])) {
         if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $cfg['httpauthpassword'])) {
             $cfg['httpauthpassword'] = base64_decode($cfg['httpauthpassword']);
         }
         $cfg['httpauthpassword'] = BackWPup_Encryption::encrypt($cfg['httpauthpassword']);
     }
     // delete old not needed vars
     unset($cfg['dirtemp'], $cfg['dirlogs'], $cfg['logfilelist'], $cfg['jobscriptruntime'], $cfg['jobscriptruntimelong'], $cfg['last_activate'], $cfg['disablewpcron'], $cfg['phpzip'], $cfg['apicronservice'], $cfg['mailsndemail'], $cfg['mailsndname'], $cfg['mailmethod'], $cfg['mailsendmail'], $cfg['mailhost'], $cfg['mailpass'], $cfg['mailhostport'], $cfg['mailsecure'], $cfg['mailuser']);
     //save in options
     foreach ($cfg as $cfgname => $cfgvalue) {
         update_site_option('backwpup_cfg_' . $cfgname, $cfgvalue);
     }
     //Put old jobs to new if exists
     foreach ($jobs as $jobid => $jobvalue) {
         //convert general settings
         if (empty($jobvalue['jobid'])) {
             $jobvalue['jobid'] = $jobid;
         }
         if (empty($jobvalue['activated'])) {
             $jobvalue['activetype'] = '';
         } else {
             $jobvalue['activetype'] = 'wpcron';
         }
         if (!isset($jobvalue['cronselect']) && !isset($jobvalue['cron'])) {
             $jobvalue['cronselect'] = 'basic';
         } elseif (!isset($jobvalue['cronselect']) && isset($jobvalue['cron'])) {
             $jobvalue['cronselect'] = 'advanced';
         }
         $jobvalue['backuptype'] = 'archive';
         $jobvalue['type'] = explode('+', $jobvalue['type']);
         //save as array
         foreach ($jobvalue['type'] as $key => $type) {
             if ($type == 'DB') {
                 $jobvalue['type'][$key] = 'DBDUMP';
             }
             if ($type == 'OPTIMIZE') {
                 unset($jobvalue['type'][$key]);
             }
             if ($type == 'CHECK') {
                 $jobvalue['type'][$key] = 'DBCHECK';
             }
             if ($type == 'MAIL') {
                 $jobvalue['type'][$key] = 'EMAIL';
             }
         }
         $jobvalue['archivename'] = $jobvalue['fileprefix'] . '%Y-%m-%d_%H-%i-%s';
         $jobvalue['archiveformat'] = $jobvalue['fileformart'];
         //convert active destinations
         $jobvalue['destinations'] = array();
         if (!empty($jobvalue['backupdir']) && $jobvalue['backupdir'] != '/') {
             $jobvalue['destinations'][] = 'FOLDER';
         }
         if (!empty($jobvalue['mailaddress'])) {
             $jobvalue['destinations'][] = 'MAIL';
         }
         if (!empty($jobvalue['ftphost']) && !empty($jobvalue['ftpuser']) && !empty($jobvalue['ftppass'])) {
             $jobvalue['destinations'][] = 'FTP';
         }
         if (!empty($jobvalue['dropetoken']) && !empty($jobvalue['dropesecret'])) {
             $jobvalue['destinations'][] = 'DROPBOX';
         }
         if (!empty($jobvalue['sugarrefreshtoken']) && !empty($jobvalue['sugarroot'])) {
             $jobvalue['destinations'][] = 'SUGARSYNC';
         }
         if (!empty($jobvalue['awsAccessKey']) && !empty($jobvalue['awsSecretKey']) && !empty($jobvalue['awsBucket'])) {
             $jobvalue['destinations'][] = 'S3';
         }
         if (!empty($jobvalue['GStorageAccessKey']) and !empty($jobvalue['GStorageSecret']) && !empty($jobvalue['GStorageBucket']) && !in_array('S3', $jobvalue['destinations'])) {
             $jobvalue['destinations'][] = 'S3';
         }
         if (!empty($jobvalue['rscUsername']) && !empty($jobvalue['rscAPIKey']) && !empty($jobvalue['rscContainer'])) {
             $jobvalue['destinations'][] = 'RSC';
         }
         if (!empty($jobvalue['msazureHost']) && !empty($jobvalue['msazureAccName']) && !empty($jobvalue['msazureKey']) && !empty($jobvalue['msazureContainer'])) {
             $jobvalue['destinations'][] = 'MSAZURE';
         }
         //convert dropbox
         $jobvalue['dropboxtoken'] = '';
         //new app key are set must reauth
         $jobvalue['dropboxsecret'] = '';
         $jobvalue['dropboxroot'] = 'dropbox';
         $jobvalue['dropboxmaxbackups'] = $jobvalue['dropemaxbackups'];
         $jobvalue['dropboxdir'] = $jobvalue['dropedir'];
         unset($jobvalue['dropetoken'], $jobvalue['dropesecret'], $jobvalue['droperoot'], $jobvalue['dropemaxbackups'], $jobvalue['dropedir']);
         //convert amazon S3
         $jobvalue['s3accesskey'] = $jobvalue['awsAccessKey'];
         $jobvalue['s3secretkey'] = BackWPup_Encryption::encrypt($jobvalue['awsSecretKey']);
         $jobvalue['s3bucket'] = $jobvalue['awsBucket'];
         //get aws region
         $jobvalue['s3region'] = 'us-east-1';
         $jobvalue['s3base_url'] = '';
         $jobvalue['s3storageclass'] = !empty($jobvalue['awsrrs']) ? 'REDUCED_REDUNDANCY' : '';
         $jobvalue['s3dir'] = $jobvalue['awsdir'];
         $jobvalue['s3maxbackups'] = $jobvalue['awsmaxbackups'];
         unset($jobvalue['awsAccessKey'], $jobvalue['awsSecretKey'], $jobvalue['awsBucket'], $jobvalue['awsrrs'], $jobvalue['awsdir'], $jobvalue['awsmaxbackups']);
         //convert google storage
         $jobvalue['s3accesskey'] = $jobvalue['GStorageAccessKey'];
         $jobvalue['s3secretkey'] = BackWPup_Encryption::encrypt($jobvalue['GStorageSecret']);
         $jobvalue['s3bucket'] = $jobvalue['GStorageBucket'];
         $jobvalue['s3region'] = 'google-storage';
         $jobvalue['s3base_url'] = '';
         $jobvalue['s3ssencrypt'] = '';
         $jobvalue['s3dir'] = $jobvalue['GStoragedir'];
         $jobvalue['s3maxbackups'] = $jobvalue['GStoragemaxbackups'];
         unset($jobvalue['GStorageAccessKey'], $jobvalue['GStorageSecret'], $jobvalue['GStorageBucket'], $jobvalue['GStoragedir'], $jobvalue['GStoragemaxbackups']);
         //convert MS Azure storage
         $jobvalue['msazureaccname'] = $jobvalue['msazureAccName'];
         $jobvalue['msazurekey'] = BackWPup_Encryption::encrypt($jobvalue['msazureKey']);
         $jobvalue['msazurecontainer'] = $jobvalue['msazureContainer'];
         unset($jobvalue['msazureHost'], $jobvalue['msazureAccName'], $jobvalue['msazureKey'], $jobvalue['msazureContainer']);
         //convert FTP
         if (preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $jobvalue['ftppass'])) {
             $jobvalue['ftppass'] = base64_decode($jobvalue['ftppass']);
         }
         $jobvalue['ftppass'] = BackWPup_Encryption::encrypt($jobvalue['ftppass']);
         if (!empty($jobvalue['ftphost']) && strstr($jobvalue['ftphost'], ':')) {
             list($jobvalue['ftphost'], $jobvalue['ftphostport']) = explode(':', $jobvalue['ftphost'], 2);
         }
         //convert Sugarsync
         //convert Mail
         $jobvalue['emailaddress'] = $jobvalue['mailaddress'];
         $jobvalue['emailefilesize'] = $jobvalue['mailefilesize'];
         unset($jobvalue['mailaddress'], $jobvalue['mailefilesize']);
         //convert RSC
         $jobvalue['rscusername'] = $jobvalue['rscUsername'];
         $jobvalue['rscapikey'] = $jobvalue['rscAPIKey'];
         $jobvalue['rsccontainer'] = $jobvalue['rscContainer'];
         //convert jobtype DB Dump
         $jobvalue['dbdumpexclude'] = $jobvalue['dbexclude'];
         unset($jobvalue['dbexclude'], $jobvalue['dbshortinsert']);
         //convert jobtype DBDUMP, DBCHECK
         $jobvalue['dbcheckrepair'] = TRUE;
         unset($jobvalue['maintenance']);
         //convert jobtype wpexport
         //convert jobtype file
         $excludes = array();
         foreach ($jobvalue['backuprootexcludedirs'] as $folder) {
             $excludes[] = basename($folder);
         }
         $jobvalue['backuprootexcludedirs'] = $excludes;
         $excludes = array();
         foreach ($jobvalue['backupcontentexcludedirs'] as $folder) {
             $excludes[] = basename($folder);
         }
         $jobvalue['backupcontentexcludedirs'] = $excludes;
         $excludes = array();
         foreach ($jobvalue['backuppluginsexcludedirs'] as $folder) {
             $excludes[] = basename($folder);
         }
         $jobvalue['backuppluginsexcludedirs'] = $excludes;
         $excludes = array();
         foreach ($jobvalue['backupthemesexcludedirs'] as $folder) {
             $excludes[] = basename($folder);
         }
         $jobvalue['backupthemesexcludedirs'] = $excludes;
         $excludes = array();
         foreach ($jobvalue['backupuploadsexcludedirs'] as $folder) {
             $excludes[] = basename($folder);
         }
         $jobvalue['backupuploadsexcludedirs'] = $excludes;
         //delete not longer needed
         unset($jobvalue['cronnextrun'], $jobvalue['fileprefix'], $jobvalue['fileformart'], $jobvalue['scheduleintervaltype'], $jobvalue['scheduleintervalteimes'], $jobvalue['scheduleinterval'], $jobvalue['dropemail'], $jobvalue['dropepass'], $jobvalue['dropesignmethod']);
         //save in options
         foreach ($jobvalue as $jobvaluename => $jobvaluevalue) {
             BackWPup_Option::update($jobvalue['jobid'], $jobvaluename, $jobvaluevalue);
         }
     }
     set_site_transient('backwpup_upgrade_from_version_two', TRUE, 3600 * 24 * 7);
 }
 /**
  * @param $email
  * @param $password
  * @throws BackWPup_Destination_SugarSync_API_Exception
  */
 public function create_account($email, $password)
 {
     $auth = '<?xml version="1.0" encoding="UTF-8" ?>';
     $auth .= '<user>';
     $auth .= '<email>' . mb_convert_encoding($email, 'UTF-8', $this->encoding) . '</email>';
     $auth .= '<password>' . mb_convert_encoding($password, 'UTF-8', $this->encoding) . '</password>';
     $auth .= '<accessKeyId>' . get_site_option('backwpup_cfg_sugarsynckey', base64_decode("TlRBek1EY3lOakV6TkRrMk1URXhNemM0TWpJ")) . '</accessKeyId>';
     $auth .= '<privateAccessKey>' . BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_sugarsyncsecret', base64_decode("TkRFd01UazRNVEpqTW1Ga05EaG1NR0k1TVRFNFpqa3lPR1V6WlRVMk1tTQ=="))) . '</privateAccessKey>';
     $auth .= '</user>';
     // init
     $curl = curl_init();
     //set options
     curl_setopt($curl, CURLOPT_URL, 'https://provisioning-api.sugarsync.com/users');
     curl_setopt($curl, CURLOPT_USERAGENT, BackWPup::get_plugin_data('User-Agent'));
     if (ini_get('open_basedir') == '') {
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
     }
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     if (BackWPup::get_plugin_data('cacert')) {
         curl_setopt($curl, CURLOPT_SSLVERSION, 1);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
         curl_setopt($curl, CURLOPT_CAINFO, BackWPup::get_plugin_data('cacert'));
         curl_setopt($curl, CURLOPT_CAPATH, dirname(BackWPup::get_plugin_data('cacert')));
     } else {
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     }
     curl_setopt($curl, CURLOPT_HEADER, TRUE);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml; charset=UTF-8', 'Content-Length: ' . strlen($auth)));
     curl_setopt($curl, CURLOPT_POSTFIELDS, $auth);
     curl_setopt($curl, CURLOPT_POST, TRUE);
     // execute
     $response = curl_exec($curl);
     $curlgetinfo = curl_getinfo($curl);
     // fetch curl errors
     if (curl_errno($curl) != 0) {
         throw new BackWPup_Destination_SugarSync_API_Exception('cUrl Error: ' . curl_error($curl));
     }
     curl_close($curl);
     if ($curlgetinfo['http_code'] == 201) {
         throw new BackWPup_Destination_SugarSync_API_Exception('Account created.');
     } else {
         if ($curlgetinfo['http_code'] == 400) {
             throw new BackWPup_Destination_SugarSync_API_Exception('Http Error: ' . $curlgetinfo['http_code'] . ' ' . substr($response, $curlgetinfo['header_size']));
         } elseif ($curlgetinfo['http_code'] == 401) {
             throw new BackWPup_Destination_SugarSync_API_Exception('Http Error: ' . $curlgetinfo['http_code'] . ' Developer credentials cannot be verified. Either a developer with the specified accessKeyId does not exist or the privateKeyID does not match an assigned accessKeyId.');
         } elseif ($curlgetinfo['http_code'] == 403) {
             throw new BackWPup_Destination_SugarSync_API_Exception('Http Error: ' . $curlgetinfo['http_code'] . ' ' . substr($response, $curlgetinfo['header_size']));
         } elseif ($curlgetinfo['http_code'] == 503) {
             throw new BackWPup_Destination_SugarSync_API_Exception('Http Error: ' . $curlgetinfo['http_code'] . ' ' . substr($response, $curlgetinfo['header_size']));
         } else {
             throw new BackWPup_Destination_SugarSync_API_Exception('Http Error: ' . $curlgetinfo['http_code']);
         }
     }
 }
 /**
  * sends test mail
  */
 public function edit_ajax()
 {
     check_ajax_referer('backwpup_ajax_nonce');
     //get mail settings
     $emailmethod = 'mail';
     $emailsendmail = '';
     $emailhost = '';
     $emailhostport = '';
     $emailsecure = '';
     $emailuser = '';
     $emailpass = '';
     if (empty($_POST['emailmethod'])) {
         //do so if i'm the wp_mail to get the settings
         global $phpmailer;
         // (Re)create it, if it's gone missing
         if (!is_object($phpmailer) || !$phpmailer instanceof PHPMailer) {
             require_once ABSPATH . WPINC . '/class-phpmailer.php';
             require_once ABSPATH . WPINC . '/class-smtp.php';
             $phpmailer = new PHPMailer(true);
         }
         //only if PHPMailer really used
         if (is_object($phpmailer)) {
             do_action_ref_array('phpmailer_init', array(&$phpmailer));
             //get settings from PHPMailer
             $emailmethod = $phpmailer->Mailer;
             $emailsendmail = $phpmailer->Sendmail;
             $emailhost = $phpmailer->Host;
             $emailhostport = $phpmailer->Port;
             $emailsecure = $phpmailer->SMTPSecure;
             $emailuser = $phpmailer->Username;
             $emailpass = $phpmailer->Password;
         }
     } else {
         $emailmethod = $_POST['emailmethod'];
         $emailsendmail = $_POST['emailsendmail'];
         $emailhost = $_POST['emailhost'];
         $emailhostport = $_POST['emailhostport'];
         $emailsecure = $_POST['emailsecure'];
         $emailuser = $_POST['emailuser'];
         $emailpass = BackWPup_Encryption::decrypt($_POST['emailpass']);
     }
     //Generate mail with Swift Mailer
     if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
         $mbEncoding = mb_internal_encoding();
         mb_internal_encoding('ASCII');
     }
     try {
         // Create the Transport
         if ($emailmethod == 'smtp') {
             $transport = Swift_SmtpTransport::newInstance($emailhost, $emailhostport);
             $transport->setUsername($emailuser);
             $transport->setPassword($emailpass);
             if ($emailsecure == 'ssl') {
                 $transport->setEncryption('ssl');
             }
             if ($emailsecure == 'tls') {
                 $transport->setEncryption('tls');
             }
         } elseif ($emailmethod == 'sendmail') {
             $transport = Swift_SendmailTransport::newInstance($emailsendmail);
         } else {
             $transport = Swift_MailTransport::newInstance();
         }
         // Create the Mailer using your created Transport
         $emailer = Swift_Mailer::newInstance($transport);
         // Create a message
         $message = Swift_Message::newInstance(__('BackWPup archive sending TEST Message', 'backwpup'));
         $message->setFrom(array($_POST['emailsndemail'] => isset($_POST['emailsndemailname']) ? $_POST['emailsndemailname'] : ''));
         $message->setTo(array($_POST['emailaddress']));
         $message->setBody(__('If this message reaches your inbox, sending backup archives via email should work for you.', 'backwpup'));
         // Send the message
         $result = $emailer->send($message);
     } catch (Exception $e) {
         echo '<span id="emailsendtext" style="color:red;">Swift Mailer: ' . $e->getMessage() . '</span>';
     }
     if (isset($mbEncoding)) {
         mb_internal_encoding($mbEncoding);
     }
     if (!isset($result) || !$result) {
         echo '<span id="emailsendtext" style="color:red;">' . __('Error while sending email!', 'backwpup') . '</span>';
     } else {
         echo '<span id="emailsendtext" style="color:green;">' . __('Email sent.', 'backwpup') . '</span>';
     }
     die;
 }
Example #8
0
 /**
  * @param $job_object
  * @return bool
  */
 public function job_run_archive(BackWPup_Job $job_object)
 {
     $job_object->substeps_todo = 2 + $job_object->backup_filesize;
     if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
         $job_object->log(sprintf(__('%d. Try to send backup file to an FTP server&#160;&hellip;', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
     }
     if (!empty($job_object->job['ftpssl'])) {
         //make SSL FTP connection
         if (function_exists('ftp_ssl_connect')) {
             $ftp_conn_id = ftp_ssl_connect($job_object->job['ftphost'], $job_object->job['ftphostport'], $job_object->job['ftptimeout']);
             if ($ftp_conn_id) {
                 $job_object->log(sprintf(__('Connected via explicit SSL-FTP to server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_NOTICE);
             } else {
                 $job_object->log(sprintf(__('Cannot connect via explicit SSL-FTP to server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_ERROR);
                 return FALSE;
             }
         } else {
             $job_object->log(__('PHP function to connect with explicit SSL-FTP to server does not exist!', 'backwpup'), E_USER_ERROR);
             return TRUE;
         }
     } else {
         //make normal FTP connection if SSL not work
         $ftp_conn_id = ftp_connect($job_object->job['ftphost'], $job_object->job['ftphostport'], $job_object->job['ftptimeout']);
         if ($ftp_conn_id) {
             $job_object->log(sprintf(__('Connected to FTP server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_NOTICE);
         } else {
             $job_object->log(sprintf(__('Cannot connect to FTP server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_ERROR);
             return FALSE;
         }
     }
     //FTP Login
     $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'USER ' . $job_object->job['ftpuser']), E_USER_NOTICE);
     if ($loginok = @ftp_login($ftp_conn_id, $job_object->job['ftpuser'], BackWPup_Encryption::decrypt($job_object->job['ftppass']))) {
         $job_object->log(sprintf(__('FTP server response: %s', 'backwpup'), 'User ' . $job_object->job['ftpuser'] . ' logged in.'), E_USER_NOTICE);
     } else {
         //if PHP ftp login don't work use raw login
         $return = ftp_raw($ftp_conn_id, 'USER ' . $job_object->job['ftpuser']);
         $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $return[0]), E_USER_NOTICE);
         if (substr(trim($return[0]), 0, 3) <= 400) {
             $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'PASS *******'), E_USER_NOTICE);
             $return = ftp_raw($ftp_conn_id, 'PASS ' . BackWPup_Encryption::decrypt($job_object->job['ftppass']));
             if (substr(trim($return[0]), 0, 3) <= 400) {
                 $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $return[0]), E_USER_NOTICE);
                 $loginok = TRUE;
             } else {
                 $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $return[0]), E_USER_ERROR);
             }
         }
     }
     if (!$loginok) {
         return FALSE;
     }
     //SYSTYPE
     $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'SYST'), E_USER_NOTICE);
     $systype = ftp_systype($ftp_conn_id);
     if ($systype) {
         $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $systype), E_USER_NOTICE);
     } else {
         $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Error getting SYSTYPE', 'backwpup')), E_USER_ERROR);
     }
     //set actual ftp dir to ftp dir
     if (empty($job_object->job['ftpdir'])) {
         $job_object->job['ftpdir'] = trailingslashit(ftp_pwd($ftp_conn_id));
     }
     // prepend actual ftp dir if relative dir
     if (substr($job_object->job['ftpdir'], 0, 1) != '/') {
         $job_object->job['ftpdir'] = trailingslashit(ftp_pwd($ftp_conn_id)) . $job_object->job['ftpdir'];
     }
     //test ftp dir and create it if not exists
     if ($job_object->job['ftpdir'] != '/') {
         @ftp_chdir($ftp_conn_id, '/');
         //go to root
         $ftpdirs = explode('/', trim($job_object->job['ftpdir'], '/'));
         foreach ($ftpdirs as $ftpdir) {
             if (empty($ftpdir)) {
                 continue;
             }
             if (!@ftp_chdir($ftp_conn_id, $ftpdir)) {
                 if (@ftp_mkdir($ftp_conn_id, $ftpdir)) {
                     $job_object->log(sprintf(__('FTP Folder "%s" created!', 'backwpup'), $ftpdir), E_USER_NOTICE);
                     ftp_chdir($ftp_conn_id, $ftpdir);
                 } else {
                     $job_object->log(sprintf(__('FTP Folder "%s" cannot be created!', 'backwpup'), $ftpdir), E_USER_ERROR);
                     return FALSE;
                 }
             }
         }
     }
     // Get the current working directory
     $current_ftp_dir = trailingslashit(ftp_pwd($ftp_conn_id));
     if ($job_object->substeps_done == 0) {
         $job_object->log(sprintf(__('FTP current folder is: %s', 'backwpup'), $current_ftp_dir), E_USER_NOTICE);
     }
     //get file size to resume upload
     @clearstatcache();
     $job_object->substeps_done = @ftp_size($ftp_conn_id, $job_object->job['ftpdir'] . $job_object->backup_file);
     if ($job_object->substeps_done == -1) {
         $job_object->substeps_done = 0;
     }
     //PASV
     $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'PASV'), E_USER_NOTICE);
     if ($job_object->job['ftppasv']) {
         if (ftp_pasv($ftp_conn_id, TRUE)) {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Entering passive mode', 'backwpup')), E_USER_NOTICE);
         } else {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Cannot enter passive mode', 'backwpup')), E_USER_WARNING);
         }
     } else {
         if (ftp_pasv($ftp_conn_id, FALSE)) {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Entering normal mode', 'backwpup')), E_USER_NOTICE);
         } else {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Cannot enter normal mode', 'backwpup')), E_USER_WARNING);
         }
     }
     if ($job_object->substeps_done < $job_object->backup_filesize) {
         $job_object->log(__('Starting upload to FTP &#160;&hellip;', 'backwpup'), E_USER_NOTICE);
         if ($fp = fopen($job_object->backup_folder . $job_object->backup_file, 'rb')) {
             //go to actual file pos
             fseek($fp, $job_object->substeps_done);
             $ret = ftp_nb_fput($ftp_conn_id, $current_ftp_dir . $job_object->backup_file, $fp, FTP_BINARY, $job_object->substeps_done);
             while ($ret == FTP_MOREDATA) {
                 $job_object->substeps_done = ftell($fp);
                 $job_object->update_working_data();
                 $job_object->do_restart_time();
                 $ret = ftp_nb_continue($ftp_conn_id);
             }
             if ($ret != FTP_FINISHED) {
                 $job_object->log(__('Cannot transfer backup to FTP server!', 'backwpup'), E_USER_ERROR);
                 return FALSE;
             } else {
                 $job_object->substeps_done = $job_object->backup_filesize + 1;
                 $job_object->log(sprintf(__('Backup transferred to FTP server: %s', 'backwpup'), $current_ftp_dir . $job_object->backup_file), E_USER_NOTICE);
                 if (!empty($job_object->job['jobid'])) {
                     BackWPup_Option::update($job_object->job['jobid'], 'lastbackupdownloadurl', "ftp://" . $job_object->job['ftpuser'] . ":" . BackWPup_Encryption::decrypt($job_object->job['ftppass']) . "@" . $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport'] . $current_ftp_dir . $job_object->backup_file);
                 }
             }
             fclose($fp);
         } else {
             $job_object->log(__('Can not open source file for transfer.', 'backwpup'), E_USER_ERROR);
             return FALSE;
         }
     }
     $backupfilelist = array();
     $filecounter = 0;
     $files = array();
     if ($filelist = ftp_nlist($ftp_conn_id, '.')) {
         foreach ($filelist as $file) {
             if (basename($file) != '.' && basename($file) != '..') {
                 if ($job_object->is_backup_archive($file)) {
                     $time = ftp_mdtm($ftp_conn_id, $file);
                     if ($time != -1) {
                         $backupfilelist[$time] = basename($file);
                     } else {
                         $backupfilelist[] = basename($file);
                     }
                 }
                 $files[$filecounter]['folder'] = 'ftp://' . $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport'] . $job_object->job['ftpdir'];
                 $files[$filecounter]['file'] = $job_object->job['ftpdir'] . basename($file);
                 $files[$filecounter]['filename'] = basename($file);
                 $files[$filecounter]['downloadurl'] = 'ftp://' . rawurlencode($job_object->job['ftpuser']) . ':' . rawurlencode(BackWPup_Encryption::decrypt($job_object->job['ftppass'])) . '@' . $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport'] . $job_object->job['ftpdir'] . basename($file);
                 $files[$filecounter]['filesize'] = ftp_size($ftp_conn_id, $file);
                 $files[$filecounter]['time'] = ftp_mdtm($ftp_conn_id, $file);
                 $filecounter++;
             }
         }
     }
     if (!empty($job_object->job['ftpmaxbackups']) && $job_object->job['ftpmaxbackups'] > 0) {
         //Delete old backups
         if (count($backupfilelist) > $job_object->job['ftpmaxbackups']) {
             ksort($backupfilelist);
             $numdeltefiles = 0;
             while ($file = array_shift($backupfilelist)) {
                 if (count($backupfilelist) < $job_object->job['ftpmaxbackups']) {
                     break;
                 }
                 if (ftp_delete($ftp_conn_id, $file)) {
                     //delete files on ftp
                     foreach ($files as $key => $filedata) {
                         if ($filedata['file'] == $job_object->job['ftpdir'] . $file) {
                             unset($files[$key]);
                         }
                     }
                     $numdeltefiles++;
                 } else {
                     $job_object->log(sprintf(__('Cannot delete "%s" on FTP server!', 'backwpup'), $job_object->job['ftpdir'] . $file), E_USER_ERROR);
                 }
             }
             if ($numdeltefiles > 0) {
                 $job_object->log(sprintf(_n('One file deleted on FTP server', '%d files deleted on FTP server', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE);
             }
         }
     }
     set_site_transient('backwpup_' . $job_object->job['jobid'] . '_ftp', $files, YEAR_IN_SECONDS);
     $job_object->substeps_done++;
     ftp_close($ftp_conn_id);
     return TRUE;
 }
    /**
     * Page Output
     */
    public static function page()
    {
        global $wpdb;
        ?>
    <div class="wrap" id="backwpup-page">
		<h2><span id="backwpup-page-icon">&nbsp;</span><?php 
        echo sprintf(__('%s Settings', 'backwpup'), BackWPup::get_plugin_data('name'));
        ?>
</h2>
		<?php 
        $tabs = array('general' => __('General', 'backwpup'), 'job' => __('Jobs', 'backwpup'), 'log' => __('Logs', 'backwpup'), 'net' => __('Network', 'backwpup'), 'apikey' => __('API Keys', 'backwpup'), 'information' => __('Information', 'backwpup'));
        $tabs = apply_filters('backwpup_page_settings_tab', $tabs);
        echo '<h2 class="nav-tab-wrapper">';
        foreach ($tabs as $id => $name) {
            echo '<a href="#backwpup-tab-' . $id . '" class="nav-tab">' . $name . '</a>';
        }
        echo '</h2>';
        BackWPup_Admin::display_messages();
        ?>

    <form id="settingsform" action="<?php 
        echo admin_url('admin-post.php?action=backwpup');
        ?>
" method="post">
		<?php 
        wp_nonce_field('backwpupsettings_page');
        ?>
        <input type="hidden" name="page" value="backwpupsettings" />
    	<input type="hidden" name="anchor" value="#backwpup-tab-general" />

		<div class="table ui-tabs-hide" id="backwpup-tab-general">

			<h3 class="title"><?php 
        _e('Display Settings', 'backwpup');
        ?>
</h3>
            <p><?php 
        _e('Do you want to see BackWPup in the WordPress admin bar?', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><?php 
        _e('Admin bar', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Admin Bar', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="showadminbar">
                                <input name="showadminbar" type="checkbox" id="showadminbar"
                                       value="1" <?php 
        checked(get_site_option('backwpup_cfg_showadminbar'), TRUE);
        ?>
 />
								<?php 
        _e('Show BackWPup links in admin bar.', 'backwpup');
        ?>
</label>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('Folder sizes', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Folder sizes', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="showfoldersize">
                                <input name="showfoldersize" type="checkbox" id="showfoldersize"
                                       value="1" <?php 
        checked(get_site_option('backwpup_cfg_showfoldersize'), TRUE);
        ?>
 />
								<?php 
        _e('Display folder sizes in the files tab when editing a job. (Might increase loading time of files tab.)', 'backwpup');
        ?>
</label>
                        </fieldset>
                    </td>
                </tr>
            </table>
			<h3 class="title"><?php 
        _e('Security', 'backwpup');
        ?>
</h3>
			<p><?php 
        _e('Security option for BackWPup', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><?php 
        _e('Protect folders', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Protect folders', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="protectfolders">
                                <input name="protectfolders" type="checkbox" id="protectfolders"
                                       value="1" <?php 
        checked(get_site_option('backwpup_cfg_protectfolders'), TRUE);
        ?>
 />
								<?php 
        _e('Protect BackWPup folders ( Temp, Log and Backups ) with <code>.htaccess</code> and <code>index.php</code>', 'backwpup');
        ?>
                            </label>
                        </fieldset>
                    </td>
                </tr>
            </table>

			<?php 
        do_action('backwpup_page_settings_tab_generel');
        ?>

		</div>

        <div class="table ui-tabs-hide" id="backwpup-tab-log">

            <p><?php 
        _e('Every time BackWPup runs a backup job, a log file is being generated. Choose where to store your log files and how many of them.', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><label for="logfolder"><?php 
        _e('Log file folder', 'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="logfolder" type="text" id="logfolder"
                               value="<?php 
        echo get_site_option('backwpup_cfg_logfolder');
        ?>
"
                               class="regular-text code"/>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><label for="maxlogs"><?php 
        _e('Maximum number of log files in folder', 'backwpup');
        ?>
</label>
                    </th>
                    <td>
                        <input name="maxlogs" type="text" id="maxlogs" title="<?php 
        esc_attr_e('Oldest files will be deleted first.', 'backwpup');
        ?>
"
                               value="<?php 
        echo get_site_option('backwpup_cfg_maxlogs');
        ?>
" class="small-text code help-tip"/>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('Compression', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Compression', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="gzlogs">
                                <input name="gzlogs" type="checkbox" id="gzlogs"
                                       value="1" <?php 
        checked(get_site_option('backwpup_cfg_gzlogs'), TRUE);
        if (!function_exists('gzopen')) {
            echo " disabled=\"disabled\"";
        }
        ?>
 />
								<?php 
        _e('Compress log files with GZip.', 'backwpup');
        ?>
</label>
                        </fieldset>
                    </td>
                </tr>
            </table>

        </div>
        <div class="table ui-tabs-hide" id="backwpup-tab-job">

            <p><?php 
        _e('There are a couple of general options for backup jobs. Set them here.', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row">
                        <label for="jobstepretry"><?php 
        _e("Maximum number of retries for job steps", 'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="jobstepretry" type="text" id="jobstepretry"
                               value="<?php 
        echo get_site_option('backwpup_cfg_jobstepretry');
        ?>
"
                               class="small-text code" />
                    </td>
                </tr>
				<tr>
                    <th scope="row"><?php 
        _e('Maximum script execution time', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Maximum PHP Script execution time', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="jobmaxexecutiontime">
                                <input name="jobmaxexecutiontime" type="text" id="jobmaxexecutiontime" size="3" title="<?php 
        esc_attr_e('Job will restart before hitting maximum execution time. It will not work with CLI and not on every step during execution. If <code>ALTERNATE_WP_CRON</code> has been defined, WordPress Cron will be used.', 'backwpup');
        ?>
"
                                       value="<?php 
        echo get_site_option('backwpup_cfg_jobmaxexecutiontime');
        ?>
" class="help-tip" />
								<?php 
        _e('seconds. 0 = disabled.', 'backwpup');
        ?>
							</label>
                        </fieldset>
                    </td>
                </tr>
				<tr>
                    <th scope="row"><?php 
        _e('Method for creating ZIP-file archives', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Method for creating ZIP-file archives', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="jobziparchivemethod">
								<select name="jobziparchivemethod" size="1" class="help-tip" title="<?php 
        esc_attr_e('Auto = Uses PHP class ZipArchive if available; otherwise uses PclZip.<br />ZipArchive = Uses less memory, but many open files at a time.<br />PclZip = Uses more memory, but only 2 open files at a time.', 'backwpup');
        ?>
">
									<option value="" <?php 
        selected(get_site_option('backwpup_cfg_jobziparchivemethod'), '');
        ?>
><?php 
        _e('Auto', 'backwpup');
        ?>
</option>
                                    <option value="ZipArchive" <?php 
        selected(get_site_option('backwpup_cfg_jobziparchivemethod'), 'ZipArchive');
        disabled(function_exists('ZipArchive'), TRUE);
        ?>
><?php 
        _e('ZipArchive', 'backwpup');
        ?>
</option>
                                    <option value="PclZip" <?php 
        selected(get_site_option('backwpup_cfg_jobziparchivemethod'), 'PclZip');
        ?>
><?php 
        _e('PclZip', 'backwpup');
        ?>
</option>
                                </select>
                            </label>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        <label for="jobrunauthkey"><?php 
        _e('Key to start jobs externally with an URL', 'backwpup');
        ?>
</label>
                    </th>
                    <td>
                        <input name="jobrunauthkey" type="text" id="jobrunauthkey" title="<?php 
        esc_attr_e('empty = deactivated. Will be used to protect job starts from unauthorized person.', 'backwpup');
        ?>
"
                               value="<?php 
        echo get_site_option('backwpup_cfg_jobrunauthkey');
        ?>
" class="text code help-tip"/>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('No translation', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('No Translation', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="jobnotranslate">
                                <input name="jobnotranslate" type="checkbox" id="jobnotranslate"
                                       value="1" <?php 
        checked(get_site_option('backwpup_cfg_jobnotranslate'), TRUE);
        ?>
 />
								<?php 
        _e('No translation for the job, the log will be written in English', 'backwpup');
        ?>
                            </label>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('Reduce server load', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Reduce server load', 'backwpup');
        ?>
</span>
                            </legend>
                            <label for="jobwaittimems">
								<select name="jobwaittimems" size="1" class="help-tip" title="<?php 
        esc_attr_e('This adds short pauses to the process. Can be used to reduce the CPU load.<br /> Disabled = off<br /> minimum = shortest sleep<br /> medium = middle between minimum and maximum<br /> maximum = longest sleep<br />', 'backwpup');
        ?>
">
									<option value="0" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 0);
        ?>
><?php 
        _e('disabled', 'backwpup');
        ?>
</option>
                                    <option value="10000" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 10000);
        ?>
><?php 
        _e('minimum', 'backwpup');
        ?>
</option>
                                    <option value="30000" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 30000);
        ?>
><?php 
        _e('medium', 'backwpup');
        ?>
</option>
                                    <option value="90000" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 90000);
        ?>
><?php 
        _e('maximum', 'backwpup');
        ?>
</option>
                                </select>
                            </label>
                        </fieldset>
                    </td>
                </tr>
            </table>

        </div>

        <div class="table ui-tabs-hide" id="backwpup-tab-net">

			<h3 class="title"><?php 
        _e('Authentication', 'backwpup');
        ?>
</h3>
            <p><?php 
        _e('Is your blog protected with HTTP basic authentication (.htaccess)? If yes, please set the username and password for authentication here.', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><label for="httpauthuser"><?php 
        _e('Username:'******'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="httpauthuser" type="text" id="httpauthuser"
                               value="<?php 
        echo get_site_option('backwpup_cfg_httpauthuser');
        ?>
"
                               class="regular-text" autocomplete="off" />
                    </td>
                </tr>
                <tr>
                    <th scope="row"><label for="httpauthpassword"><?php 
        _e('Password:'******'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="httpauthpassword" type="password" id="httpauthpassword"
                               value="<?php 
        echo BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_httpauthpassword'));
        ?>
"
                               class="regular-text" autocomplete="off" />
                </tr>
            </table>

        </div>

        <div class="table ui-tabs-hide" id="backwpup-tab-apikey">

			<?php 
        do_action('backwpup_page_settings_tab_apikey');
        ?>

        </div>

        <div class="table ui-tabs-hide" id="backwpup-tab-information">
			<br />
			<?php 
        echo '<table class="wp-list-table widefat fixed" cellspacing="0" style="width: 85%;margin-left:auto;;margin-right:auto;">';
        echo '<thead><tr><th width="35%">' . __('Setting', 'backwpup') . '</th><th>' . __('Value', 'backwpup') . '</th></tr></thead>';
        echo '<tfoot><tr><th>' . __('Setting', 'backwpup') . '</th><th>' . __('Value', 'backwpup') . '</th></tr></tfoot>';
        echo '<tr title="&gt;=3.2"><td>' . __('WordPress version', 'backwpup') . '</td><td>' . BackWPup::get_plugin_data('wp_version') . '</td></tr>';
        if (!class_exists('BackWPup_Pro', FALSE)) {
            echo '<tr title=""><td>' . __('BackWPup version', 'backwpup') . '</td><td>' . BackWPup::get_plugin_data('Version') . ' <a href="' . translate(BackWPup::get_plugin_data('pluginuri'), 'backwpup') . '">' . __('Get pro.', 'backwpup') . '</a></td></tr>';
        } else {
            echo '<tr title=""><td>' . __('BackWPup Pro version', 'backwpup') . '</td><td>' . BackWPup::get_plugin_data('Version') . '</td></tr>';
        }
        echo '<tr title="&gt;=5.3.3"><td>' . __('PHP version', 'backwpup') . '</td><td>' . PHP_VERSION . '</td></tr>';
        echo '<tr title="&gt;=5.0.7"><td>' . __('MySQL version', 'backwpup') . '</td><td>' . $wpdb->get_var("SELECT VERSION() AS version") . '</td></tr>';
        if (function_exists('curl_version')) {
            $curlversion = curl_version();
            echo '<tr title=""><td>' . __('cURL version', 'backwpup') . '</td><td>' . $curlversion['version'] . '</td></tr>';
            echo '<tr title=""><td>' . __('cURL SSL version', 'backwpup') . '</td><td>' . $curlversion['ssl_version'] . '</td></tr>';
        } else {
            echo '<tr title=""><td>' . __('cURL version', 'backwpup') . '</td><td>' . __('unavailable', 'backwpup') . '</td></tr>';
        }
        echo '<tr title=""><td>' . __('WP-Cron url:', 'backwpup') . '</td><td>' . site_url('wp-cron.php') . '</td></tr>';
        //response test
        echo '<tr><td>' . __('Server self connect:', 'backwpup') . '</td><td>';
        $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));
        }
        $headers = wp_remote_retrieve_headers($raw_response);
        if (isset($headers['x-backwpup-ver']) && $headers['x-backwpup-ver'] != BackWPup::get_plugin_data('version')) {
            $test_result .= sprintf(__('The BackWPup HTTP response header returns a false value: "%s"', 'backwpup'), $headers['x-backwpup-ver']);
        }
        if (empty($test_result)) {
            _e('Response Test O.K.', 'backwpup');
        } else {
            echo $test_result;
        }
        echo '</td></tr>';
        //folder test
        echo '<tr><td>' . __('Temp folder:', 'backwpup') . '</td><td>';
        if (!is_dir(BackWPup::get_plugin_data('TEMP'))) {
            echo sprintf(__('Temp folder %s doesn\'t exist.', 'backwpup'), BackWPup::get_plugin_data('TEMP'));
        } elseif (!is_writable(BackWPup::get_plugin_data('TEMP'))) {
            echo sprintf(__('Temporary folder %s is not writable.', 'backwpup'), BackWPup::get_plugin_data('TEMP'));
        } else {
            echo BackWPup::get_plugin_data('TEMP');
        }
        echo '</td></tr>';
        echo '<tr><td>' . __('Log folder:', 'backwpup') . '</td><td>';
        if (!is_dir(get_site_option('backwpup_cfg_logfolder'))) {
            echo sprintf(__('Logs folder %s not exist.', 'backwpup'), get_site_option('backwpup_cfg_logfolder'));
        } elseif (!is_writable(get_site_option('backwpup_cfg_logfolder'))) {
            echo sprintf(__('Log folder %s is not writable.', 'backwpup'), get_site_option('backwpup_cfg_logfolder'));
        } else {
            echo get_site_option('backwpup_cfg_logfolder');
        }
        echo '</td></tr>';
        echo '<tr title=""><td>' . __('Server', 'backwpup') . '</td><td>' . $_SERVER['SERVER_SOFTWARE'] . '</td></tr>';
        echo '<tr title=""><td>' . __('Operating System', 'backwpup') . '</td><td>' . PHP_OS . '</td></tr>';
        echo '<tr title=""><td>' . __('PHP SAPI', 'backwpup') . '</td><td>' . PHP_SAPI . '</td></tr>';
        echo '<tr title=""><td>' . __('Current PHP user', 'backwpup') . '</td><td>' . get_current_user() . '</td></tr>';
        $text = (bool) ini_get('safe_mode') ? __('On', 'backwpup') : __('Off', 'backwpup');
        echo '<tr title=""><td>' . __('Safe Mode', 'backwpup') . '</td><td>' . $text . '</td></tr>';
        echo '<tr title="&gt;=30"><td>' . __('Maximum execution time', 'backwpup') . '</td><td>' . ini_get('max_execution_time') . ' ' . __('seconds', 'backwpup') . '</td></tr>';
        if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
            echo '<tr title="ALTERNATE_WP_CRON"><td>' . __('Alternative WP Cron', 'backwpup') . '</td><td>' . __('On', 'backwpup') . '</td></tr>';
        } else {
            echo '<tr title="ALTERNATE_WP_CRON"><td>' . __('Alternative WP Cron', 'backwpup') . '</td><td>' . __('Off', 'backwpup') . '</td></tr>';
        }
        if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
            echo '<tr title="DISABLE_WP_CRON"><td>' . __('Disabled WP Cron', 'backwpup') . '</td><td>' . __('On', 'backwpup') . '</td></tr>';
        } else {
            echo '<tr title="DISABLE_WP_CRON"><td>' . __('Disabled WP Cron', 'backwpup') . '</td><td>' . __('Off', 'backwpup') . '</td></tr>';
        }
        if (defined('FS_CHMOD_DIR')) {
            echo '<tr title="FS_CHMOD_DIR"><td>' . __('CHMOD Dir', 'backwpup') . '</td><td>' . FS_CHMOD_DIR . '</td></tr>';
        } else {
            echo '<tr title="FS_CHMOD_DIR"><td>' . __('CHMOD Dir', 'backwpup') . '</td><td>0755</td></tr>';
        }
        $now = localtime(time(), TRUE);
        echo '<tr title=""><td>' . __('Server Time', 'backwpup') . '</td><td>' . $now['tm_hour'] . ':' . $now['tm_min'] . '</td></tr>';
        echo '<tr title=""><td>' . __('Blog Time', 'backwpup') . '</td><td>' . date_i18n('H:i') . '</td></tr>';
        echo '<tr title=""><td>' . __('Blog Timezone', 'backwpup') . '</td><td>' . get_option('timezone_string') . '</td></tr>';
        echo '<tr title=""><td>' . __('Blog Time offset', 'backwpup') . '</td><td>' . sprintf(__('%s hours', 'backwpup'), get_option('gmt_offset')) . '</td></tr>';
        echo '<tr title="WPLANG"><td>' . __('Blog language', 'backwpup') . '</td><td>' . get_bloginfo('language') . '</td></tr>';
        echo '<tr title="utf8"><td>' . __('MySQL Client encoding', 'backwpup') . '</td><td>';
        echo defined('DB_CHARSET') ? DB_CHARSET : '';
        echo '</td></tr>';
        echo '<tr title="URF-8"><td>' . __('Blog charset', 'backwpup') . '</td><td>' . get_bloginfo('charset') . '</td></tr>';
        echo '<tr title="&gt;=128M"><td>' . __('PHP Memory limit', 'backwpup') . '</td><td>' . ini_get('memory_limit') . '</td></tr>';
        echo '<tr title="WP_MEMORY_LIMIT"><td>' . __('WP memory limit', 'backwpup') . '</td><td>' . WP_MEMORY_LIMIT . '</td></tr>';
        echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __('WP maximum memory limit', 'backwpup') . '</td><td>' . WP_MAX_MEMORY_LIMIT . '</td></tr>';
        echo '<tr title=""><td>' . __('Memory in use', 'backwpup') . '</td><td>' . size_format(@memory_get_usage(TRUE), 2) . '</td></tr>';
        //disabled PHP functions
        $disabled = ini_get('disable_functions');
        if (!empty($disabled)) {
            $disabledarry = explode(',', $disabled);
            echo '<tr title=""><td>' . __('Disabled PHP Functions:', 'backwpup') . '</td><td>';
            echo implode(', ', $disabledarry);
            echo '</td></tr>';
        }
        //Loaded PHP Extensions
        echo '<tr title=""><td>' . __('Loaded PHP Extensions:', 'backwpup') . '</td><td>';
        $extensions = get_loaded_extensions();
        sort($extensions);
        echo implode(', ', $extensions);
        echo '</td></tr>';
        echo '</table>';
        ?>
        </div>

		<?php 
        do_action('backwpup_page_settings_tab_content');
        ?>

        <p class="submit">
            <input type="submit" name="submit" id="submit" class="button-primary" value="<?php 
        _e('Save Changes', 'backwpup');
        ?>
" />
			&nbsp;
			<input type="submit" name="default_settings" id="default_settings" class="button-secondary" value="<?php 
        _e('Reset all settings to default', 'backwpup');
        ?>
" />
        </p>
    </form>
    </div>
	<?php 
    }
 /**
  * @param string $args
  */
 public function edit_ajax($args = '')
 {
     $error = '';
     if (is_array($args)) {
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         $args['rscusername'] = $_POST['rscusername'];
         $args['rscapikey'] = $_POST['rscapikey'];
         $args['rscselected'] = $_POST['rscselected'];
         $args['rscregion'] = $_POST['rscregion'];
         $ajax = TRUE;
     }
     echo '<span id="rsccontainererror" style="color:red;">';
     $container_list = array();
     if (!empty($args['rscusername']) && !empty($args['rscapikey']) && !empty($args['rscregion'])) {
         try {
             $conn = new OpenCloud\Rackspace(self::get_auth_url_by_region($args['rscregion']), array('username' => $args['rscusername'], 'apiKey' => BackWPup_Encryption::decrypt($args['rscapikey'])));
             $ostore = $conn->objectStoreService('cloudFiles', $args['rscregion'], 'publicURL');
             $containerlist = $ostore->listContainers();
             while ($container = $containerlist->next()) {
                 $container_list[] = $container->name;
             }
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['rscusername'])) {
         _e('Missing username!', 'backwpup');
     } elseif (empty($args['rscapikey'])) {
         _e('Missing API Key!', 'backwpup');
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (empty($container_list)) {
         _e("A container could not be found!", 'backwpup');
     }
     echo '</span>';
     if (!empty($container_list)) {
         echo '<select name="rsccontainer" id="rsccontainer">';
         foreach ($container_list as $container_name) {
             echo "<option " . selected(strtolower($args['rscselected']), strtolower($container_name), FALSE) . ">" . $container_name . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     } else {
         return;
     }
 }
Example #11
0
 /**
  * @param string $args
  */
 public function edit_ajax($args = '')
 {
     $error = '';
     $buckets_list = array();
     if (is_array($args)) {
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         $args['s3accesskey'] = sanitize_text_field($_POST['s3accesskey']);
         $args['s3secretkey'] = sanitize_text_field($_POST['s3secretkey']);
         $args['s3bucketselected'] = sanitize_text_field($_POST['s3bucketselected']);
         $args['s3base_url'] = esc_url_raw($_POST['s3base_url']);
         $args['s3region'] = sanitize_text_field($_POST['s3region']);
         $ajax = TRUE;
     }
     echo '<span id="s3bucketerror" style="color:red;">';
     if (!empty($args['s3accesskey']) && !empty($args['s3secretkey'])) {
         try {
             $s3 = Aws\S3\S3Client::factory(array('key' => $args['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($args['s3secretkey']), 'region' => $args['s3region'], 'base_url' => $this->get_s3_base_url($args['s3region'], $args['s3base_url']), 'scheme' => 'https', 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert')));
             $buckets = $s3->listBuckets();
             if (!empty($buckets['Buckets'])) {
                 $buckets_list = $buckets['Buckets'];
             }
             while (!empty($vaults['Marker'])) {
                 $buckets = $s3->listBuckets(array('marker' => $buckets['Marker']));
                 if (!empty($buckets['Buckets'])) {
                     $buckets_list = array_merge($buckets_list, $buckets['Buckets']);
                 }
             }
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['s3accesskey'])) {
         _e('Missing access key!', 'backwpup');
     } elseif (empty($args['s3secretkey'])) {
         _e('Missing secret access key!', 'backwpup');
     } elseif (!empty($error) && $error == 'Access Denied') {
         echo '<input type="text" name="s3bucket" id="s3bucket" value="' . esc_attr($args['s3bucketselected']) . '" >';
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (!isset($buckets) || count($buckets['Buckets']) < 1) {
         _e('No bucket found!', 'backwpup');
     }
     echo '</span>';
     if (!empty($buckets_list)) {
         echo '<select name="s3bucket" id="s3bucket">';
         foreach ($buckets_list as $bucket) {
             echo "<option " . selected($args['s3bucketselected'], esc_attr($bucket['Name']), FALSE) . ">" . esc_attr($bucket['Name']) . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     }
 }
    /**
     * Page Output
     */
    public static function page()
    {
        global $wpdb;
        ?>
    <div class="wrap" id="backwpup-page">
		<h1><?php 
        echo sprintf(__('%s &rsaquo; Settings', 'backwpup'), BackWPup::get_plugin_data('name'));
        ?>
</h1>
		<?php 
        $tabs = array('general' => __('General', 'backwpup'), 'job' => __('Jobs', 'backwpup'), 'log' => __('Logs', 'backwpup'), 'net' => __('Network', 'backwpup'), 'apikey' => __('API Keys', 'backwpup'), 'information' => __('Information', 'backwpup'));
        $tabs = apply_filters('backwpup_page_settings_tab', $tabs);
        echo '<h2 class="nav-tab-wrapper">';
        foreach ($tabs as $id => $name) {
            echo '<a href="#backwpup-tab-' . esc_attr($id) . '" class="nav-tab">' . esc_attr($name) . '</a>';
        }
        echo '</h2>';
        BackWPup_Admin::display_messages();
        ?>

    <form id="settingsform" action="<?php 
        echo admin_url('admin-post.php');
        ?>
" method="post">
		<?php 
        wp_nonce_field('backwpupsettings_page');
        ?>
        <input type="hidden" name="page" value="backwpupsettings" />
	    <input type="hidden" name="action" value="backwpup" />
    	<input type="hidden" name="anchor" value="#backwpup-tab-general" />

		<div class="table ui-tabs-hide" id="backwpup-tab-general">

			<h3 class="title"><?php 
        _e('Display Settings', 'backwpup');
        ?>
</h3>
            <p><?php 
        _e('Do you want to see BackWPup in the WordPress admin bar?', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><?php 
        _e('Admin bar', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Admin Bar', 'backwpup');
        ?>
</span></legend>
                            <label for="showadminbarmenu">
                                <input name="showadminbarmenu" type="checkbox" id="showadminbarmenu" value="1" <?php 
        checked(get_site_option('backwpup_cfg_showadminbar'), TRUE);
        ?>
 />
								<?php 
        _e('Show BackWPup links in admin bar.', 'backwpup');
        ?>
                            </label>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('Folder sizes', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Folder sizes', 'backwpup');
        ?>
</span></legend>
                            <label for="showfoldersize">
                                <input name="showfoldersize" type="checkbox" id="showfoldersize" value="1" <?php 
        checked(get_site_option('backwpup_cfg_showfoldersize'), TRUE);
        ?>
 />
								<?php 
        _e('Display folder sizes in the files tab when editing a job. (Might increase loading time of files tab.)', 'backwpup');
        ?>
                            </label>
                        </fieldset>
                    </td>
                </tr>
            </table>
			<h3 class="title"><?php 
        _e('Security', 'backwpup');
        ?>
</h3>
			<p><?php 
        _e('Security option for BackWPup', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><?php 
        _e('Protect folders', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Protect folders', 'backwpup');
        ?>
</span></legend>
                            <label for="protectfolders">
                                <input name="protectfolders" type="checkbox" id="protectfolders" value="1" <?php 
        checked(get_site_option('backwpup_cfg_protectfolders'), TRUE);
        ?>
 />
								<?php 
        _e('Protect BackWPup folders ( Temp, Log and Backups ) with <code>.htaccess</code> and <code>index.php</code>', 'backwpup');
        ?>
                            </label>
                        </fieldset>
                    </td>
                </tr>
            </table>

			<?php 
        do_action('backwpup_page_settings_tab_generel');
        ?>

		</div>

        <div class="table ui-tabs-hide" id="backwpup-tab-log">

            <p><?php 
        _e('Every time BackWPup runs a backup job, a log file is being generated. Choose where to store your log files and how many of them.', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><label for="logfolder"><?php 
        _e('Log file folder', 'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="logfolder" type="text" id="logfolder" value="<?php 
        echo esc_attr(get_site_option('backwpup_cfg_logfolder'));
        ?>
" class="regular-text code"/>
	                    <p class="description"><?php 
        echo sprintf(__('You can use absolute or relative path! Relative path is relative to %s.', 'backwpup'), '<code>' . trailingslashit(str_replace('\\', '/', WP_CONTENT_DIR)) . '</code>');
        ?>
</p>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><label for="maxlogs"><?php 
        _e('Maximum log files', 'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="maxlogs" type="number" min="0" step="1" id="maxlogs" value="<?php 
        echo absint(get_site_option('backwpup_cfg_maxlogs'));
        ?>
" class="small-text"/>
	                    <?php 
        _e('Maximum log files in folder.', 'backwpup');
        ?>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('Compression', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Compression', 'backwpup');
        ?>
</span></legend>
                            <label for="gzlogs">
                                <input name="gzlogs" type="checkbox" id="gzlogs" value="1" <?php 
        checked(get_site_option('backwpup_cfg_gzlogs'), TRUE);
        if (!function_exists('gzopen')) {
            echo ' disabled="disabled"';
        }
        ?>
 />
								<?php 
        _e('Compress log files with GZip.', 'backwpup');
        ?>
                            </label>
                        </fieldset>
                    </td>
                </tr>
	            <tr>
		            <th scope="row"><?php 
        _e('Logging Level', 'backwpup');
        ?>
</th>
		            <td>
			            <fieldset>
				            <legend class="screen-reader-text"><span><?php 
        _e('Logging Level', 'backwpup');
        ?>
</span></legend>
				            <label for="loglevel">
					            <select name="loglevel" size="1">
						            <option value="normal_translated" <?php 
        selected(get_site_option('backwpup_cfg_loglevel', 'normal_translated'), 'normal_translated');
        ?>
><?php 
        _e('Normal (translated)', 'backwpup');
        ?>
</option>
						            <option value="normal" <?php 
        selected(get_site_option('backwpup_cfg_loglevel'), 'normal');
        ?>
><?php 
        _e('Normal (not translated)', 'backwpup');
        ?>
</option>
						            <option value="debug_translated" <?php 
        selected(get_site_option('backwpup_cfg_loglevel'), 'debug_translated');
        ?>
><?php 
        _e('Debug (translated)', 'backwpup');
        ?>
</option>
						            <option value="debug" <?php 
        selected(get_site_option('backwpup_cfg_loglevel'), 'debug');
        ?>
><?php 
        _e('Debug (not translated)', 'backwpup');
        ?>
</option>
					            </select>
				            </label>
				            <p class="description"><?php 
        esc_attr_e('Debug log has much more informations than normal logs. It is for support and should be handled carefully. For support is the best to use a not translated log file. Usage of not translated logs can reduce the PHP memory usage too.', 'backwpup');
        ?>
</p>
			            </fieldset>
		            </td>
	            </tr>
            </table>

        </div>
        <div class="table ui-tabs-hide" id="backwpup-tab-job">

            <p><?php 
        _e('There are a couple of general options for backup jobs. Set them here.', 'backwpup');
        ?>
</p>
            <table class="form-table">
                <tr>
                    <th scope="row"><label for="jobstepretry"><?php 
        _e("Maximum number of retries for job steps", 'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="jobstepretry" type="number" min="1" step="1" max="99" id="jobstepretry" value="<?php 
        echo absint(get_site_option('backwpup_cfg_jobstepretry'));
        ?>
" class="small-text" />
                    </td>
                </tr>
				<tr>
                    <th scope="row"><?php 
        _e('Maximum script execution time', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Maximum PHP Script execution time', 'backwpup');
        ?>
</span></legend>
                            <label for="jobmaxexecutiontime">
                                <input name="jobmaxexecutiontime" type="number" min="0" step="1" max="300" id="jobmaxexecutiontime" value="<?php 
        echo absint(get_site_option('backwpup_cfg_jobmaxexecutiontime'));
        ?>
" class="small-text" />
								<?php 
        _e('seconds.', 'backwpup');
        ?>
	                            <p class="description"><?php 
        _e('Job will restart before hitting maximum execution time. Restarts will be disabled on CLI usage. If <code>ALTERNATE_WP_CRON</code> has been defined, WordPress Cron will be used for restarts, so it can take a while. 0 means no maximum.', 'backwpup');
        ?>
</p>
							</label>
                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        <label for="jobrunauthkey"><?php 
        _e('Key to start jobs externally with an URL', 'backwpup');
        ?>
</label>
                    </th>
                    <td>
                        <input name="jobrunauthkey" type="text" id="jobrunauthkey" value="<?php 
        echo esc_attr(get_site_option('backwpup_cfg_jobrunauthkey'));
        ?>
" class="text code"/>
	                    <p class="description"><?php 
        _e('Will be used to protect job starts from unauthorized person.', 'backwpup');
        ?>
</p>
                    </td>
                </tr>
                <tr>
                    <th scope="row"><?php 
        _e('Reduce server load', 'backwpup');
        ?>
</th>
                    <td>
                        <fieldset>
                            <legend class="screen-reader-text"><span><?php 
        _e('Reduce server load', 'backwpup');
        ?>
</span></legend>
                            <label for="jobwaittimems">
								<select name="jobwaittimems" size="1">
									<option value="0" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 0);
        ?>
><?php 
        _e('disabled', 'backwpup');
        ?>
</option>
                                    <option value="10000" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 10000);
        ?>
><?php 
        _e('minimum', 'backwpup');
        ?>
</option>
                                    <option value="30000" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 30000);
        ?>
><?php 
        _e('medium', 'backwpup');
        ?>
</option>
                                    <option value="90000" <?php 
        selected(get_site_option('backwpup_cfg_jobwaittimems'), 90000);
        ?>
><?php 
        _e('maximum', 'backwpup');
        ?>
</option>
                                </select>
                            </label>
	                        <p class="description"><?php 
        _e('This adds short pauses to the process. Can be used to reduce the CPU load.', 'backwpup');
        ?>
</p>
                        </fieldset>
                    </td>
                </tr>
	            <tr>
		            <th scope="row"><?php 
        _e('Empty output on working', 'backwpup');
        ?>
</th>
		            <td>
			            <fieldset>
				            <legend class="screen-reader-text"><span><?php 
        _e('Enable an empty Output on backup working.', 'backwpup');
        ?>
</span></legend>
				            <label for="jobdooutput">
					            <input name="jobdooutput" type="checkbox" id="jobdooutput" value="1" <?php 
        checked(get_site_option('backwpup_cfg_jobdooutput'), TRUE);
        ?>
 />
					            <?php 
        _e('Enable an empty Output on backup working.', 'backwpup');
        ?>
				            </label>
				            <p class="description"><?php 
        _e('This do an empty output on job working. This can help in some situations or can brake the working. You must test it.', 'backwpup');
        ?>
</p>
			            </fieldset>
		            </td>
	            </tr>
            </table>

        </div>

        <div class="table ui-tabs-hide" id="backwpup-tab-net">

			<h3><?php 
        echo sprintf(__('Authentication for <code>%s</code>', 'backwpup'), site_url('wp-cron.php'));
        ?>
</h3>
            <p><?php 
        _e('If you protected your blog with HTTP basic authentication (.htaccess), or you use a Plugin to secure wp-cron.php, then use the authentication methods below.', 'backwpup');
        ?>
</p>
            <?php 
        $authentication = get_site_option('backwpup_cfg_authentication', array('method' => '', 'basic_user' => '', 'basic_password' => '', 'user_id' => 0, 'query_arg' => ''));
        ?>
	        <table class="form-table">
	            <tr>
		            <th scope="row"><?php 
        _e('Authentication method', 'backwpup');
        ?>
</th>
		            <td>
			            <fieldset>
				            <legend class="screen-reader-text"><span><?php 
        _e('Authentication method', 'backwpup');
        ?>
</span></legend>
				            <label for="authentication_method">
					            <select name="authentication_method" id="authentication_method" size="1" >
						            <option value="" <?php 
        selected($authentication['method'], '');
        ?>
><?php 
        _e('none', 'backwpup');
        ?>
</option>
						            <option value="basic" <?php 
        selected($authentication['method'], 'basic');
        ?>
><?php 
        _e('Basic auth', 'backwpup');
        ?>
</option>
						            <option value="user" <?php 
        selected($authentication['method'], 'user');
        ?>
><?php 
        _e('WordPress User', 'backwpup');
        ?>
</option>
						            <option value="query_arg" <?php 
        selected($authentication['method'], 'query_arg');
        ?>
><?php 
        _e('Query argument', 'backwpup');
        ?>
</option>
					            </select>
				            </label>
			            </fieldset>
		            </td>
	            </tr>
                <tr class="authentication_basic" <?php 
        if ($authentication['method'] !== 'basic') {
            echo 'style="display:none"';
        }
        ?>
>
                    <th scope="row"><label for="authentication_basic_user"><?php 
        _e('Basic Auth Username:'******'backwpup');
        ?>
</label></th>
                    <td>
                        <input name="authentication_basic_user" type="text" id="authentication_basic_user" value="<?php 
        echo esc_attr($authentication['basic_user']);
        ?>
" class="regular-text" autocomplete="off" />
                    </td>
                </tr>
                <tr class="authentication_basic" <?php 
        if ($authentication['method'] !== 'basic') {
            echo 'style="display:none"';
        }
        ?>
>
			        <th scope="row"><label for="authentication_basic_password"><?php 
        _e('Basic Auth Password:'******'backwpup');
        ?>
</label></th>
			        <td>
				        <input name="authentication_basic_password" type="password" id="authentication_basic_password" value="<?php 
        echo esc_attr(BackWPup_Encryption::decrypt($authentication['basic_password']));
        ?>
" class="regular-text" autocomplete="off" />
		        </tr>
		        <tr class="authentication_user" <?php 
        if ($authentication['method'] !== 'user') {
            echo 'style="display:none"';
        }
        ?>
>
			        <th scope="row"><?php 
        _e('Select WordPress User', 'backwpup');
        ?>
</th>
			        <td>
				        <fieldset>
					        <legend class="screen-reader-text"><span><?php 
        _e('Select WordPress User', 'backwpup');
        ?>
</span>
					        </legend>
					        <label for="authentication_user_id">
						        <select name="authentication_user_id" size="1" >
							        <?php 
        $users = get_users(array('who' => 'administrators', 'number' => 99, 'orderby' => 'display_name'));
        foreach ($users as $user) {
            echo '<option value="' . $user->ID . '" ' . selected($authentication['user_id'], $user->ID, FALSE) . '>' . esc_attr($user->display_name) . '</option>';
        }
        ?>
						        </select>
					        </label>
				        </fieldset>
			        </td>
		        </tr>
		        <tr class="authentication_query_arg" <?php 
        if ($authentication['method'] != 'query_arg') {
            echo 'style="display:none"';
        }
        ?>
>
			        <th scope="row"><label for="authentication_query_arg"><?php 
        _e('Query arg key=value:', 'backwpup');
        ?>
</label></th>
			        <td>
				        ?<input name="authentication_query_arg" type="text" id="authentication_query_arg" value="<?php 
        echo esc_attr($authentication['query_arg']);
        ?>
" class="regular-text" />
			        </td>
		        </tr>
            </table>

        </div>

        <div class="table ui-tabs-hide" id="backwpup-tab-apikey">

			<?php 
        do_action('backwpup_page_settings_tab_apikey');
        ?>

        </div>

        <div class="table ui-tabs-hide" id="backwpup-tab-information">
			<br />
			<?php 
        echo '<table class="wp-list-table widefat fixed" cellspacing="0" style="width:85%;margin-left:auto;margin-right:auto;">';
        echo '<thead><tr><th width="35%">' . __('Setting', 'backwpup') . '</th><th>' . __('Value', 'backwpup') . '</th></tr></thead>';
        echo '<tfoot><tr><th>' . __('Setting', 'backwpup') . '</th><th>' . __('Value', 'backwpup') . '</th></tr></tfoot>';
        echo '<tr title="&gt;=3.2"><td>' . __('WordPress version', 'backwpup') . '</td><td>' . esc_html(BackWPup::get_plugin_data('wp_version')) . '</td></tr>';
        if (!class_exists('BackWPup_Pro', FALSE)) {
            echo '<tr title=""><td>' . __('BackWPup version', 'backwpup') . '</td><td>' . esc_html(BackWPup::get_plugin_data('Version')) . ' <a href="' . __('http://backwpup.com', 'backwpup') . '">' . __('Get pro.', 'backwpup') . '</a></td></tr>';
        } else {
            echo '<tr title=""><td>' . __('BackWPup Pro version', 'backwpup') . '</td><td>' . esc_html(BackWPup::get_plugin_data('Version')) . '</td></tr>';
        }
        $bit = '';
        if (PHP_INT_SIZE === 4) {
            $bit = ' (32bit)';
        }
        if (PHP_INT_SIZE === 8) {
            $bit = ' (64bit)';
        }
        echo '<tr title="&gt;=5.3.3"><td>' . __('PHP version', 'backwpup') . '</td><td>' . esc_html(PHP_VERSION . ' ' . $bit) . '</td></tr>';
        echo '<tr title="&gt;=5.0.7"><td>' . __('MySQL version', 'backwpup') . '</td><td>' . esc_html($wpdb->get_var("SELECT VERSION() AS version")) . '</td></tr>';
        if (function_exists('curl_version')) {
            $curlversion = curl_version();
            echo '<tr title=""><td>' . __('cURL version', 'backwpup') . '</td><td>' . esc_html($curlversion['version']) . '</td></tr>';
            echo '<tr title=""><td>' . __('cURL SSL version', 'backwpup') . '</td><td>' . esc_html($curlversion['ssl_version']) . '</td></tr>';
        } else {
            echo '<tr title=""><td>' . __('cURL version', 'backwpup') . '</td><td>' . __('unavailable', 'backwpup') . '</td></tr>';
        }
        echo '<tr title=""><td>' . __('WP-Cron url:', 'backwpup') . '</td><td>' . site_url('wp-cron.php') . '</td></tr>';
        //response test
        echo '<tr><td>' . __('Server self connect:', 'backwpup') . '</td><td>';
        $raw_response = BackWPup_Job::get_jobrun_url('test');
        $response_code = wp_remote_retrieve_response_code($raw_response);
        $response_body = wp_remote_retrieve_body($raw_response);
        if (strstr($response_body, 'BackWPup test request') === false) {
            $test_result = __('<strong>Not expected HTTP response:</strong><br>', 'backwpup');
            if (!$response_code) {
                $test_result .= sprintf(__('WP Http Error: <code>%s</code>', 'backwpup'), esc_html($raw_response->get_error_message())) . '<br>';
            } else {
                $test_result .= sprintf(__('Status-Code: <code>%d</code>', 'backwpup'), esc_html($response_code)) . '<br>';
            }
            $response_headers = wp_remote_retrieve_headers($raw_response);
            foreach ($response_headers as $key => $value) {
                $test_result .= esc_html(ucfirst($key)) . ': <code>' . esc_html($value) . '</code><br>';
            }
            $content = esc_html(wp_remote_retrieve_body($raw_response));
            if ($content) {
                $test_result .= sprintf(__('Content: <code>%s</code>', 'backwpup'), $content);
            }
            echo $test_result;
        } else {
            _e('Response Test O.K.', 'backwpup');
        }
        echo '</td></tr>';
        //folder test
        echo '<tr><td>' . __('Temp folder:', 'backwpup') . '</td><td>';
        if (!is_dir(BackWPup::get_plugin_data('TEMP'))) {
            echo sprintf(__('Temp folder %s doesn\'t exist.', 'backwpup'), esc_html(BackWPup::get_plugin_data('TEMP')));
        } elseif (!is_writable(BackWPup::get_plugin_data('TEMP'))) {
            echo sprintf(__('Temporary folder %s is not writable.', 'backwpup'), esc_html(BackWPup::get_plugin_data('TEMP')));
        } else {
            echo esc_html(BackWPup::get_plugin_data('TEMP'));
        }
        echo '</td></tr>';
        $log_folder = esc_html(get_site_option('backwpup_cfg_logfolder'));
        $log_folder = BackWPup_File::get_absolute_path($log_folder);
        echo '<tr><td>' . __('Log folder:', 'backwpup') . '</td><td>';
        if (!is_dir($log_folder)) {
            echo sprintf(__('Logs folder %s not exist.', 'backwpup'), $log_folder);
        } elseif (!is_writable($log_folder)) {
            echo sprintf(__('Log folder %s is not writable.', 'backwpup'), $log_folder);
        } else {
            echo $log_folder;
        }
        echo '</td></tr>';
        echo '<tr title=""><td>' . __('Server', 'backwpup') . '</td><td>' . esc_html($_SERVER['SERVER_SOFTWARE']) . '</td></tr>';
        echo '<tr title=""><td>' . __('Operating System', 'backwpup') . '</td><td>' . esc_html(PHP_OS) . '</td></tr>';
        echo '<tr title=""><td>' . __('PHP SAPI', 'backwpup') . '</td><td>' . esc_html(PHP_SAPI) . '</td></tr>';
        $php_user = __('Function Disabled', 'backwpup');
        if (function_exists('get_current_user')) {
            $php_user = get_current_user();
        }
        echo '<tr title=""><td>' . __('Current PHP user', 'backwpup') . '</td><td>' . esc_html($php_user) . '</td></tr>';
        echo '<tr title="&gt;=30"><td>' . __('Maximum execution time', 'backwpup') . '</td><td>' . esc_html(ini_get('max_execution_time')) . ' ' . __('seconds', 'backwpup') . '</td></tr>';
        if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
            echo '<tr title="ALTERNATE_WP_CRON"><td>' . __('Alternative WP Cron', 'backwpup') . '</td><td>' . __('On', 'backwpup') . '</td></tr>';
        } else {
            echo '<tr title="ALTERNATE_WP_CRON"><td>' . __('Alternative WP Cron', 'backwpup') . '</td><td>' . __('Off', 'backwpup') . '</td></tr>';
        }
        if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
            echo '<tr title="DISABLE_WP_CRON"><td>' . __('Disabled WP Cron', 'backwpup') . '</td><td>' . __('On', 'backwpup') . '</td></tr>';
        } else {
            echo '<tr title="DISABLE_WP_CRON"><td>' . __('Disabled WP Cron', 'backwpup') . '</td><td>' . __('Off', 'backwpup') . '</td></tr>';
        }
        if (defined('FS_CHMOD_DIR')) {
            echo '<tr title="FS_CHMOD_DIR"><td>' . __('CHMOD Dir', 'backwpup') . '</td><td>' . esc_html(FS_CHMOD_DIR) . '</td></tr>';
        } else {
            echo '<tr title="FS_CHMOD_DIR"><td>' . __('CHMOD Dir', 'backwpup') . '</td><td>0755</td></tr>';
        }
        $now = localtime(time(), TRUE);
        echo '<tr title=""><td>' . __('Server Time', 'backwpup') . '</td><td>' . esc_html($now['tm_hour'] . ':' . $now['tm_min']) . '</td></tr>';
        echo '<tr title=""><td>' . __('Blog Time', 'backwpup') . '</td><td>' . date('H:i', current_time('timestamp')) . '</td></tr>';
        echo '<tr title=""><td>' . __('Blog Timezone', 'backwpup') . '</td><td>' . esc_html(get_option('timezone_string')) . '</td></tr>';
        echo '<tr title=""><td>' . __('Blog Time offset', 'backwpup') . '</td><td>' . sprintf(__('%s hours', 'backwpup'), (int) get_option('gmt_offset')) . '</td></tr>';
        echo '<tr title="WPLANG"><td>' . __('Blog language', 'backwpup') . '</td><td>' . get_bloginfo('language') . '</td></tr>';
        echo '<tr title="utf8"><td>' . __('MySQL Client encoding', 'backwpup') . '</td><td>';
        echo defined('DB_CHARSET') ? DB_CHARSET : '';
        echo '</td></tr>';
        echo '<tr title="URF-8"><td>' . __('Blog charset', 'backwpup') . '</td><td>' . get_bloginfo('charset') . '</td></tr>';
        echo '<tr title="&gt;=128M"><td>' . __('PHP Memory limit', 'backwpup') . '</td><td>' . esc_html(ini_get('memory_limit')) . '</td></tr>';
        echo '<tr title="WP_MEMORY_LIMIT"><td>' . __('WP memory limit', 'backwpup') . '</td><td>' . esc_html(WP_MEMORY_LIMIT) . '</td></tr>';
        echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __('WP maximum memory limit', 'backwpup') . '</td><td>' . esc_html(WP_MAX_MEMORY_LIMIT) . '</td></tr>';
        echo '<tr title=""><td>' . __('Memory in use', 'backwpup') . '</td><td>' . size_format(@memory_get_usage(TRUE), 2) . '</td></tr>';
        //disabled PHP functions
        $disabled = esc_html(ini_get('disable_functions'));
        if (!empty($disabled)) {
            $disabledarry = explode(',', $disabled);
            echo '<tr title=""><td>' . __('Disabled PHP Functions:', 'backwpup') . '</td><td>';
            echo implode(', ', $disabledarry);
            echo '</td></tr>';
        }
        //Loaded PHP Extensions
        echo '<tr title=""><td>' . __('Loaded PHP Extensions:', 'backwpup') . '</td><td>';
        $extensions = get_loaded_extensions();
        sort($extensions);
        echo esc_html(implode(', ', $extensions));
        echo '</td></tr>';
        echo '</table>';
        ?>
        </div>

		<?php 
        do_action('backwpup_page_settings_tab_content');
        ?>

        <p class="submit">
            <input type="submit" name="submit" id="submit" class="button-primary" value="<?php 
        _e('Save Changes', 'backwpup');
        ?>
" />
			&nbsp;
			<input type="submit" name="default_settings" id="default_settings" class="button-secondary" value="<?php 
        _e('Reset all settings to default', 'backwpup');
        ?>
" />
        </p>
    </form>
    </div>
	<?php 
    }
Example #13
0
 /**
  *
  * Get a url to run a job of BackWPup
  *
  * @param string     $starttype Start types are 'runnow', 'runnowlink', 'cronrun', 'runext', 'restart', 'test'
  * @param int        $jobid     The id of job to start else 0
  * @return array|object [url] is the job url [header] for auth header or object form wp_remote_get()
  */
 public static function get_jobrun_url($starttype, $jobid = 0)
 {
     $wp_admin_user = get_users(array('role' => 'backwpup_admin', 'number' => 1));
     //get a user for cookie auth
     $url = site_url('wp-cron.php');
     $header = array();
     $authurl = '';
     $query_args = array('_nonce' => substr(wp_hash(wp_nonce_tick() . 'backwpup_job_run-' . $starttype, 'nonce'), -12, 10), 'doing_wp_cron' => sprintf('%.22F', microtime(true)));
     if (in_array($starttype, array('restart', 'runnow', 'cronrun', 'runext', 'test'))) {
         $query_args['backwpup_run'] = $starttype;
     }
     if (in_array($starttype, array('runnowlink', 'runnow', 'cronrun', 'runext')) && !empty($jobid)) {
         $query_args['jobid'] = $jobid;
     }
     if (get_site_option('backwpup_cfg_httpauthuser') && get_site_option('backwpup_cfg_httpauthpassword')) {
         $header['Authorization'] = 'Basic ' . base64_encode(get_site_option('backwpup_cfg_httpauthuser') . ':' . BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_httpauthpassword')));
         $authurl = get_site_option('backwpup_cfg_httpauthuser') . ':' . BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_httpauthpassword')) . '@';
     }
     if ($starttype == 'runext') {
         $query_args['_nonce'] = get_site_option('backwpup_cfg_jobrunauthkey');
         $query_args['doing_wp_cron'] = NULL;
         if (!empty($authurl)) {
             $url = str_replace('https://', 'https://' . $authurl, $url);
             $url = str_replace('http://', 'http://' . $authurl, $url);
         }
     }
     if ($starttype == 'runnowlink' && (!defined('ALTERNATE_WP_CRON') || !ALTERNATE_WP_CRON)) {
         $url = wp_nonce_url(network_admin_url('admin.php'), 'backwpup_job_run-' . $starttype);
         $query_args['page'] = 'backwpupjobs';
         $query_args['action'] = 'runnow';
         $query_args['doing_wp_cron'] = NULL;
         unset($query_args['_nonce']);
     }
     if ($starttype == 'runnowlink' && defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
         $query_args['backwpup_run'] = 'runnowalt';
         $query_args['_nonce'] = substr(wp_hash(wp_nonce_tick() . 'backwpup_job_run-runnowalt', 'nonce'), -12, 10);
         $query_args['doing_wp_cron'] = NULL;
     }
     //Extra for WP-Cron control
     if (class_exists('WP_Cron_Control') && ($starttype == 'runext' || $starttype == 'runnow' || $starttype == 'restart')) {
         $wp_cron_control_settings = get_option('wpcroncontrol_settings', array());
         if (empty($wp_cron_control_settings['secret_string']) && file_exists(WP_PLUGIN_DIR . '/wp-cron-control/wp-cron-control.php')) {
             $wp_cron_control_settings['secret_string'] = md5(realpath(WP_PLUGIN_DIR . '/wp-cron-control/wp-cron-control.php') . get_current_blog_id());
             $wp_cron_control_settings['enable'] = 1;
         }
         if (isset($wp_cron_control_settings['enable']) && $wp_cron_control_settings['enable'] == 1) {
             if (defined('WP_CRON_CONTROL_SECRET')) {
                 $wp_cron_control_settings['secret_string'] = WP_CRON_CONTROL_SECRET;
             }
             $query_args[$wp_cron_control_settings['secret_string']] = '';
             $query_args['doing_wp_cron'] = NULL;
         }
     }
     $cron_request = apply_filters('cron_request', array('url' => add_query_arg($query_args, $url), 'key' => $query_args['doing_wp_cron'], 'args' => array('blocking' => FALSE, 'sslverify' => apply_filters('https_local_ssl_verify', true), 'timeout' => 0.01, 'headers' => $header, 'cookies' => array(new WP_Http_Cookie(array('name' => AUTH_COOKIE, 'value' => wp_generate_auth_cookie($wp_admin_user[0]->ID, time() + 300, 'auth'))), new WP_Http_Cookie(array('name' => LOGGED_IN_COOKIE, 'value' => wp_generate_auth_cookie($wp_admin_user[0]->ID, time() + 300, 'logged_in')))), 'user-agent' => BackWpup::get_plugin_data('User-Agent'))));
     if ($starttype == 'test') {
         $cron_request['args']['timeout'] = 15;
         $cron_request['args']['blocking'] = TRUE;
     }
     if (!in_array($starttype, array('runnowlink', 'runext'))) {
         set_transient('doing_cron', $query_args['doing_wp_cron']);
         return wp_remote_post($cron_request['url'], $cron_request['args']);
     }
     return $cron_request;
 }
 /**
  * @param string $boxtype
  * @throws BackWPup_Destination_Dropbox_API_Exception
  */
 public function __construct($boxtype = 'dropbox')
 {
     if ($boxtype == 'dropbox') {
         $this->oauth_app_key = get_site_option('backwpup_cfg_dropboxappkey');
         $this->oauth_app_secret = BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_dropboxappsecret'));
         $this->root = 'dropbox';
     } else {
         $this->oauth_app_key = get_site_option('backwpup_cfg_dropboxsandboxappkey');
         $this->oauth_app_secret = BackWPup_Encryption::decrypt(get_site_option('backwpup_cfg_dropboxsandboxappsecret'));
         $this->root = 'sandbox';
     }
     if (empty($this->oauth_app_key) or empty($this->oauth_app_secret)) {
         throw new BackWPup_Destination_Dropbox_API_Exception("No App key or App Secret specified.");
     }
 }
 /**
  * @param $job_object BAckWPup_Job
  * @return bool
  */
 public function job_run_archive(BackWPup_Job $job_object)
 {
     $job_object->substeps_todo = 2 + $job_object->backup_filesize;
     if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
         $job_object->log(sprintf(__('%d. Trying to send backup file to S3 Service&#160;&hellip;', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
     }
     try {
         $s3 = Aws\S3\S3Client::factory(array('key' => $job_object->job['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($job_object->job['s3secretkey']), 'region' => $job_object->job['s3region'], 'base_url' => $this->get_s3_base_url($job_object->job['s3region'], $job_object->job['s3base_url']), 'scheme' => 'https', 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert')));
         if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY'] && $job_object->substeps_done < $job_object->backup_filesize) {
             if ($s3->doesBucketExist($job_object->job['s3bucket'])) {
                 $bucketregion = $s3->getBucketLocation(array('Bucket' => $job_object->job['s3bucket']));
                 $job_object->log(sprintf(__('Connected to S3 Bucket "%1$s" in %2$s', 'backwpup'), $job_object->job['s3bucket'], $bucketregion->get('Location')), E_USER_NOTICE);
             } else {
                 $job_object->log(sprintf(__('S3 Bucket "%s" does not exist!', 'backwpup'), $job_object->job['s3bucket']), E_USER_ERROR);
                 return TRUE;
             }
             if ($job_object->job['s3multipart'] && empty($job_object->steps_data[$job_object->step_working]['UploadId'])) {
                 //Check for aboded Multipart Uploads
                 $job_object->log(__('Checking for not aborted multipart Uploads&#160;&hellip;', 'backwpup'));
                 $multipart_uploads = $s3->listMultipartUploads(array('Bucket' => $job_object->job['s3bucket'], 'Prefix' => (string) $job_object->job['s3dir']));
                 $uploads = $multipart_uploads->get('Uploads');
                 if (!empty($uploads)) {
                     foreach ($uploads as $upload) {
                         $s3->abortMultipartUpload(array('Bucket' => $job_object->job['s3bucket'], 'Key' => $upload['Key'], 'UploadId' => $upload['UploadId']));
                         $job_object->log(sprintf(__('Upload for %s aborted.', 'backwpup'), $upload['Key']));
                     }
                 }
             }
             //transfer file to S3
             $job_object->log(__('Starting upload to S3 Service&#160;&hellip;', 'backwpup'));
         }
         if (!$job_object->job['s3multipart'] || $job_object->backup_filesize < 1048576 * 6) {
             //Prepare Upload
             if (!($up_file_handle = fopen($job_object->backup_folder . $job_object->backup_file, 'rb'))) {
                 $job_object->log(__('Can not open source file for transfer.', 'backwpup'), E_USER_ERROR);
                 return FALSE;
             }
             $create_args = array();
             $create_args['Bucket'] = $job_object->job['s3bucket'];
             $create_args['ACL'] = 'private';
             //encrxption
             if (!empty($job_object->job['s3ssencrypt'])) {
                 $create_args['ServerSideEncryption'] = $job_object->job['s3ssencrypt'];
             }
             //Storage Class
             if (!empty($job_object->job['s3storageclass'])) {
                 $create_args['StorageClass'] = $job_object->job['s3storageclass'];
             }
             $create_args['Metadata'] = array('BackupTime' => date('Y-m-d H:i:s', $job_object->start_time));
             $create_args['Body'] = $up_file_handle;
             $create_args['Key'] = $job_object->job['s3dir'] . $job_object->backup_file;
             $create_args['ContentType'] = $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file);
             try {
                 $s3->putObject($create_args);
             } catch (Aws\Common\Exception\MultipartUploadException $e) {
                 $job_object->log(E_USER_ERROR, sprintf(__('S3 Service API: %s', 'backwpup'), $e->getMessage()), $e->getFile(), $e->getLine());
                 return FALSE;
             }
         } else {
             //Prepare Upload
             if ($file_handle = fopen($job_object->backup_folder . $job_object->backup_file, 'rb')) {
                 fseek($file_handle, $job_object->substeps_done);
                 try {
                     if (empty($job_object->steps_data[$job_object->step_working]['UploadId'])) {
                         $args = array('ACL' => 'private', 'Bucket' => $job_object->job['s3bucket'], 'ContentType' => $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file), 'Key' => $job_object->job['s3dir'] . $job_object->backup_file);
                         if (!empty($job_object->job['s3ssencrypt'])) {
                             $args['ServerSideEncryption'] = $job_object->job['s3ssencrypt'];
                         }
                         if (!empty($job_object->job['s3storageclass'])) {
                             $args['StorageClass'] = empty($job_object->job['s3storageclass']) ? '' : $job_object->job['s3storageclass'];
                         }
                         $upload = $s3->createMultipartUpload($args);
                         $job_object->steps_data[$job_object->step_working]['UploadId'] = $upload->get('UploadId');
                         $job_object->steps_data[$job_object->step_working]['Parts'] = array();
                         $job_object->steps_data[$job_object->step_working]['Part'] = 1;
                     }
                     while (!feof($file_handle)) {
                         $chunk_upload_start = microtime(TRUE);
                         $part_data = fread($file_handle, 1048576 * 5);
                         //5MB Minimum part size
                         $part = $s3->uploadPart(array('Bucket' => $job_object->job['s3bucket'], 'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file, 'PartNumber' => $job_object->steps_data[$job_object->step_working]['Part'], 'Body' => $part_data));
                         $chunk_upload_time = microtime(TRUE) - $chunk_upload_start;
                         $job_object->substeps_done = $job_object->substeps_done + strlen($part_data);
                         $job_object->steps_data[$job_object->step_working]['Parts'][] = array('ETag' => $part->get('ETag'), 'PartNumber' => $job_object->steps_data[$job_object->step_working]['Part']);
                         $job_object->steps_data[$job_object->step_working]['Part']++;
                         $time_remaining = $job_object->do_restart_time();
                         if ($time_remaining < $chunk_upload_time) {
                             $job_object->do_restart_time(TRUE);
                         }
                         $job_object->update_working_data();
                     }
                     $s3->completeMultipartUpload(array('Bucket' => $job_object->job['s3bucket'], 'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file, 'Parts' => $job_object->steps_data[$job_object->step_working]['Parts']));
                 } catch (Exception $e) {
                     $job_object->log(E_USER_ERROR, sprintf(__('S3 Service API: %s', 'backwpup'), $e->getMessage()), $e->getFile(), $e->getLine());
                     if (!empty($job_object->steps_data[$job_object->step_working]['uploadId'])) {
                         $s3->abortMultipartUpload(array('Bucket' => $job_object->job['s3bucket'], 'UploadId' => $job_object->steps_data[$job_object->step_working]['uploadId'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file));
                     }
                     unset($job_object->steps_data[$job_object->step_working]['UploadId']);
                     unset($job_object->steps_data[$job_object->step_working]['Parts']);
                     unset($job_object->steps_data[$job_object->step_working]['Part']);
                     $job_object->substeps_done = 0;
                     if (is_resource($file_handle)) {
                         fclose($file_handle);
                     }
                     return FALSE;
                 }
                 fclose($file_handle);
             } else {
                 $job_object->log(__('Can not open source file for transfer.', 'backwpup'), E_USER_ERROR);
                 return FALSE;
             }
         }
         $result = $s3->headObject(array('Bucket' => $job_object->job['s3bucket'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file));
         if ($result->get('ContentLength') == filesize($job_object->backup_folder . $job_object->backup_file)) {
             $job_object->substeps_done = 1 + $job_object->backup_filesize;
             $job_object->log(sprintf(__('Backup transferred to %s.', 'backwpup'), $this->get_s3_base_url($job_object->job['s3region'], $job_object->job['s3base_url']) . '/' . $job_object->job['s3bucket'] . '/' . $job_object->job['s3dir'] . $job_object->backup_file), E_USER_NOTICE);
             if (!empty($job_object->job['jobid'])) {
                 BackWPup_Option::update($job_object->job['jobid'], 'lastbackupdownloadurl', network_admin_url('admin.php') . '?page=backwpupbackups&action=downloads3&file=' . $job_object->job['s3dir'] . $job_object->backup_file . '&jobid=' . $job_object->job['jobid']);
             }
         } else {
             $job_object->log(sprintf(__('Cannot transfer backup to S3! (%1$d) %2$s', 'backwpup'), $result->get("status"), $result->get("Message")), E_USER_ERROR);
         }
     } catch (Exception $e) {
         $job_object->log(E_USER_ERROR, sprintf(__('S3 Service API: %s', 'backwpup'), $e->getMessage()), $e->getFile(), $e->getLine());
         return FALSE;
     }
     try {
         $backupfilelist = array();
         $filecounter = 0;
         $files = array();
         $args = array('Bucket' => $job_object->job['s3bucket'], 'Prefix' => (string) $job_object->job['s3dir']);
         $objects = $s3->getIterator('ListObjects', $args);
         if (is_object($objects)) {
             foreach ($objects as $object) {
                 $file = basename($object['Key']);
                 $changetime = strtotime($object['LastModified']) + get_option('gmt_offset') * 3600;
                 if ($job_object->is_backup_archive($file)) {
                     $backupfilelist[$changetime] = $file;
                 }
                 $files[$filecounter]['folder'] = $this->get_s3_base_url($job_object->job['s3region'], $job_object->job['s3base_url']) . '/' . $job_object->job['s3bucket'] . '/' . dirname($object['Key']);
                 $files[$filecounter]['file'] = $object['Key'];
                 $files[$filecounter]['filename'] = basename($object['Key']);
                 if (!empty($object['StorageClass'])) {
                     $files[$filecounter]['info'] = sprintf(__('Storage Class: %s', 'backwpup'), $object['StorageClass']);
                 }
                 $files[$filecounter]['downloadurl'] = network_admin_url('admin.php') . '?page=backwpupbackups&action=downloads3&file=' . $object['Key'] . '&jobid=' . $job_object->job['jobid'];
                 $files[$filecounter]['filesize'] = $object['Size'];
                 $files[$filecounter]['time'] = $changetime;
                 $filecounter++;
             }
         }
         if ($job_object->job['s3maxbackups'] > 0 && is_object($s3)) {
             //Delete old backups
             if (count($backupfilelist) > $job_object->job['s3maxbackups']) {
                 ksort($backupfilelist);
                 $numdeltefiles = 0;
                 while ($file = array_shift($backupfilelist)) {
                     if (count($backupfilelist) < $job_object->job['s3maxbackups']) {
                         break;
                     }
                     //delete files on S3
                     $args = array('Bucket' => $job_object->job['s3bucket'], 'Key' => $job_object->job['s3dir'] . $file);
                     if ($s3->deleteObject($args)) {
                         foreach ($files as $key => $filedata) {
                             if ($filedata['file'] == $job_object->job['s3dir'] . $file) {
                                 unset($files[$key]);
                             }
                         }
                         $numdeltefiles++;
                     } else {
                         $job_object->log(sprintf(__('Cannot delete backup from %s.', 'backwpup'), $this->get_s3_base_url($job_object->job['s3region'], $job_object->job['s3base_url']) . '/' . $job_object->job['s3bucket'] . '/' . $job_object->job['s3dir'] . $file), E_USER_ERROR);
                     }
                 }
                 if ($numdeltefiles > 0) {
                     $job_object->log(sprintf(_n('One file deleted on S3 Bucket.', '%d files deleted on S3 Bucket', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE);
                 }
             }
         }
         set_site_transient('backwpup_' . $job_object->job['jobid'] . '_s3', $files, YEAR_IN_SECONDS);
     } catch (Exception $e) {
         $job_object->log(E_USER_ERROR, sprintf(__('S3 Service API: %s', 'backwpup'), $e->getMessage()), $e->getFile(), $e->getLine());
         return FALSE;
     }
     $job_object->substeps_done = 2 + $job_object->backup_filesize;
     return TRUE;
 }