/** * Save settings form data */ public static function save_post_form() { if (!current_user_can('backwpup_settings')) { return; } //set default options if button clicked if (isset($_POST['default_settings']) && $_POST['default_settings']) { delete_site_option('backwpup_cfg_showadminbar'); delete_site_option('backwpup_cfg_showfoldersize'); delete_site_option('backwpup_cfg_jobsteprestart'); delete_site_option('backwpup_cfg_jobstepretry'); delete_site_option('backwpup_cfg_jobmaxexecutiontime'); delete_site_option('backwpup_cfg_jobziparchivemethod'); delete_site_option('backwpup_cfg_jobnotranslate'); delete_site_option('backwpup_cfg_jobwaittimems'); delete_site_option('backwpup_cfg_maxlogs'); delete_site_option('backwpup_cfg_gzlogs'); delete_site_option('backwpup_cfg_protectfolders'); delete_site_option('backwpup_cfg_httpauthuser'); delete_site_option('backwpup_cfg_httpauthpassword'); delete_site_option('backwpup_cfg_logfolder'); BackWPup_Admin::message(__('Settings reset to default', 'backwpup')); return; } update_site_option('backwpup_cfg_showadminbar', isset($_POST['showadminbar']) ? 1 : 0); update_site_option('backwpup_cfg_showfoldersize', isset($_POST['showfoldersize']) ? 1 : 0); update_site_option('backwpup_cfg_jobsteprestart', isset($_POST['jobsteprestart']) ? 1 : 0); if (100 > $_POST['jobstepretry'] && 0 < $_POST['jobstepretry']) { $_POST['jobstepretry'] = abs((int) $_POST['jobstepretry']); } if (empty($_POST['jobstepretry']) or !is_int($_POST['jobstepretry'])) { $_POST['jobstepretry'] = 3; } update_site_option('backwpup_cfg_jobstepretry', $_POST['jobstepretry']); update_site_option('backwpup_cfg_jobmaxexecutiontime', abs((int) $_POST['jobmaxexecutiontime'])); update_site_option('backwpup_cfg_jobziparchivemethod', $_POST['jobziparchivemethod'] == '' || $_POST['jobziparchivemethod'] == 'PclZip' || $_POST['jobziparchivemethod'] == 'ZipArchive' ? $_POST['jobziparchivemethod'] : ''); update_site_option('backwpup_cfg_jobnotranslate', isset($_POST['jobnotranslate']) ? 1 : 0); update_site_option('backwpup_cfg_jobwaittimems', $_POST['jobwaittimems']); update_site_option('backwpup_cfg_maxlogs', abs((int) $_POST['maxlogs'])); update_site_option('backwpup_cfg_gzlogs', isset($_POST['gzlogs']) ? 1 : 0); update_site_option('backwpup_cfg_protectfolders', isset($_POST['protectfolders']) ? 1 : 0); update_site_option('backwpup_cfg_httpauthuser', $_POST['httpauthuser']); update_site_option('backwpup_cfg_httpauthpassword', BackWPup_Encryption::encrypt($_POST['httpauthpassword'])); $_POST['jobrunauthkey'] = preg_replace('/[^a-zA-Z0-9]/', '', trim($_POST['jobrunauthkey'])); update_site_option('backwpup_cfg_jobrunauthkey', $_POST['jobrunauthkey']); $_POST['logfolder'] = trailingslashit(str_replace('\\', '/', trim(stripslashes($_POST['logfolder'])))); if ($_POST['logfolder'][0] == '.' || $_POST['logfolder'][0] != '/' && !preg_match('#^[a-zA-Z]:/#', $_POST['logfolder'])) { $_POST['logfolder'] = trailingslashit(str_replace('\\', '/', ABSPATH)) . $_POST['logfolder']; } //set def. folders if (empty($_POST['logfolder']) || $_POST['logfolder'] == '/') { delete_site_option('backwpup_cfg_logfolder'); } else { update_site_option('backwpup_cfg_logfolder', $_POST['logfolder']); } do_action('backwpup_page_settings_save'); BackWPup_Admin::message(__('Settings saved', 'backwpup')); }
/** * @param $jobid */ public function edit_tab($jobid) { //Dropbox auth keys from Dropbox // if cancelled auth if (!empty($_GET['not_approved'])) { echo '<div id="message" class="error"><p>' . __('Dropbox authentication not approved', 'backwpup') . '</p></div>'; delete_site_transient('backwpup_dropbox_auth_' . $jobid); } // if Auth data exists $auth_data = get_site_transient('backwpup_dropbox_auth_' . $jobid); if ($auth_data) { $oAuthStuff = array(); try { $dropbox = new BackWPup_Destination_Dropbox_API($auth_data['type']); $oAuthStuff = $dropbox->oAuthAccessToken($auth_data['oauth_token'], $auth_data['oauth_token_secret']); if (!empty($oAuthStuff)) { echo '<div id="message" class="updated below-h2"><p>' . __('Dropbox authentication complete!', 'backwpup') . '</p></div>'; BackWPup_Option::update($jobid, 'dropboxtoken', $oAuthStuff['oauth_token']); BackWPup_Option::update($jobid, 'dropboxsecret', BackWPup_Encryption::encrypt($oAuthStuff['oauth_token_secret'])); BackWPup_Option::update($jobid, 'dropboxroot', $auth_data['type']); delete_site_transient('backwpup_dropbox_auth_' . $jobid); } } catch (Exception $e) { echo '<div id="message" class="error"><p>' . sprintf(__('Dropbox API: %s', 'backwpup'), $e->getMessage()) . '</p></div>'; delete_site_transient('backwpup_dropbox_auth_' . $jobid); } } ?> <h3 class="title"><?php _e('Login', 'backwpup'); ?> </h3> <p></p> <table class="form-table"> <tr> <th scope="row"><?php _e('Authenticate', 'backwpup'); ?> </th> <td><?php if (!BackWPup_Option::get($jobid, 'dropboxtoken') && !BackWPup_Option::get($jobid, 'dropboxsecret') && !isset($oAuthStuff['oauth_token'])) { ?> <span style="color:red;"><?php _e('Not authenticated!', 'backwpup'); ?> </span> <a href="http://db.tt/8irM1vQ0"><?php _e('Create Account', 'backwpup'); ?> </a><br /> <?php } else { ?> <span style="color:green;"><?php _e('Authenticated!', 'backwpup'); ?> </span><br /> <?php } ?> <a class="button secondary" href="<?php echo admin_url('admin-ajax.php', 'relative'); ?> ?action=backwpup_dest_dropbox&type=sandbox&jobid=<?php echo $jobid; ?> "><?php _e('Reauthenticate (Sandbox)', 'backwpup'); ?> </a> <a class="button secondary" href="<?php echo admin_url('admin-ajax.php', 'relative'); ?> ?action=backwpup_dest_dropbox&type=dropbox&jobid=<?php echo $jobid; ?> "><?php _e('Reauthenticate (full Dropbox)', 'backwpup'); ?> </a> </td> </tr> </table> <h3 class="title"><?php _e('Backup settings', 'backwpup'); ?> </h3> <p></p> <table class="form-table"> <tr> <th scope="row"><label for="iddropboxdir"><?php _e('Folder in Dropbox', 'backwpup'); ?> </label></th> <td> <input id="iddropboxdir" name="dropboxdir" type="text" value="<?php echo esc_attr(BackWPup_Option::get($jobid, 'dropboxdir')); ?> " class="regular-text" /> </td> </tr> <tr> <th scope="row"><?php _e('File Deletion', 'backwpup'); ?> </th> <td> <?php if (BackWPup_Option::get($jobid, 'backuptype') == 'archive') { ?> <label for="iddropboxmaxbackups"><input id="iddropboxmaxbackups" name="dropboxmaxbackups" title="<?php esc_attr_e('Oldest files will be deleted first. 0 = no deletion', 'backwpup'); ?> " type="text" size="3" value="<?php echo esc_attr(BackWPup_Option::get($jobid, 'dropboxmaxbackups')); ?> " class="small-text help-tip" /> <?php _e('Number of files to keep in folder.', 'backwpup'); ?> </label> <?php } else { ?> <label for="iddropboxsyncnodelete" ><input class="checkbox" value="1" type="checkbox" <?php checked(BackWPup_Option::get($jobid, 'dropboxsyncnodelete'), TRUE); ?> name="dropboxsyncnodelete" id="iddropboxsyncnodelete" /> <?php _e('Do not delete files while syncing to destination!', 'backwpup'); ?> </label> <?php } ?> </td> </tr> </table> <?php }
/** * @param $jobid * @return string */ public function edit_form_post_save($jobid) { BackWPup_Option::update($jobid, 's3accesskey', isset($_POST['s3accesskey']) ? $_POST['s3accesskey'] : ''); BackWPup_Option::update($jobid, 's3secretkey', isset($_POST['s3secretkey']) ? BackWPup_Encryption::encrypt($_POST['s3secretkey']) : ''); BackWPup_Option::update($jobid, 's3base_url', isset($_POST['s3base_url']) ? esc_url_raw($_POST['s3base_url']) : ''); BackWPup_Option::update($jobid, 's3region', isset($_POST['s3region']) ? $_POST['s3region'] : ''); BackWPup_Option::update($jobid, 's3storageclass', isset($_POST['s3storageclass']) ? $_POST['s3storageclass'] : ''); BackWPup_Option::update($jobid, 's3ssencrypt', isset($_POST['s3ssencrypt']) && $_POST['s3ssencrypt'] == 'AES256' ? 'AES256' : ''); BackWPup_Option::update($jobid, 's3bucket', isset($_POST['s3bucket']) ? $_POST['s3bucket'] : ''); $_POST['s3dir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(stripslashes($_POST['s3dir']))))); if (substr($_POST['s3dir'], 0, 1) == '/') { $_POST['s3dir'] = substr($_POST['s3dir'], 1); } if ($_POST['s3dir'] == '/') { $_POST['s3dir'] = ''; } BackWPup_Option::update($jobid, 's3dir', $_POST['s3dir']); BackWPup_Option::update($jobid, 's3maxbackups', isset($_POST['s3maxbackups']) ? (int) $_POST['s3maxbackups'] : 0); BackWPup_Option::update($jobid, 's3syncnodelete', isset($_POST['s3syncnodelete']) && $_POST['s3syncnodelete'] == 1 ? TRUE : FALSE); BackWPup_Option::update($jobid, 's3multipart', isset($_POST['s3multipart']) && $_POST['s3multipart'] == 1 ? TRUE : FALSE); //create new bucket if (!empty($_POST['s3newbucket'])) { try { $s3 = new AmazonS3(array('key' => $_POST['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($_POST['s3secretkey']), 'certificate_authority' => TRUE)); $base_url = $this->get_s3_base_url($_POST['s3region'], $_POST['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(); } // set bucket creation region if ($_POST['s3region'] == 'google-storage' || $_POST['s3region'] == 'hosteurope') { $region = 'EU'; } else { $region = str_replace(array('http://', 'https://'), '', $base_url); } $bucket = $s3->create_bucket($_POST['s3newbucket'], $region, 'private'); if ($bucket->status == 200) { BackWPup_Admin::message(sprintf(__('Bucket %1$s created in %2$s.', 'backwpup'), $_POST['s3newbucket'], $bucket['Location'])); } else { BackWPup_Admin::message(sprintf(__('Bucket %s could not be created.', 'backwpup'), $_POST['s3newbucket']), TRUE); } } catch (Exception $e) { BackWPup_Admin::message($e->getMessage(), TRUE); } BackWPup_Option::update($jobid, 's3bucket', $_POST['s3newbucket']); } }
/** * @param $jobid * @return string */ public function edit_form_post_save($jobid) { BackWPup_Option::update($jobid, 'msazureaccname', isset($_POST['msazureaccname']) ? $_POST['msazureaccname'] : ''); BackWPup_Option::update($jobid, 'msazurekey', isset($_POST['msazurekey']) ? BackWPup_Encryption::encrypt($_POST['msazurekey']) : ''); BackWPup_Option::update($jobid, 'msazurecontainer', isset($_POST['msazurecontainer']) ? $_POST['msazurecontainer'] : ''); $_POST['msazuredir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(stripslashes($_POST['msazuredir']))))); if (substr($_POST['msazuredir'], 0, 1) == '/') { $_POST['msazuredir'] = substr($_POST['msazuredir'], 1); } if ($_POST['msazuredir'] == '/') { $_POST['msazuredir'] = ''; } BackWPup_Option::update($jobid, 'msazuredir', $_POST['msazuredir']); BackWPup_Option::update($jobid, 'msazuremaxbackups', isset($_POST['msazuremaxbackups']) ? (int) $_POST['msazuremaxbackups'] : 0); BackWPup_Option::update($jobid, 'msazuresyncnodelete', isset($_POST['msazuresyncnodelete']) && $_POST['msazuresyncnodelete'] == 1 ? TRUE : FALSE); //create a new container if (!empty($_POST['newmsazurecontainer']) && !empty($_POST['msazureaccname']) && !empty($_POST['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=' . $_POST['msazureaccname'] . ';AccountKey=' . $_POST['msazurekey']); $container_options = new WindowsAzure\Blob\Models\CreateContainerOptions(); $container_options->setPublicAccess(WindowsAzure\Blob\Models\PublicAccessType::NONE); $blobRestProxy->createContainer($_POST['newmsazurecontainer'], $container_options); BackWPup_Option::update($jobid, 'msazurecontainer', $_POST['newmsazurecontainer']); BackWPup_Admin::message(sprintf(__('MS Azure container "%s" created.', 'backwpup'), $_POST['newmsazurecontainer'])); } catch (Exception $e) { BackWPup_Admin::message(sprintf(__('MS Azure container create: %s', 'backwpup'), $e->getMessage()), TRUE); } } }
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 $id */ public function edit_form_post_save($id) { $_POST['ftphost'] = str_replace(array('http://', 'ftp://'), '', sanitize_text_field($_POST['ftphost'])); BackWPup_Option::update($id, 'ftphost', isset($_POST['ftphost']) ? $_POST['ftphost'] : ''); BackWPup_Option::update($id, 'ftphostport', !empty($_POST['ftphostport']) ? absint($_POST['ftphostport']) : 21); BackWPup_Option::update($id, 'ftptimeout', !empty($_POST['ftptimeout']) ? absint($_POST['ftptimeout']) : 90); BackWPup_Option::update($id, 'ftpuser', sanitize_text_field($_POST['ftpuser'])); BackWPup_Option::update($id, 'ftppass', BackWPup_Encryption::encrypt($_POST['ftppass'])); if (!empty($_POST['ftpdir'])) { $_POST['ftpdir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(sanitize_text_field($_POST['ftpdir']))))); } BackWPup_Option::update($id, 'ftpdir', $_POST['ftpdir']); BackWPup_Option::update($id, 'ftpmaxbackups', !empty($_POST['ftpmaxbackups']) ? absint($_POST['ftpmaxbackups']) : 0); if (function_exists('ftp_ssl_connect')) { BackWPup_Option::update($id, 'ftpssl', !empty($_POST['ftpssl'])); } else { BackWPup_Option::update($id, 'ftpssl', false); } BackWPup_Option::update($id, 'ftppasv', !empty($_POST['ftppasv'])); }
/** * @param $jobid */ public function edit_form_post_save($jobid) { BackWPup_Option::update($jobid, 'emailaddress', isset($_POST['emailaddress']) ? sanitize_email($_POST['emailaddress']) : ''); BackWPup_Option::update($jobid, 'emailefilesize', isset($_POST['emailefilesize']) ? (int) $_POST['emailefilesize'] : 0); BackWPup_Option::update($jobid, 'emailsndemail', sanitize_email($_POST['emailsndemail'])); BackWPup_Option::update($jobid, 'emailmethod', $_POST['emailmethod'] == '' || $_POST['emailmethod'] == 'mail' || $_POST['emailmethod'] == 'sendmail' || $_POST['emailmethod'] == 'smtp' ? $_POST['emailmethod'] : ''); BackWPup_Option::update($jobid, 'emailsendmail', $_POST['emailsendmail']); BackWPup_Option::update($jobid, 'emailsndemailname', $_POST['emailsndemailname']); BackWPup_Option::update($jobid, 'emailhost', $_POST['emailhost']); BackWPup_Option::update($jobid, 'emailhostport', (int) $_POST['emailhostport']); BackWPup_Option::update($jobid, 'emailsecure', $_POST['emailsecure'] == 'ssl' || $_POST['emailsecure'] == 'tls' ? $_POST['emailsecure'] : ''); BackWPup_Option::update($jobid, 'emailuser', $_POST['emailuser']); BackWPup_Option::update($jobid, 'emailpass', BackWPup_Encryption::encrypt($_POST['emailpass'])); }
/** * @param $id */ public function edit_form_post_save($id) { BackWPup_Option::update($id, 'rscusername', isset($_POST['rscusername']) ? $_POST['rscusername'] : ''); BackWPup_Option::update($id, 'rscapikey', isset($_POST['rscapikey']) ? BackWPup_Encryption::encrypt($_POST['rscapikey']) : ''); BackWPup_Option::update($id, 'rsccontainer', isset($_POST['rsccontainer']) ? $_POST['rsccontainer'] : ''); BackWPup_Option::update($id, 'rscregion', !empty($_POST['rscregion']) ? $_POST['rscregion'] : 'DFW'); $_POST['rscdir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(stripslashes($_POST['rscdir']))))); if (substr($_POST['rscdir'], 0, 1) == '/') { $_POST['rscdir'] = substr($_POST['rscdir'], 1); } if ($_POST['rscdir'] == '/') { $_POST['rscdir'] = ''; } BackWPup_Option::update($id, 'rscdir', $_POST['rscdir']); BackWPup_Option::update($id, 'rscmaxbackups', isset($_POST['rscmaxbackups']) ? (int) $_POST['rscmaxbackups'] : 0); BackWPup_Option::update($id, 'rscsyncnodelete', isset($_POST['rscsyncnodelete']) && $_POST['rscsyncnodelete'] == 1 ? TRUE : FALSE); if (!empty($_POST['rscusername']) && !empty($_POST['rscapikey']) && !empty($_POST['newrsccontainer'])) { try { $conn = new OpenCloud\Rackspace(self::get_auth_url_by_region($_POST['rscregion']), array('username' => $_POST['rscusername'], 'apiKey' => $_POST['rscapikey'])); $ostore = $conn->objectStoreService('cloudFiles', $_POST['rscregion'], 'publicURL'); $ostore->createContainer($_POST['newrsccontainer']); BackWPup_Option::update($id, 'rsccontainer', $_POST['newrsccontainer']); BackWPup_Admin::message(sprintf(__('Rackspace Cloud container "%s" created.', 'backwpup'), $_POST['newrsccontainer'])); } catch (Exception $e) { BackWPup_Admin::message(sprintf(__('Rackspace Cloud API: %s', 'backwpup'), $e->getMessage()), TRUE); } } }
/** * @param $jobid * @return string */ public function edit_form_post_save($jobid) { BackWPup_Option::update($jobid, 's3accesskey', sanitize_text_field($_POST['s3accesskey'])); BackWPup_Option::update($jobid, 's3secretkey', isset($_POST['s3secretkey']) ? BackWPup_Encryption::encrypt($_POST['s3secretkey']) : ''); BackWPup_Option::update($jobid, 's3base_url', isset($_POST['s3base_url']) ? esc_url_raw($_POST['s3base_url']) : ''); BackWPup_Option::update($jobid, 's3region', sanitize_text_field($_POST['s3region'])); BackWPup_Option::update($jobid, 's3storageclass', sanitize_text_field($_POST['s3storageclass'])); BackWPup_Option::update($jobid, 's3ssencrypt', isset($_POST['s3ssencrypt']) && $_POST['s3ssencrypt'] === 'AES256' ? 'AES256' : ''); BackWPup_Option::update($jobid, 's3bucket', isset($_POST['s3bucket']) ? sanitize_text_field($_POST['s3bucket']) : ''); $_POST['s3dir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(sanitize_text_field($_POST['s3dir']))))); if (substr($_POST['s3dir'], 0, 1) == '/') { $_POST['s3dir'] = substr($_POST['s3dir'], 1); } if ($_POST['s3dir'] == '/') { $_POST['s3dir'] = ''; } BackWPup_Option::update($jobid, 's3dir', $_POST['s3dir']); BackWPup_Option::update($jobid, 's3maxbackups', !empty($_POST['s3maxbackups']) ? absint($_POST['s3maxbackups']) : 0); BackWPup_Option::update($jobid, 's3syncnodelete', !empty($_POST['s3syncnodelete'])); BackWPup_Option::update($jobid, 's3multipart', !empty($_POST['s3multipart'])); //create new bucket if (!empty($_POST['s3newbucket'])) { try { $s3 = Aws\S3\S3Client::factory(array('key' => sanitize_text_field($_POST['s3accesskey']), 'secret' => sanitize_text_field($_POST['s3secretkey']), 'region' => sanitize_text_field($_POST['s3region']), 'base_url' => $this->get_s3_base_url(sanitize_text_field($_POST['s3region']), esc_url_raw($_POST['s3base_url'])), 'scheme' => 'https', 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert'))); // set bucket creation region if ($_POST['s3region'] === 'google-storage') { $region = 'EU'; } elseif ($_POST['s3region'] === 'google-storage-us') { $region = 'US'; } elseif ($_POST['s3region'] === 'google-storage-asia') { $region = 'ASIA'; } else { $region = sanitize_text_field($_POST['s3region']); } if ($s3->isValidBucketName($_POST['s3newbucket'])) { $s3->createBucket(array('Bucket' => sanitize_text_field($_POST['s3newbucket']), 'LocationConstraint' => $region)); $s3->waitUntil('bucket_exists', array('Bucket' => $_POST['s3newbucket'])); BackWPup_Admin::message(sprintf(__('Bucket %1$s created.', 'backwpup'), sanitize_text_field($_POST['s3newbucket']))); } else { BackWPup_Admin::message(sprintf(__(' %s is not a valid bucket name.', 'backwpup'), sanitize_text_field($_POST['s3newbucket'])), TRUE); } } catch (Aws\S3\Exception\S3Exception $e) { BackWPup_Admin::message($e->getMessage(), TRUE); } BackWPup_Option::update($jobid, 's3bucket', sanitize_text_field($_POST['s3newbucket'])); } }
/** * Save settings form data */ public static function save_post_form() { if (!current_user_can('backwpup_settings')) { return; } //set default options if button clicked if (isset($_POST['default_settings']) && $_POST['default_settings']) { delete_site_option('backwpup_cfg_showadminbar'); delete_site_option('backwpup_cfg_showfoldersize'); delete_site_option('backwpup_cfg_jobstepretry'); delete_site_option('backwpup_cfg_jobmaxexecutiontime'); delete_site_option('backwpup_cfg_jobziparchivemethod'); delete_site_option('backwpup_cfg_loglevel'); delete_site_option('backwpup_cfg_jobwaittimems'); delete_site_option('backwpup_cfg_jobrunauthkey'); delete_site_option('backwpup_cfg_jobdooutput'); delete_site_option('backwpup_cfg_maxlogs'); delete_site_option('backwpup_cfg_gzlogs'); delete_site_option('backwpup_cfg_protectfolders'); delete_site_option('backwpup_cfg_authentication'); delete_site_option('backwpup_cfg_logfolder'); delete_site_option('backwpup_cfg_dropboxappkey'); delete_site_option('backwpup_cfg_dropboxappsecret'); delete_site_option('backwpup_cfg_dropboxsandboxappkey'); delete_site_option('backwpup_cfg_dropboxsandboxappsecret'); delete_site_option('backwpup_cfg_sugarsynckey'); delete_site_option('backwpup_cfg_sugarsyncsecret'); delete_site_option('backwpup_cfg_sugarsyncappid'); BackWPup_Option::default_site_options(); BackWPup_Admin::message(__('Settings reset to default', 'backwpup')); return; } update_site_option('backwpup_cfg_showadminbar', isset($_POST['showadminbar']) ? 1 : 0); update_site_option('backwpup_cfg_showfoldersize', isset($_POST['showfoldersize']) ? 1 : 0); if (100 > $_POST['jobstepretry'] && 0 < $_POST['jobstepretry']) { $_POST['jobstepretry'] = abs((int) $_POST['jobstepretry']); } if (empty($_POST['jobstepretry']) or !is_int($_POST['jobstepretry'])) { $_POST['jobstepretry'] = 3; } update_site_option('backwpup_cfg_jobstepretry', $_POST['jobstepretry']); $max_exe_time = abs((int) $_POST['jobmaxexecutiontime']); if (!is_int($max_exe_time) || $max_exe_time < 0) { $max_exe_time = 0; } elseif ($max_exe_time > 300) { $max_exe_time = 300; } update_site_option('backwpup_cfg_jobmaxexecutiontime', $max_exe_time); update_site_option('backwpup_cfg_jobziparchivemethod', $_POST['jobziparchivemethod'] == '' || $_POST['jobziparchivemethod'] == 'PclZip' || $_POST['jobziparchivemethod'] == 'ZipArchive' ? $_POST['jobziparchivemethod'] : ''); update_site_option('backwpup_cfg_loglevel', in_array($_POST['loglevel'], array('normal_translated', 'normal', 'debug_translated', 'debug')) ? $_POST['loglevel'] : 'normal_translated'); update_site_option('backwpup_cfg_jobwaittimems', $_POST['jobwaittimems']); update_site_option('backwpup_cfg_jobdooutput', isset($_POST['jobdooutput']) ? 1 : 0); update_site_option('backwpup_cfg_maxlogs', abs((int) $_POST['maxlogs'])); update_site_option('backwpup_cfg_gzlogs', isset($_POST['gzlogs']) ? 1 : 0); update_site_option('backwpup_cfg_protectfolders', isset($_POST['protectfolders']) ? 1 : 0); $_POST['jobrunauthkey'] = preg_replace('/[^a-zA-Z0-9]/', '', trim($_POST['jobrunauthkey'])); update_site_option('backwpup_cfg_jobrunauthkey', $_POST['jobrunauthkey']); $_POST['logfolder'] = trailingslashit(str_replace('\\', '/', trim(stripslashes($_POST['logfolder'])))); //set def. folders if (empty($_POST['logfolder']) || $_POST['logfolder'] === '/') { delete_site_option('backwpup_cfg_logfolder'); BackWPup_Option::default_site_options(); } else { update_site_option('backwpup_cfg_logfolder', $_POST['logfolder']); } $authentication = get_site_option('backwpup_cfg_authentication', array('method' => '', 'basic_user' => '', 'basic_password' => '', 'user_id' => 0, 'query_arg' => '')); $authentication['method'] = in_array($_POST['authentication_method'], array('user', 'basic', 'query_arg')) ? $_POST['authentication_method'] : ''; $authentication['basic_user'] = $_POST['authentication_basic_user']; $authentication['basic_password'] = BackWPup_Encryption::encrypt($_POST['authentication_basic_password']); $authentication['query_arg'] = $_POST['authentication_query_arg']; $authentication['user_id'] = (int) $_POST['authentication_user_id']; update_site_option('backwpup_cfg_authentication', $authentication); delete_site_transient('backwpup_cookies'); do_action('backwpup_page_settings_save'); BackWPup_Admin::message(__('Settings saved', 'backwpup')); }
/** * @param $id */ public function edit_form_post_save($id) { $_POST['ftphost'] = str_replace(array('http://', 'ftp://'), '', $_POST['ftphost']); BackWPup_Option::update($id, 'ftphost', isset($_POST['ftphost']) ? $_POST['ftphost'] : ''); BackWPup_Option::update($id, 'ftphostport', !empty($_POST['ftphostport']) ? (int) $_POST['ftphostport'] : 21); BackWPup_Option::update($id, 'ftptimeout', !empty($_POST['ftptimeout']) ? (int) $_POST['ftptimeout'] : 90); BackWPup_Option::update($id, 'ftpuser', isset($_POST['ftpuser']) ? $_POST['ftpuser'] : ''); BackWPup_Option::update($id, 'ftppass', isset($_POST['ftppass']) ? BackWPup_Encryption::encrypt($_POST['ftppass']) : ''); if (!empty($_POST['ftpdir'])) { $_POST['ftpdir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(stripslashes($_POST['ftpdir']))))); } BackWPup_Option::update($id, 'ftpdir', $_POST['ftpdir']); BackWPup_Option::update($id, 'ftpmaxbackups', isset($_POST['ftpmaxbackups']) ? (int) $_POST['ftpmaxbackups'] : 0); if (function_exists('ftp_ssl_connect')) { BackWPup_Option::update($id, 'ftpssl', isset($_POST['ftpssl']) && $_POST['ftpssl'] == 1 ? TRUE : FALSE); } else { BackWPup_Option::update($id, 'ftpssl', FALSE); } BackWPup_Option::update($id, 'ftppasv', isset($_POST['ftppasv']) && $_POST['ftppasv'] == 1 ? TRUE : FALSE); }
/** * @param $jobid * @return string */ public function edit_form_post_save($jobid) { BackWPup_Option::update($jobid, 's3accesskey', isset($_POST['s3accesskey']) ? $_POST['s3accesskey'] : ''); BackWPup_Option::update($jobid, 's3secretkey', isset($_POST['s3secretkey']) ? BackWPup_Encryption::encrypt($_POST['s3secretkey']) : ''); BackWPup_Option::update($jobid, 's3base_url', isset($_POST['s3base_url']) ? esc_url_raw($_POST['s3base_url']) : ''); BackWPup_Option::update($jobid, 's3region', isset($_POST['s3region']) ? $_POST['s3region'] : ''); BackWPup_Option::update($jobid, 's3storageclass', isset($_POST['s3storageclass']) ? $_POST['s3storageclass'] : ''); BackWPup_Option::update($jobid, 's3ssencrypt', isset($_POST['s3ssencrypt']) && $_POST['s3ssencrypt'] == 'AES256' ? 'AES256' : ''); BackWPup_Option::update($jobid, 's3bucket', isset($_POST['s3bucket']) ? $_POST['s3bucket'] : ''); $_POST['s3dir'] = trailingslashit(str_replace('//', '/', str_replace('\\', '/', trim(stripslashes($_POST['s3dir']))))); if (substr($_POST['s3dir'], 0, 1) == '/') { $_POST['s3dir'] = substr($_POST['s3dir'], 1); } if ($_POST['s3dir'] == '/') { $_POST['s3dir'] = ''; } BackWPup_Option::update($jobid, 's3dir', $_POST['s3dir']); BackWPup_Option::update($jobid, 's3maxbackups', isset($_POST['s3maxbackups']) ? (int) $_POST['s3maxbackups'] : 0); BackWPup_Option::update($jobid, 's3syncnodelete', isset($_POST['s3syncnodelete']) && $_POST['s3syncnodelete'] == 1 ? TRUE : FALSE); BackWPup_Option::update($jobid, 's3multipart', isset($_POST['s3multipart']) && $_POST['s3multipart'] == 1 ? TRUE : FALSE); //create new bucket if (!empty($_POST['s3newbucket'])) { try { $s3 = Aws\S3\S3Client::factory(array('key' => $_POST['s3accesskey'], 'secret' => $_POST['s3secretkey'], 'region' => $_POST['s3region'], 'base_url' => $this->get_s3_base_url($_POST['s3region'], $_POST['s3base_url']), 'scheme' => 'https', 'ssl.certificate_authority' => BackWPup::get_plugin_data('plugindir') . '/vendor/cacert.pem')); // set bucket creation region if ($_POST['s3region'] == 'google-storage' || $_POST['s3region'] == 'hosteurope') { $region = 'EU'; } else { $region = $_POST['s3region']; } if ($s3->isValidBucketName($_POST['s3newbucket'])) { $bucket = $s3->createBucket(array('Bucket' => $_POST['s3newbucket'], 'LocationConstraint' => $region)); $s3->waitUntil('bucket_exists', $_POST['s3newbucket']); if ($bucket->get('Location')) { BackWPup_Admin::message(sprintf(__('Bucket %1$s created in %2$s.', 'backwpup'), $_POST['s3newbucket'], $bucket->get('Location'))); } else { BackWPup_Admin::message(sprintf(__('Bucket %s could not be created.', 'backwpup'), $_POST['s3newbucket']), TRUE); } } else { BackWPup_Admin::message(sprintf(__(' %s is not a valid bucket name.', 'backwpup'), $_POST['s3newbucket']), TRUE); } } catch (Aws\S3\Exception\S3Exception $e) { BackWPup_Admin::message($e->getMessage(), TRUE); } BackWPup_Option::update($jobid, 's3bucket', $_POST['s3newbucket']); } }