'', 'rscapikey' => '', 'rsccontainer' => '', 'rscregion' => 'DFW', 'rscdir' => trailingslashit( sanitize_file_name( get_bloginfo( 'name' ) ) ), 'rscmaxbackups' => 15, 'rscsyncnodelete' => TRUE ); } /** * Get Auht url by region code * * @param $region string region code * @return string */ public static function get_auth_url_by_region( $region ) { $region = strtoupper( $region ); if ( $region === 'LON' ) { return RACKSPACE_UK; } return RACKSPACE_US; } /** * @param $jobid */ public function edit_tab( $jobid ) { ?>


edit_ajax( array( 'rscusername' => BackWPup_Option::get( $jobid, 'rscusername' ), 'rscregion' => BackWPup_Option::get( $jobid, 'rscregion' ), 'rscapikey' => BackWPup_Encryption::decrypt( BackWPup_Option::get( $jobid, 'rscapikey' ) ), 'rscselected' => BackWPup_Option::get( $jobid, 'rsccontainer' ) ) ); ?>

Warning: Files belonging to this job are now tracked. Old backup archives which are untracked will not be automatically deleted.', 'backwpup' ) ?>

$_POST[ 'rscusername' ], 'apiKey' => $_POST[ 'rscapikey' ] ), array( 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert') ) ); $ostore = $conn->objectStoreService( 'cloudFiles', sanitize_text_field( $_POST[ 'rscregion' ] ), 'publicURL' ); $ostore->createContainer( $_POST[ 'newrsccontainer' ] ); BackWPup_Option::update( $id, 'rsccontainer', sanitize_text_field( $_POST[ 'newrsccontainer' ] ) ); BackWPup_Admin::message( sprintf( __( 'Rackspace Cloud container "%s" created.', 'backwpup' ), esc_html( sanitize_text_field( $_POST[ 'newrsccontainer' ] ) ) ) ); } catch ( Exception $e ) { BackWPup_Admin::message( sprintf( __( 'Rackspace Cloud API: %s', 'backwpup' ), $e->getMessage() ), TRUE ); } } } /** * @param $jobdest * @param $backupfile */ public function file_delete( $jobdest, $backupfile ) { $files = get_site_transient( 'backwpup_'. strtolower( $jobdest ) ); list( $jobid, $dest ) = explode( '_', $jobdest ); if ( BackWPup_Option::get( $jobid, 'rscusername' ) && BackWPup_Option::get( $jobid, 'rscapikey' ) && BackWPup_Option::get( $jobid, 'rsccontainer' ) ) { try { $conn = new OpenCloud\Rackspace( self::get_auth_url_by_region( BackWPup_Option::get( $jobid, 'rscregion' ) ), array( 'username' => BackWPup_Option::get( $jobid, 'rscusername' ), 'apiKey' => BackWPup_Encryption::decrypt( BackWPup_Option::get( $jobid, 'rscapikey' ) ) ), array( 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert') ) ); $ostore = $conn->objectStoreService( 'cloudFiles' , BackWPup_Option::get( $jobid, 'rscregion' ), 'publicURL'); $container = $ostore->getContainer( BackWPup_Option::get( $jobid, 'rsccontainer' ) ); $fileobject = $container->getObject( $backupfile ); $fileobject->delete(); //update file list foreach ( $files as $key => $file ) { if ( is_array( $file ) && $file[ 'file' ] == $backupfile ) unset( $files[ $key ] ); } } catch ( Exception $e ) { BackWPup_Admin::message( 'RSC: ' . $e->getMessage(), TRUE ); } } set_site_transient( 'backwpup_'. strtolower( $jobdest ), $files, YEAR_IN_SECONDS ); } /** * @param $jobid * @param $get_file * @param $local_file_path */ public function file_download( $jobid, $get_file, $local_file_path = null ) { try { $conn = new OpenCloud\Rackspace( self::get_auth_url_by_region( BackWPup_Option::get( $jobid, 'rscregion' ) ), array( 'username' => BackWPup_Option::get( $jobid, 'rscusername' ), 'apiKey' => BackWPup_Encryption::decrypt( BackWPup_Option::get( $jobid, 'rscapikey' ) ) ), array( 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert') ) ); $ostore = $conn->objectStoreService( 'cloudFiles' , BackWPup_Option::get( $jobid, 'rscregion' ), 'publicURL'); $container = $ostore->getContainer( BackWPup_Option::get( $jobid, 'rsccontainer' ) ); $backupfile = $container->getObject( $get_file ); if ( $level = ob_get_level() ) { for ( $i = 0; $i < $level; $i ++ ) { ob_end_clean(); } } @set_time_limit( 300 ); nocache_headers(); header( 'Content-Description: File Transfer' ); header( 'Content-Type: ' . MimeTypeExtractor::fromFilePath( $get_file ) ); header( 'Content-Disposition: attachment; filename="' . basename( $get_file ) . '"' ); header( 'Content-Transfer-Encoding: binary' ); header( 'Content-Length: ' . $backupfile->getContentLength() ); echo $backupfile->getContent(); die(); } catch ( Exception $e ) { die( $e->getMessage() ); } } /** * @inheritdoc */ public function file_get_list( $jobdest ) { $list = (array) get_site_transient( 'backwpup_' . strtolower( $jobdest ) ); $list = array_filter( $list ); return $list; } /** * @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; $job_object->substeps_done = 0; $job_object->log( sprintf( __( '%d. Trying to send backup file to Rackspace cloud …', 'backwpup' ), $job_object->steps_data[ $job_object->step_working ][ 'STEP_TRY' ] ), E_USER_NOTICE ); try { $conn = new OpenCloud\Rackspace( self::get_auth_url_by_region( $job_object->job[ 'rscregion' ] ), array( 'username' => $job_object->job[ 'rscusername' ], 'apiKey' => BackWPup_Encryption::decrypt( $job_object->job[ 'rscapikey' ] ) ), array( 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert') ) ); //connect to cloud files $ostore = $conn->objectStoreService( 'cloudFiles' , $job_object->job[ 'rscregion' ], 'publicURL' ); $container = $ostore->getContainer( $job_object->job[ 'rsccontainer' ] ); $job_object->log( sprintf(__( 'Connected to Rackspace cloud files container %s', 'backwpup' ), $job_object->job[ 'rsccontainer' ] ) ); } catch ( Exception $e ) { $job_object->log( E_USER_ERROR, sprintf( __( 'Rackspace Cloud API: %s', 'backwpup' ), $e->getMessage() ), $e->getFile(), $e->getLine() ); return FALSE; } try { //Transfer Backup to Rackspace Cloud $job_object->substeps_done = 0; $job_object->log( __( 'Upload to Rackspace cloud started …', 'backwpup' ), E_USER_NOTICE ); if ( $handle = fopen( $job_object->backup_folder . $job_object->backup_file, 'rb' ) ) { $uploded = $container->uploadObject( $job_object->job[ 'rscdir' ] . $job_object->backup_file, $handle ); fclose( $handle ); } else { $job_object->log( __( 'Can not open source file for transfer.', 'backwpup' ), E_USER_ERROR ); return FALSE; } // $transfer = $container->setupObjectTransfer( array( // 'name' => $job_object->job[ 'rscdir' ] . $job_object->backup_file, // 'path' => $job_object->backup_folder . $job_object->backup_file, // 'concurrency' => 1, // 'partSize' => 4 * 1024 * 1024 // ) ); // $uploded = $transfer->upload(); if ( $uploded ) { $job_object->log( __( 'Backup File transferred to RSC://', 'backwpup' ) . $job_object->job[ 'rsccontainer' ] . '/' . $job_object->job[ 'rscdir' ] . $job_object->backup_file, E_USER_NOTICE ); $job_object->substeps_done = 1 + $job_object->backup_filesize; if ( ! empty( $job_object->job[ 'jobid' ] ) ) { BackWPup_Option::update( $job_object->job[ 'jobid' ], 'lastbackupdownloadurl', network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=downloadrsc&file=' . $job_object->job[ 'rscdir' ] . $job_object->backup_file . '&jobid=' . $job_object->job[ 'jobid' ] ); } } else { $job_object->log( __( 'Cannot transfer backup to Rackspace cloud.', 'backwpup' ), E_USER_ERROR ); return FALSE; } } catch ( Exception $e ) { $job_object->log( E_USER_ERROR, sprintf( __( 'Rackspace Cloud API: %s', 'backwpup' ), $e->getMessage() ), $e->getFile(), $e->getLine() ); return FALSE; } try { $backupfilelist = array(); $filecounter = 0; $files = array(); $objlist = $container->objectList( array( 'prefix' => $job_object->job[ 'rscdir' ] ) ); while ( $object = $objlist->next() ) { $file = basename( $object->getName() ); if ( $job_object->job[ 'rscdir' ] . $file == $object->getName() ) { //only in the folder and not in complete bucket if ( $this->is_backup_archive( $file ) && $this->is_backup_owned_by_job( $file, $job_object->job['jobid'] ) == true ) $backupfilelist[ strtotime( $object->getLastModified() ) ] = $object; } $files[ $filecounter ][ 'folder' ] = "RSC://" . $job_object->job[ 'rsccontainer' ] . "/" . dirname( $object->getName() ) . "/"; $files[ $filecounter ][ 'file' ] = $object->getName(); $files[ $filecounter ][ 'filename' ] = basename( $object->getName() ); $files[ $filecounter ][ 'downloadurl' ] = network_admin_url( 'admin.php' ) . '?page=backwpupbackups&action=downloadrsc&file=' . $object->getName() . '&jobid=' . $job_object->job[ 'jobid' ]; $files[ $filecounter ][ 'filesize' ] = $object->getContentLength(); $files[ $filecounter ][ 'time' ] = strtotime( $object->getLastModified() ); $filecounter ++; } if ( ! empty( $job_object->job[ 'rscmaxbackups' ] ) && $job_object->job[ 'rscmaxbackups' ] > 0 ) { //Delete old backups if ( count( $backupfilelist ) > $job_object->job[ 'rscmaxbackups' ] ) { ksort( $backupfilelist ); $numdeltefiles = 0; while ( $file = array_shift( $backupfilelist ) ) { if ( count( $backupfilelist ) < $job_object->job[ 'rscmaxbackups' ] ) break; foreach ( $files as $key => $filedata ) { if ( $filedata[ 'file' ] == $file->getName() ) unset( $files[ $key ] ); } $file->delete(); $numdeltefiles ++; } if ( $numdeltefiles > 0 ) $job_object->log( sprintf( _n( 'One file deleted on Rackspace cloud container.', '%d files deleted on Rackspace cloud container.', $numdeltefiles, 'backwpup' ), $numdeltefiles ), E_USER_NOTICE ); } } set_site_transient( 'backwpup_' . $job_object->job[ 'jobid' ] . '_rsc', $files, YEAR_IN_SECONDS ); } catch ( Exception $e ) { $job_object->log( E_USER_ERROR, sprintf( __( 'Rackspace Cloud API: %s', 'backwpup' ), $e->getMessage() ), $e->getFile(), $e->getLine() ); return FALSE; } $job_object->substeps_done ++; return TRUE; } /** * @param $job_settings array * @return bool */ public function can_run( array $job_settings ) { if ( empty( $job_settings[ 'rscusername'] ) ) return FALSE; if ( empty( $job_settings[ 'rscapikey'] ) ) return FALSE; if ( empty( $job_settings[ 'rsccontainer'] ) ) return FALSE; return TRUE; } /** * */ public function edit_inline_js() { ?> '; $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' ] ), ), array( 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert') ) ); $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 ''; if ( ! empty( $container_list ) ) { echo ''; } if ( $ajax ) die(); else return; } }