Plugin Directory

Changeset 726630


Ignore:
Timestamp:
06/14/2013 10:59:57 AM (13 years ago)
Author:
Driskell
Message:

Update

Location:
wponlinebackup/trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wponlinebackup/trunk/include/bootstrap.php

    r724954 r726630  
    26382638        $this->Load_Status();
    26392639
    2640         // Send through a content-type header to stop any CDN or rogue plugin modifying our binary stream
    2641         // We had an instance where 0x09 (tab) was getting replaced with 0x20 (space), corrupting the data stream
    2642         header( 'Content-Type: application/octet-stream' );
    2643 
    26442640        // Check we have a backup running
    26452641        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'] : '?' ) );
    26472643
    26482644        // If we're not an online backup, we shouldn't be retrieving
    26492645        if ( $this->status['progress']['config']['target'] != 'online' )
    2650             die('OBFWRI2');
     2646            return $this->_Pull_Failure( 'OBFWRI2' );
    26512647
    26522648        // We may replace all this with WPOnlineBackup_HTTP_Range at some point...
     
    26592655        // Check the nonce
    26602656        if ( $this->status['progress']['nonce'] == '' )
    2661             die('OBFWRI3');
     2657            return $this->_Pull_Failure( 'OBFWRI3' );
    26622658        else if ( $nonce != $this->status['progress']['nonce'] )
    2663             die('OBFWRI4');
     2659            return $this->_Pull_Failure( 'OBFWRI4' );
    26642660
    26652661        // Make sure which is acceptable
     
    26682664        // Check we're not starting the transfer past the end of the file
    26692665        if ( $start > $this->status['progress']['file_set']['size'][$which] )
    2670             die('OBFWRE1');
     2666            return $this->_Pull_Failure( 'OBFWRE1' );
    26712667
    26722668        // 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
    26732670        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() );
    26752672
    26762673        if ( @fseek( $f, $this->status['progress']['file_set']['offset'][$which] + $start, SEEK_SET ) != 0 ) {
    26772674            $ret = OBFW_Exception();
    26782675            @fclose( $f );
    2679             die( 'OBFWRE3 ' . $ret );
     2676            return $this->_Pull_Failure( 'OBFWRE3 ' . $ret );
    26802677        }
    26812678
     
    26842681
    26852682        // 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' );
    26882693
    26892694        // Send the length of the data we're about to pass through - this is OBFWRD (6) + Length of nonce + File Size - Start position
     
    26982703        @fclose( $f );
    26992704
    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();
    27042730    }
    27052731
     
    27132739    }
    27142740
     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
    27152749    /*public*/ function _Prevent_Output( $in )
    27162750    {
  • wponlinebackup/trunk/include/disk.php

    r724954 r726630  
    375375    }
    376376
    377     /*private*/ function Partial_Write( $written, $length, $type = '' )
     377    /*private*/ function Partial_Write( $method, $written, $length, $type = '' )
    378378    {
    379379        $e = OBFW_Exception();
     
    391391        if ( $e ) $e = 'PHP last error: ' . $e;
    392392        else $e = 'PHP has no record of an error.';
    393         return 'Attempt to write to 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;
    394394    }
    395395
     
    397397    {
    398398        // ASSERTION - Status is 0
     399        $rlen = strlen( $data );
    399400        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.';
    401404
    402405        // Make sure we don't go into the loop with 0 bytes, and pretend we were successful
     
    417420            // If we wrote nothing, fail
    418421            if ( $written == 0 )
    419                 return $this->Partial_Write( $length - $todo_length, $length );
     422                return $this->Partial_Write( 'write', $length - $todo_length, $length );
    420423
    421424            $todo_length -= $written;
     
    444447        // ASSERTION - Status is 0
    445448        // ASSERTION - Rewrite always rewrites EXISTING data, and never writes past the current end of the file
     449        $rlen = strlen( $data );
    446450        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.';
    448454
    449455        if ( $offset >= $this->offset ) {
     
    462468                // If we wrote nothing, fail
    463469                if ( $written == 0 )
    464                     return $this->Partial_Write( $length - $todo_length, $length );
     470                    return $this->Partial_Write( 'rewrite', $length - $todo_length, $length );
    465471
    466472                $todo_length -= $written;
     
    512518                // If we wrote nothing, fail
    513519                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' );
    515521
    516522                $todo_length -= $written;
     
    905911            // If we wrote nothing, fail
    906912            if ( $written == 0 ) {
    907                 $ret = $this->Partial_Write( $length - $todo_length, $length, 'rc' );
     913                $ret = $this->Partial_Write( 'write', $length - $todo_length, $length, 'rc' );
    908914                @fclose( $this->rc_file );
    909915                return $ret;
     
    987993            // If we wrote nothing, fail
    988994            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 );
    990996
    991997            $todo_length -= $written;
Note: See TracChangeset for help on using the changeset viewer.