public/wordpress/wp-content/plugins/backupbuddy/classes/remote_api.php
/* _getFile()
	 *
	 * Calling site is wanting to get a file FROM this site.
	 *
	 */
_getFile()
Calling site is wanting to get a file FROM this site.
_getFile () Calling site is wanting to get a file FROM this site .
private static function _getFile( $type ) {
		$rootDir = self::_getFilePathByType( $type ); 
		$filePath = stripslashes_deep( self::$_incomingPayload[ 'filename' ] );
		$fullFilename = $rootDir . $filePath;
		$seekTo = self::$_incomingPayload[ 'seekto' ];
		if ( ! is_numeric( $seekTo ) ) {
			$seekTo = 0;
		}
		$maxPayload = self::$_incomingPayload[ 'maxPayload' ]; 
		$maxPayloadBytes = $maxPayload * 1024 * 1024;
		if ( ! file_exists( $fullFilename ) ) {
			$utf_decoded_filename = utf8_decode( $filePath );
			if ( file_exists( $rootDir . $utf_decoded_filename ) ) {
				$fullFilename = $rootDir . $utf_decoded_filename;
			} else {
				$message = 'Error #83929838: Requested `' . $type . '` file with full path `' . $fullFilename . '` does not exist. Was it just deleted? See log for details.';
				pb_backupbuddy::status( 'error', $message );
				self::_reply( array( 'success' => false, 'error' => $message ) );
			}
		}
		$size = filesize( $fullFilename );
		pb_backupbuddy::status( 'details', 'File size of file to get: ' . pb_backupbuddy::$format->file_size( $size ) );
		if ( $size > $maxPayloadBytes ) {
			$chunksTotal = ceil( $size / $maxPayloadBytes );
			pb_backupbuddy::status( 'details', 'This file + encoding exceeds the maximum per-chunk payload size so will be read in and sent in chunks of ' . self::$_incomingPayload[ 'maxPayload' ] . 'MB (' . $maxPayloadBytes . ' bytes) totaling approximately ' . $chunksTotal . ' chunks.' );
		} else {
			pb_backupbuddy::status( 'details', 'This file + encoding does not exceed per-chunk payload size of ' . self::$_incomingPayload[ 'maxPayload' ] . 'MB (' . pb_backupbuddy::$format->file_size( $maxPayloadBytes ) . ') so sending in one pass.' );
		}
		$prevPointer = 0;
		pb_backupbuddy::status( 'details', 'Reading in `' . $maxPayloadBytes . '` bytes at a time.' );
		if ( false === ( $fs = fopen( $fullFilename, 'rb' ) )) {
			$message = 'Error #235532: Unable to fopen file `' . $fullFilename . '`.';
			pb_backupbuddy::status( 'error', $message );
			self::_reply( array( 'success' => false, 'error' => $message ) );
		}
		if ( 0 != $seekTo ) {
			if ( 0 != fseek( $fs, $seekTo ) ) {
				@fclose( $fs );
				$message = 'Error #6464534229: Unable to fseek file.';
				pb_backupbuddy::status( 'error', $message );
				self::_reply( array( 'success' => false, 'error' => $message ) );
			}
		}
		$resumePoint = 0;
		$fileDone = false;
		$fileData = fread( $fs, $maxPayloadBytes );
		if ( feof( $fs ) ) {
			pb_backupbuddy::status( 'details', 'Read to end of file (feof true). No more chunks left after this.' );
			$fileDone = true;
		} else {
			if ( FALSE === ( $resumePoint = ftell( $fs ) ) ) {
				pb_backupbuddy::status( 'error', 'Error #42353212: Unable to get ftell pointer of file handle.' );
				@fclose( $fs );
				return false;
			} else {
				pb_backupbuddy::status( 'details', 'File pointer resume point: `' . $resumePoint . '`.' );
			}
		}
		@fclose( $fs );
		$file = array(
			'success'      => true,
			'data'         => $fileData,
			'datalen'      => strlen( $fileData ),
			'done'         => $fileDone,
			'size'         => $size,
			'resumepoint'  => $resumePoint,
			'encoded'      => isset( $utf_decoded_filename ), 
		);
		self::_reply( $file );
	}
private static function _getFile ( $ type ) { $ rootDir = self :: _getFilePathByType ( $ type ) ; $ filePath = stripslashes_deep ( self :: $ _incomingPayload [ 'filename' ] ) ; $ fullFilename = $ rootDir . $ filePath ; $ seekTo = self :: $ _incomingPayload [ 'seekto' ] ; if ( ! is_numeric ( $ seekTo ) ) { $ seekTo = 0 ; } $ maxPayload = self :: $ _incomingPayload [ 'maxPayload' ] ; $ maxPayloadBytes = $ maxPayload * 1024 * 1024 ; if ( ! file_exists ( $ fullFilename ) ) { $ utf_decoded_filename = utf8_decode ( $ filePath ) ; if ( file_exists ( $ rootDir . $ utf_decoded_filename ) ) { $ fullFilename = $ rootDir . $ utf_decoded_filename ; } else { $ message = 'Error #83929838: Requested `' . $ type . '` file with full path `' . $ fullFilename . '` does not exist. Was it just deleted? See log for details.' ; pb_backupbuddy :: status ( 'error' , $ message ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } } $ size = filesize ( $ fullFilename ) ; pb_backupbuddy :: status ( 'details' , 'File size of file to get: ' . pb_backupbuddy :: $ format -> file_size ( $ size ) ) ; if ( $ size > $ maxPayloadBytes ) { $ chunksTotal = ceil ( $ size / $ maxPayloadBytes ) ; pb_backupbuddy :: status ( 'details' , 'This file + encoding exceeds the maximum per-chunk payload size so will be read in and sent in chunks of ' . self :: $ _incomingPayload [ 'maxPayload' ] . 'MB (' . $ maxPayloadBytes . ' bytes) totaling approximately ' . $ chunksTotal . ' chunks.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'This file + encoding does not exceed per-chunk payload size of ' . self :: $ _incomingPayload [ 'maxPayload' ] . 'MB (' . pb_backupbuddy :: $ format -> file_size ( $ maxPayloadBytes ) . ') so sending in one pass.' ) ; } $ prevPointer = 0 ; pb_backupbuddy :: status ( 'details' , 'Reading in `' . $ maxPayloadBytes . '` bytes at a time.' ) ; if ( false === ( $ fs = fopen ( $ fullFilename , 'rb' ) ) ) { $ message = 'Error #235532: Unable to fopen file `' . $ fullFilename . '`.' ; pb_backupbuddy :: status ( 'error' , $ message ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } if ( 0 != $ seekTo ) { if ( 0 != fseek ( $ fs , $ seekTo ) ) { @ fclose ( $ fs ) ; $ message = 'Error #6464534229: Unable to fseek file.' ; pb_backupbuddy :: status ( 'error' , $ message ) ; self :: _reply ( array ( 'success' => false , 'error' => $ message ) ) ; } } $ resumePoint = 0 ; $ fileDone = false ; $ fileData = fread ( $ fs , $ maxPayloadBytes ) ; if ( feof ( $ fs ) ) { pb_backupbuddy :: status ( 'details' , 'Read to end of file (feof true). No more chunks left after this.' ) ; $ fileDone = true ; } else { if ( FALSE === ( $ resumePoint = ftell ( $ fs ) ) ) { pb_backupbuddy :: status ( 'error' , 'Error #42353212: Unable to get ftell pointer of file handle.' ) ; @ fclose ( $ fs ) ; return false ; } else { pb_backupbuddy :: status ( 'details' , 'File pointer resume point: `' . $ resumePoint . '`.' ) ; } } @ fclose ( $ fs ) ; $ file = array ( 'success' => true , 'data' => $ fileData , 'datalen' => strlen ( $ fileData ) , 'done' => $ fileDone , 'size' => $ size , 'resumepoint' => $ resumePoint , 'encoded' => isset ( $ utf_decoded_filename ) , ) ; self :: _reply ( $ file ) ; }
_getFile()
 Calling site is wanting to get a file FROM this site.
_getFile () Calling site is wanting to get a file FROM this site .
// contains trailing slash. // Max payload in bytes. // File exist? (note: if utf8 then this first check will fail and inside we will check for the file after utf8 decoding.) // Check if utf8 decoding the filename helps us find it. // Open for reading. // Seek to position (if applicable). // only isset if utf8 was needed to find this file.