Changeset 726630
- Timestamp:
- 06/14/2013 10:59:57 AM (13 years ago)
- Location:
- wponlinebackup/trunk/include
- Files:
-
- 2 edited
-
bootstrap.php (modified) (6 diffs)
-
disk.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wponlinebackup/trunk/include/bootstrap.php
r724954 r726630 2638 2638 $this->Load_Status(); 2639 2639 2640 // Send through a content-type header to stop any CDN or rogue plugin modifying our binary stream2641 // We had an instance where 0x09 (tab) was getting replaced with 0x20 (space), corrupting the data stream2642 header( 'Content-Type: application/octet-stream' );2643 2644 2640 // Check we have a backup running 2645 2641 if ( $this->status['status'] != WPONLINEBACKUP_STATUS_RUNNING && $this->status['status'] != WPONLINEBACKUP_STATUS_TICKING && $this->status['status'] != WPONLINEBACKUP_STATUS_CHECKING ) 2646 die( 'OBFWRF' . $this->status['status'] . ':' . ( isset( $this->status['progress']['comp'] ) ? $this->status['progress']['comp'] : '?' ) );2642 return $this->_Pull_Failure( 'OBFWRF' . $this->status['status'] . ':' . ( isset( $this->status['progress']['comp'] ) ? $this->status['progress']['comp'] : '?' ) ); 2647 2643 2648 2644 // If we're not an online backup, we shouldn't be retrieving 2649 2645 if ( $this->status['progress']['config']['target'] != 'online' ) 2650 die('OBFWRI2');2646 return $this->_Pull_Failure( 'OBFWRI2' ); 2651 2647 2652 2648 // We may replace all this with WPOnlineBackup_HTTP_Range at some point... … … 2659 2655 // Check the nonce 2660 2656 if ( $this->status['progress']['nonce'] == '' ) 2661 die('OBFWRI3');2657 return $this->_Pull_Failure( 'OBFWRI3' ); 2662 2658 else if ( $nonce != $this->status['progress']['nonce'] ) 2663 die('OBFWRI4');2659 return $this->_Pull_Failure( 'OBFWRI4' ); 2664 2660 2665 2661 // Make sure which is acceptable … … 2668 2664 // Check we're not starting the transfer past the end of the file 2669 2665 if ( $start > $this->status['progress']['file_set']['size'][$which] ) 2670 die('OBFWRE1');2666 return $this->_Pull_Failure( 'OBFWRE1' ); 2671 2667 2672 2668 // Open the requested file - open in binary mode! We don't want any conversions happening 2669 // If this fails - we treat as a temporary condition since maybe the file isn't quite ready 2673 2670 if ( ( $f = @fopen( $this->status['progress']['file_set']['file'][$which], 'rb' ) ) === false ) 2674 die( 'OBFWRE2 ' . OBFW_Exception() );2671 return $this->_Pull_Delay( 'OBFWRE2 ' . OBFW_Exception() ); 2675 2672 2676 2673 if ( @fseek( $f, $this->status['progress']['file_set']['offset'][$which] + $start, SEEK_SET ) != 0 ) { 2677 2674 $ret = OBFW_Exception(); 2678 2675 @fclose( $f ); 2679 die( 'OBFWRE3 ' . $ret );2676 return $this->_Pull_Failure( 'OBFWRE3 ' . $ret ); 2680 2677 } 2681 2678 … … 2684 2681 2685 2682 // Avoid timeouts and do not ignore a client abort 2686 @set_time_limit(0); 2687 @ignore_user_abort(false); 2683 @set_time_limit( 0 ); 2684 @ignore_user_abort( false ); 2685 2686 // Turn off HTML errors to try and ensure the data stream doesn't get tainted by any 2687 ini_set( 'display_errors', 0 ); 2688 ini_set( 'html_errors', 0 ); 2689 2690 // Send through a content-type header to stop any CDN or rogue plugin modifying our binary stream 2691 // We had an instance where 0x09 (tab) was getting replaced with 0x20 (space), corrupting the data stream 2692 header( 'Content-Type: application/octet-stream' ); 2688 2693 2689 2694 // Send the length of the data we're about to pass through - this is OBFWRD (6) + Length of nonce + File Size - Start position … … 2698 2703 @fclose( $f ); 2699 2704 2700 // Capture any post-request junk - POST should have resolved most of this but double check 2701 ob_start( array( & $this, '_Prevent_Output' ), 4096 ); 2702 2703 return true; 2705 return $this->_End_Request(); 2706 } 2707 2708 /*private*/ function _Pull_Failure( $message ) 2709 { 2710 // This tells the server we failed - octet-stream to prevent conversions of line endings so we remain consistent 2711 header( 'HTTP/1.1 500 Service Unavailable' ); 2712 header( 'Content-Type: application/octet-stream' ); 2713 2714 // And the reason for failure 2715 echo $message; 2716 2717 return $this->_End_Request(); 2718 } 2719 2720 /*private*/ function _Pull_Delay( $message ) 2721 { 2722 // This header tells the server to try again - octet-stream to prevent conversions of line endings so we remain consistent 2723 header( 'HTTP/1.1 503 Service Unavailable' ); 2724 header( 'Content-Type: application/octet-stream' ); 2725 2726 // If the server has tried again multiple times, it'll use this message as the reason 2727 echo $message; 2728 2729 return $this->_End_Request(); 2704 2730 } 2705 2731 … … 2713 2739 } 2714 2740 2741 /*private*/ function _End_Request() 2742 { 2743 // Capture any post-request junk - POST should have resolved most of this but double check 2744 ob_start( array( & $this, '_Prevent_Output' ), 4096 ); 2745 2746 return true; 2747 } 2748 2715 2749 /*public*/ function _Prevent_Output( $in ) 2716 2750 { -
wponlinebackup/trunk/include/disk.php
r724954 r726630 375 375 } 376 376 377 /*private*/ function Partial_Write( $ written, $length, $type = '' )377 /*private*/ function Partial_Write( $method, $written, $length, $type = '' ) 378 378 { 379 379 $e = OBFW_Exception(); … … 391 391 if ( $e ) $e = 'PHP last error: ' . $e; 392 392 else $e = 'PHP has no record of an error.'; 393 return 'Attempt to writeto file ' . $this->prefix . '/' . $name . '.php only partially succeeded. Only ' . $written . ' of ' . $length . ' bytes were written. (' . $this->size . ' bytes already written.) ' . $e;393 return 'Attempt to ' . $method . ' to file ' . $this->prefix . '/' . $name . '.php only partially succeeded. Only ' . $written . ' of ' . $length . ' bytes were written. (' . $this->size . ' bytes already written.) ' . $e; 394 394 } 395 395 … … 397 397 { 398 398 // ASSERTION - Status is 0 399 $rlen = strlen( $data ); 399 400 if ( is_null( $length ) ) 400 $length = strlen( $data ); 401 $length = $rlen; 402 else if ( $rlen < $length ) 403 return 'Attempt to write file ' . $this->prefix . '/' . $name . '.php failed due to insufficient data. Only ' . $rlen . ' of ' . $length . ' bytes were available.'; 401 404 402 405 // Make sure we don't go into the loop with 0 bytes, and pretend we were successful … … 417 420 // If we wrote nothing, fail 418 421 if ( $written == 0 ) 419 return $this->Partial_Write( $length - $todo_length, $length );422 return $this->Partial_Write( 'write', $length - $todo_length, $length ); 420 423 421 424 $todo_length -= $written; … … 444 447 // ASSERTION - Status is 0 445 448 // ASSERTION - Rewrite always rewrites EXISTING data, and never writes past the current end of the file 449 $rlen = strlen( $data ); 446 450 if ( is_null( $length ) ) 447 $length = strlen( $data ); 451 $length = $rlen; 452 else if ( $rlen < $length ) 453 return 'Attempt to write file ' . $this->prefix . '/' . $name . '.php failed due to insufficient data. Only ' . $rlen . ' of ' . $length . ' bytes were available.'; 448 454 449 455 if ( $offset >= $this->offset ) { … … 462 468 // If we wrote nothing, fail 463 469 if ( $written == 0 ) 464 return $this->Partial_Write( $length - $todo_length, $length );470 return $this->Partial_Write( 'rewrite', $length - $todo_length, $length ); 465 471 466 472 $todo_length -= $written; … … 512 518 // If we wrote nothing, fail 513 519 if ( $written == 0 ) 514 return $this->Partial_Write( $this_length - $todo_length, $this_length, 'patch' );520 return $this->Partial_Write( 'rewrite', $this_length - $todo_length, $this_length, 'patch' ); 515 521 516 522 $todo_length -= $written; … … 905 911 // If we wrote nothing, fail 906 912 if ( $written == 0 ) { 907 $ret = $this->Partial_Write( $length - $todo_length, $length, 'rc' );913 $ret = $this->Partial_Write( 'write', $length - $todo_length, $length, 'rc' ); 908 914 @fclose( $this->rc_file ); 909 915 return $ret; … … 987 993 // If we wrote nothing, fail 988 994 if ( $written == 0 ) 989 return $this->Partial_Write( $length - $todo_length, $length, $type );995 return $this->Partial_Write( 'write header', $length - $todo_length, $length, $type ); 990 996 991 997 $todo_length -= $written;
Note: See TracChangeset
for help on using the changeset viewer.