Plugin Directory

Changeset 2678176


Ignore:
Timestamp:
02/14/2022 05:42:31 AM (3 years ago)
Author:
infinitewp
Message:

Release: 1.9.6 Final commit

Location:
iwp-client/trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • iwp-client/trunk/addons/post_links/post.class.php

    r2548691 r2678176  
    6363        // create dynamic url RegExp
    6464        $dot_match_count = 0;
    65         $iwp_regexp_url = "";
    66        
    67         if(!empty($post_upload_dir)){
     65       
     66        if(empty($post_upload_dir)){
     67            $iwp_regexp_url = "";
     68            $iwp_base_url   = array();
     69            $iwp_base_url['host'] = '';
     70            $iwp_base_url['path'] = '';
     71        }else{
    6872            $iwp_base_url   = parse_url($post_upload_dir['url']);
    6973            $iwp_regexp_url = $iwp_base_url['host'] . $iwp_base_url['path'];
     74        }
    7075            $rep            = array(
    7176                '/',
     
    8994            $iwp_mmb_dot_url     = str_replace($rep, $with, $iwp_mmb_dot_url);
    9095            $dot_match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]*' . $iwp_mmb_dot_url . '[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $dot_get_urls, PREG_SET_ORDER);
    91         }
    9296       
    9397               
  • iwp-client/trunk/addons/wp_optimize/purge-plugins-cache-class.php

    r2128300 r2678176  
    8080        }
    8181
     82        if (empty($params) || isset($params['litespeed-cache'])) {
     83            $response = $this->deleteAllLiteSpeedCache();
     84            if (!empty($response['success'])) {
     85                $text .= "<span class='wpm_results_db'> Litespeed Cache"." : " . $response['success'] . "</span><br>";
     86                $cleanup_values['value_array']['litespeed-cache'] = $values['value'];
     87            }elseif(!empty($response['error'])){
     88                $text .= "<span class='wpm_results_db'> Litespeed Cache"." : " . $response['error'] . "</span><br>";
     89                $cleanup_values['value_array']['auto_optimize'] = 'Litespeed Cache';
     90            }
     91        }
     92
    8293        if ($text !==''){
    8394            $cleanup_values['message'] = $text;
     
    126137                return true;
    127138            }
     139        }
     140        return false;
     141    }
     142
     143    public function checkLiteSpeedCachePlugin() {
     144        include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     145        if ( is_plugin_active( 'litespeed-cache/litespeed-cache.php' ) ) {
     146            @include_once(WP_PLUGIN_DIR . '/litespeed-cache/litespeed-cache.php');
     147            return true;
    128148        }
    129149        return false;
     
    280300    }
    281301
     302    public function deleteAllLiteSpeedCache(){
     303        if ($this->checkLiteSpeedCachePlugin()) {
     304            do_action('litespeed_purge_all');
     305            return array('success' => 'Purged all caches successfully');
     306         }else {
     307            return array('error'=>"Litespeed cache not activated", 'error_code' => 'litespeed_cache_plugin_is_not_activated');
     308        }
     309    }
     310
    282311}
    283312
  • iwp-client/trunk/backup.class.multicall.php

    r2548691 r2678176  
    284284                }
    285285                upgradeOldDropBoxBackupList($params['account_info']['iwp_dropbox']);
     286            }
     287
     288            if (!empty($params['account_info']['iwp_dropbox'])) {
     289                set_iwp_dropbox_auth_setting($params['account_info']['iwp_dropbox']);               
    286290            }
    287291           
     
    45244528    function remove_ftp_backup($args)
    45254529    {
     4530        global $iwp_backup_core;
    45264531        extract($args);
    45274532        //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
     
    45454550                            );
    45464551            }
     4552            $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    45474553            if (!$sftp->login($ftp_username, $ftp_password)) {
    45484554                return array(
     
    45994605    function get_ftp_backup($args, $current_file_num = 0)
    46004606    {
     4607        global $iwp_backup_core;
    46014608        extract($args);
    46024609        if(isset($use_sftp) && $use_sftp==1) {
     
    46184625                            );
    46194626            }
     4627            $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    46204628            if (!$sftp->login($ftp_username, $ftp_password)) {
    46214629                return array(
     
    47744782                        $dropbox_destination .= '/' . basename($backup_file);
    47754783                }else{
    4776                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
    4777                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
    4778                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
    4779                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
    4780                    
    4781                     $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
    4782                     $oauth->setToken($dropbox_access_token);
    4783                     $dropbox = new IWP_Dropbox_API($oauth);
     4784
     4785                    if(!isset($dropbox_email) && empty($dropbox_email)){
     4786                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
     4787                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
     4788                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
     4789                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
     4790   
     4791                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     4792                       
     4793                        $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
     4794                        $oauth->setToken($dropbox_access_token);
     4795                        $dropbox = new IWP_Dropbox_API($oauth);
     4796
     4797                    }else{
     4798                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     4799                       
     4800                        try{
     4801                            $helper = new IWP_MMB_UploadModule_dropbox();
     4802                            $dropbox = $helper->bootstrap();
     4803                        }
     4804                        catch(Exception $e){
     4805                            return $this->statusLog($historyID, array('stage' => 'uploadDropBox', 'status' => 'error', 'statusMsg' => $e->getMessage(), 'statusCode' => 'dropbox_verification_failed_file_may_be_corrupted'));
     4806                        }
     4807                    }
     4808
    47844809                    $oldRoot = 'Apps/InfiniteWP/';
    47854810                    $dropbox_destination = $oldRoot.ltrim(trim($dropbox_destination), '/');
     
    49815006                $dropbox_destination .= '/' . $this->site_name;
    49825007       }else{
    4983             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
    4984             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
    4985             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
    4986             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
     5008            if(!isset($dropbox_email) && empty($dropbox_email)){
     5009                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
     5010                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
     5011                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
     5012                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
    49875013           
    4988             $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
    4989             $oauth->setToken($dropbox_access_token);
    4990             $dropbox = new IWP_Dropbox_API($oauth);
     5014                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     5015                   
     5016                $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
     5017                $oauth->setToken($dropbox_access_token);
     5018                $dropbox = new IWP_Dropbox_API($oauth);
     5019
     5020            }else{
     5021                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     5022               
     5023                try{
     5024                    set_iwp_dropbox_auth_setting($args);
     5025                    $helper = new IWP_MMB_UploadModule_dropbox();
     5026                    $dropbox = $helper->bootstrap();
     5027                }
     5028                catch(Exception $e){
     5029                   
     5030                }
     5031            }
    49915032            $oldRoot = 'Apps/InfiniteWP/';
    49925033            $dropbox_destination = $oldRoot.ltrim(trim($dropbox_destination), '/');
  • iwp-client/trunk/backup.class.singlecall.php

    r2548691 r2678176  
    20282028function ftp_backup($args)
    20292029    {
     2030        global $iwp_backup_core;
    20302031        extract($args);
    20312032        //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder, $ftp_site_folder
     
    20482049                            );
    20492050            }
     2051            $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    20502052            if (!$sftp->login($ftp_username, $ftp_password)) {
    20512053                return array(
     
    21492151    function remove_ftp_backup($args)
    21502152    {
     2153        global $iwp_backup_core;
    21512154        extract($args);
    21522155        //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
     
    21692172                            );
    21702173            }
     2174            $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    21712175            if (!$sftp->login($ftp_username, $ftp_password)) {
    21722176                return array(
     
    22402244                        $dropbox_destination .= '/' . basename($backup_file);
    22412245                }else{
    2242                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
    2243                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
    2244                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
    2245                     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
     2246                    if(!isset($dropbox_email) && empty($dropbox_email)){
     2247                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
     2248                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
     2249                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
     2250                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
    22462251                   
    2247                     $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
    2248                     $oauth->setToken($dropbox_access_token);
    2249                     $dropbox = new IWP_Dropbox_API($oauth);
     2252                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     2253                           
     2254                        $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
     2255                        $oauth->setToken($dropbox_access_token);
     2256                        $dropbox = new IWP_Dropbox_API($oauth);
     2257
     2258                    }else{
     2259                        require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     2260                       
     2261                        try{
     2262                            set_iwp_dropbox_auth_setting($args);
     2263                            $helper = new IWP_MMB_UploadModule_dropbox();
     2264                            $dropbox = $helper->bootstrap();
     2265                        }
     2266                        catch(Exception $e){
     2267                           
     2268                        }
     2269                    }
    22502270                    $oldRoot = 'Apps/InfiniteWP/';
    22512271                    $oldVersion = false;
     
    23082328            $oldVersion = true;
    23092329       }else{
    2310             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
    2311             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
    2312             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
    2313             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
     2330            if(!isset($dropbox_email) && empty($dropbox_email)){
     2331                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
     2332                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
     2333                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
     2334                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
    23142335           
    2315             $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
    2316             $oauth->setToken($dropbox_access_token);
    2317             $dropbox = new IWP_Dropbox_API($oauth);
     2336                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     2337                   
     2338                $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
     2339                $oauth->setToken($dropbox_access_token);
     2340                $dropbox = new IWP_Dropbox_API($oauth);
     2341
     2342            }else{
     2343                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     2344               
     2345                try{
     2346                    set_iwp_dropbox_auth_setting($args);
     2347                    $helper = new IWP_MMB_UploadModule_dropbox();
     2348                    $dropbox = $helper->bootstrap();
     2349                }
     2350                catch(Exception $e){
     2351                   
     2352                }
     2353            }
    23182354            $oldRoot = 'Apps/InfiniteWP/';
    23192355            $dropbox_destination = $oldRoot.ltrim(trim($dropbox_destination), '/');
  • iwp-client/trunk/backup/backup-repo-test.php

    r2548691 r2678176  
    144144
    145145    public function SFTPTestConnection($args){
     146        global $iwp_backup_core;
    146147        extract($args);
    147148
     
    161162                );
    162163        }
     164        // Ensure phpseclib Crypt_Blowfish is loaded, over PEAR's
     165        $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    163166        if (!$sftp->login($ftp_username, $ftp_password)) {
    164167            return array('status' => 'error',
     
    189192            $uploadFilePath = IWP_BACKUP_DIR;
    190193            $uploadTestFile = $sftp->put(basename($backup_file),$backup_file,NET_SFTP_LOCAL_FILE);
     194            $remote_test_file = rtrim($ftp_remote_folder, '/') . '/' . basename($backup_file);
     195            $sftp->delete($remote_test_file);
    191196            @unlink($backup_file);
    192197            if ($uploadTestFile === false) {
     
    202207    public function backupRepositoryDropbox($args){
    203208        extract($args);
    204         if(isset($dropbox_access_token) && !empty($dropbox_access_token)){
    205             require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Dropbox/API.php';
    206             require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Dropbox/Exception.php';
    207             require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
    208             require_once $GLOBALS['iwp_mmb_plugin_dir'].'/lib/Dropbox/OAuth/Consumer/Curl.php';
    209            
     209        $dropbox = null;
     210        if(!isset($dropbox_email) && empty($dropbox_email) && isset($dropbox_access_token) && !empty($dropbox_access_token)){
     211            require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
     212            require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
     213            require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
     214            require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
     215       
     216            require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
    210217            try{
    211218                $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
    212219                $oauth->setToken($dropbox_access_token);
    213                 $dropbox = new IWP_Dropbox_API($oauth);
     220                $dropbox = new IWP_Dropbox_API($oauth);         
     221            }
     222            catch(Exception $e){
     223                return array('error' => $e->getMessage(), 'error_code' => 'dropbox_test_failed');
     224            }
     225
     226        }elseif( isset($dropbox_email) && !empty($dropbox_email) ){
     227            require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     228           
     229            try{
     230                set_iwp_dropbox_auth_setting($args);
     231                $helper = new IWP_MMB_UploadModule_dropbox();
     232                $dropbox = $helper->bootstrap();
     233            }
     234            catch(Exception $e){
     235                return array('error' => $e->getMessage(), 'error_code' => 'dropbox_test_failed');
     236            }
     237        }
     238       
     239        if (!is_null($dropbox)) {
     240            try{
    214241                $oldRoot = 'Apps/InfiniteWP';
    215242                $dropbox_destination = $oldRoot.$dropbox_destination;
    216243                $response = $dropbox->accountInfo();
    217                 return array('status' => 'success');           
     244                return array('status' => 'success');
    218245            }
    219246            catch(Exception $e){
     
    221248            }
    222249        }
     250
    223251        return array('error' => 'Consumer Secret not available', 'error_code' => 'consumer_secret_not_available');
    224252    }
  • iwp-client/trunk/backup/backup.core.class.php

    r2548691 r2678176  
    37393739    }
    37403740
    3741     public function ensure_phpseclib($classes = false, $class_paths = false) {
     3741    public function ensure_phpseclib_old($classes = false, $class_paths = false) {
    37423742
    37433743        $this->no_deprecation_warnings_on_php7();
     
    37603760            }
    37613761        }
     3762    }
     3763
     3764    public function ensure_phpseclib($classes = array()) {
     3765
     3766        $classes = (array) $classes;
     3767   
     3768        $this->no_deprecation_warnings_on_php7();
     3769
     3770        $any_missing = false;
     3771       
     3772        foreach ($classes as $cl) {
     3773            if (!class_exists($cl)) $any_missing = true;
     3774        }
     3775
     3776        if (!$any_missing) return true;
     3777       
     3778        $ret = true;
     3779       
     3780        // From phpseclib/phpseclib/phpseclib/bootstrap.php - we nullify it there, but log here instead
     3781        if (extension_loaded('mbstring')) {
     3782            // 2 - MB_OVERLOAD_STRING
     3783            // @codingStandardsIgnoreLine
     3784            if (ini_get('mbstring.func_overload') & 2) {
     3785                // We go on to try anyway, in case the caller wasn't using an affected part of phpseclib
     3786                // @codingStandardsIgnoreLine
     3787                $ret = new WP_Error('mbstring_func_overload', 'Overloading of string functions using mbstring.func_overload is not supported by phpseclib.');
     3788            }
     3789        }
     3790       
     3791        $phpseclib_dir = $GLOBALS['iwp_mmb_plugin_dir'].'/lib/phpseclib/phpseclib/phpseclib';
     3792        if (false === strpos(get_include_path(), $phpseclib_dir)) set_include_path(get_include_path().PATH_SEPARATOR.$phpseclib_dir);
     3793        foreach ($classes as $cl) {
     3794            $path = str_replace('_', '/', $cl);
     3795            if (!class_exists($cl)) include_once($phpseclib_dir.'/'.$path.'.php');
     3796        }
     3797       
     3798        return $ret;
    37623799    }
    37633800
     
    39974034                    'dropbox_site_folder' => $dropbox_details['dropbox_site_folder']
    39984035                );
     4036                if ( !empty($dropbox_details['dropbox_email']) ) {
     4037                    $opts['email'] = $dropbox_details['dropbox_email'];
     4038                }
    39994039                IWP_MMB_Backup_Options::update_iwp_backup_option('IWP_dropbox', $opts);
    40004040            }elseif (!empty($params['account_info']['iwp_gdrive'])) {
     
    44254465
    44264466    public function createCloudInstance($type, $args){
     4467        global $iwp_backup_core;
    44274468        if ($type == 'dropbox') {
    44284469            extract($args['iwp_dropbox']);
    4429             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
    4430             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
    4431             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
    4432             require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
     4470            if(!isset($dropbox_email) && empty($dropbox_email)){
     4471                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/API.php';
     4472                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/Exception.php';
     4473                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/ConsumerAbstract.php';
     4474                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Dropbox/OAuth/Consumer/Curl.php';
    44334475           
    4434             $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
    4435             $oauth->setToken($dropbox_access_token);
    4436             $dropbox = new IWP_Dropbox_API($oauth);
     4476                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     4477                   
     4478                $oauth = new IWP_Dropbox_OAuth_Consumer_Curl($dropbox_app_key, $dropbox_app_secure_key);
     4479                $oauth->setToken($dropbox_access_token);
     4480                $dropbox = new IWP_Dropbox_API($oauth);
     4481
     4482            }else{
     4483                require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/backup/dropbox.php';
     4484               
     4485                try{
     4486                    set_iwp_dropbox_auth_setting($args['iwp_dropbox']);
     4487                    $helper = new IWP_MMB_UploadModule_dropbox();
     4488                    $dropbox = $helper->bootstrap();
     4489                }
     4490                catch(Exception $e){
     4491                    return false;
     4492                }
     4493            }
    44374494            return $dropbox;
    44384495        }elseif ($type == 'ftp') {
     
    44524509                    return false;
    44534510                }
     4511                $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    44544512                if (!$sftp->login($ftp_username, $ftp_password)) {
    44554513                    return false;
     
    46974755                    }
    46984756                }
     4757
     4758                if (isset($backups[$timestamp]['service_setting'])) {
     4759                    $service_setting = $backups[$timestamp]['service_setting'];
     4760                    if (isset($service_setting['dropbox_site_folder'])) {
     4761                        set_iwp_dropbox_auth_setting($service_setting);
     4762                    }
     4763                }
    46994764            }
    47004765
     
    47534818                        foreach ($instance_settings as $instance_id => $options) {
    47544819
    4755                             $remote_obj->set_options($options, false, $instance_id);
     4820                            $remote_obj->set_options($service_setting, false, $instance_id);
    47564821
    47574822                            foreach ($files as $index => $file) {
     
    49885053                    'dropbox_site_folder' => $dropbox_details['dropbox_site_folder']
    49895054                );
     5055                if ( !empty($dropbox_details['dropbox_email']) ) {
     5056                    $opts['email'] = $dropbox_details['dropbox_email'];
     5057                }
    49905058                IWP_MMB_Backup_Options::update_iwp_backup_option('IWP_dropbox', $opts);
    49915059            }elseif (!empty($params['account_info']['iwp_gdrive'])) {
  • iwp-client/trunk/backup/backup.upload.php

    r1851728 r2678176  
    99
    1010    private $_instance_id;
     11
     12    private $_storage;
    1113   
    1214    /**
     
    2325       
    2426        if (null !== $instance_id) $this->set_instance_id($instance_id);
     27
     28        if (!empty($this->_storage)) unset($this->_storage);
    2529       
    2630        if ($save) return $this->save_options();
     
    3943        }
    4044   
    41         if (!$this->_instance_id) {
    42             throw new Exception('set_options() requires an instance ID, but was called without setting one (either directly or via set_instance_id())');
    43         }
     45        // if (!$this->_instance_id) {
     46        // throw new Exception('set_options() requires an instance ID, but was called without setting one (either directly or via set_instance_id())');
     47        // }
    4448       
    4549        global $iwp_backup_core;
     
    292296       
    293297    }
     298
     299
     300    /**
     301     * This method will set the stored storage object to that indicated
     302     *
     303     * @param Object $storage - the storage client
     304     */
     305    public function set_storage($storage) {
     306        $this->_storage = $storage;
     307    }
     308
     309    /**
     310     * This method will return the stored storage client
     311     *
     312     * @return Object - the stored remote storage client
     313     */
     314    public function get_storage() {
     315        if (!empty($this->_storage)) return $this->_storage;
     316    }
    294317}
  • iwp-client/trunk/backup/dropbox.php

    r1851728 r2678176  
    3232
    3333        $time_now = microtime(true);
     34        $storage = $this->get_storage();
    3435       
    3536        $time_since_last_tick = $time_now - $this->upload_tick;
     
    5051                $new_chunk = $new_chunk - ($new_chunk % 524288);
    5152                $chunk_size = (int)$new_chunk;
    52                 $this->dropbox_object->setChunkSize($chunk_size);
     53                $storage->setChunkSize($chunk_size);
    5354                $iwp_backup_core->jobdata_set('dropbox_chunk_size', $chunk_size);
    5455            }
     
    441442    }
    442443
    443 public function config_print() {
     444    public function config_print() {
    444445   
    445446        $opts = $this->get_options();
     
    486487        $sec = empty($opts['appkey']) ? '' : $opts['appkey'];
    487488       
    488         $oauth2_id = base64_decode('aXA3NGR2Zm1sOHFteTA5');
     489        $oauth2_id = $key;
     490        $old_auth = false;
     491        if ( empty($opts['email']) ) {
     492            $old_auth = true;
     493        }
    489494
    490495   
     
    493498
    494499        // Instantiate the storage
    495         $storage = new Dropbox_WordPress($encrypter, "tk_", 'IWP_dropbox', $this);
     500        $dropbox_storage = new Dropbox_WordPress($encrypter, "tk_", 'IWP_dropbox', $this);
    496501
    497502//      WordPress consumer does not yet work
     
    508513       
    509514        try {
    510             $OAuth = new Dropbox_Curl($sec, $oauth2_id, $key, $storage, null, null, $deauthenticate);
     515            $OAuth = new Dropbox_Curl($sec, $oauth2_id, $key, $dropbox_storage, null, null, $deauthenticate, null,$old_auth);
    511516        } catch (Exception $e) {
    512517            global $iwp_backup_core;
     
    517522
    518523        if ($deauthenticate) return true;
    519        
    520         $OAuth->setToken($opts['tk_access_token']);
    521         $this->dropbox_object = new IWP_MMB_Dropbox_API($OAuth, $root);
    522         return $this->dropbox_object;
     524
     525        if ( empty($opts['email']) ) {
     526            $dropbox_storage->set($opts['tk_access_token'], 'access_token');
     527        }
     528       
     529        $storage = new IWP_MMB_Dropbox_API($OAuth, $root);
     530       
     531        $this->set_storage($storage);
     532       
     533        return $storage;
    523534    }
    524535
  • iwp-client/trunk/core.class.php

    r2548691 r2678176  
    794794Description: This plugin will be created automatically when you activate your InfiniteWP Client plugin to improve the performance. And it will be deleted when you deactivate the client plugin.
    795795Author: Revmakx
     796Version: 1.0.0
    796797Author URI: https://infinitewp.com/
    797798*/
     
    844845            throw new Exception(sprintf('Unable to write loader: %s', $error['message']));
    845846        }
     847        update_option('iwp_mu_plugin_version','1.0.0');
    846848    }
    847849
  • iwp-client/trunk/init.php

    r2548691 r2678176  
    55Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
    66Author: Revmakx
    7 Version: 1.9.4.11
     7Version: 1.9.6
    88Author URI: http://www.revmakx.com
    99Network: true
     
    3030endif;
    3131if(!defined('IWP_MMB_CLIENT_VERSION'))
    32     define('IWP_MMB_CLIENT_VERSION', '1.9.4.11');
     32    define('IWP_MMB_CLIENT_VERSION', '1.9.6');
    3333
    3434
     
    32813281    $iwp_plugin_fix->fixSpamShield();
    32823282    $iwp_plugin_fix->fixWpSpamShieldBan();
    3283     $iwp_plugin_fix->fixPantheonGlobals();
     3283    $iwp_plugin_fix->fixGlobals();
    32843284
    32853285}
     
    32923292
    32933293    if (file_exists($loaderPath)) {
    3294         return;
     3294        $iwp_mu_plugin_version = get_option('iwp_mu_plugin_version');
     3295        if(empty($iwp_mu_plugin_version)){
     3296            $iwp_mu_plugin_version = '1.0.0';
     3297            $data = build_mu_plugin_version($loaderPath,$iwp_mu_plugin_version);
     3298            if(!$data){
     3299                iwp_mmb_response(array('error' => 'Unable to read InfiniteWP must use plugin', 'error_code' => 'iwp_mu_plugin_read_failed'), false);
     3300                return;
     3301            }
     3302        }else{
     3303            return;  //Both file and version number exisit
     3304        }
     3305    }else{
     3306        $data = $iwp_mmb_core->buildLoaderContent('iwp-client/init.php');
    32953307    }
    32963308    try {
    3297         $iwp_mmb_core->registerMustUse($loaderName, $iwp_mmb_core->buildLoaderContent('iwp-client/init.php'));
     3309        $iwp_mmb_core->registerMustUse($loaderName,$data);
    32983310    } catch (Exception $e) {
    32993311        iwp_mmb_response(array('error' => 'Unable to write InfiniteWP Client loader:'.$e->getMessage(), 'error_code' => 'iwp_mu_plugin_loader_failed'), false);
    33003312    }
    33013313}
     3314
     3315function build_mu_plugin_version($loaderPath,$iwp_mu_plugin_version){
     3316    $res = false;
     3317    $loaderWritten = @file_get_contents($loaderPath);
     3318    if($loaderWritten){
     3319        $res = preg_replace('/Author: Revmakx/', "Author: Revmakx ".PHP_EOL."Version :".$iwp_mu_plugin_version." ", $loaderWritten);
     3320    }
     3321    return $res;
     3322}
     3323
     3324function set_iwp_dropbox_auth_setting($dropbox_details){
     3325    if ( !empty($dropbox_details['dropbox_email']) ) {
     3326        $opts = array(
     3327            'appkey' => $dropbox_details['dropbox_app_key'],
     3328            'secret' => $dropbox_details['dropbox_app_secure_key'],
     3329            'tk_access_token' => $dropbox_details['dropbox_access_token'],
     3330            'folder' => $dropbox_details['dropbox_destination'],
     3331            'ownername' => '',
     3332            'email' => $dropbox_details['dropbox_email'],
     3333            'CSRF' => '',
     3334            'dropbox_site_folder' => $dropbox_details['dropbox_site_folder']
     3335        );
     3336        IWP_MMB_Backup_Options::update_iwp_backup_option('IWP_dropbox', $opts);
     3337    }
     3338}
     3339
    33023340if(!function_exists('iwp_mmb_is_WPTC')) {
    33033341function iwp_mmb_is_WPTC() {
  • iwp-client/trunk/lib/Dropbox2/API.php

    r1851728 r2678176  
    1111class IWP_MMB_Dropbox_API {
    1212    // API Endpoints
    13     const API_URL     = 'https://api.dropbox.com/1/';
    1413    const API_URL_V2  = 'https://api.dropboxapi.com/';
    15     const CONTENT_URL = 'https://api-content.dropbox.com/1/';
    1614    const CONTENT_URL_V2 = 'https://content.dropboxapi.com/2/';
    1715   
     
    7270        }
    7371    }
     72
     73    /**
     74     * This function will make a request to refresh the access token
     75     *
     76     * @return void
     77     */
     78    public function refreshAccessToken() {
     79        $this->OAuth->refreshAccessToken();
     80    }
    7481   
    7582    /**
     
    8693    /**
    8794     * Retrieves information about the user's quota
     95     * @param array $options - valid keys are 'timeout'
    8896     * @return object stdClass
    8997     */
    90     public function quotaInfo() {
     98    public function quotaInfo($options = array()) {
    9199        $call = '2/users/get_space_usage';
    92         $params = array('api_v2' => true);
     100        // Cases have been seen (Apr 2019) where a response came back (HTTP/2.0 response header - suspected outgoing web hosting proxy, as everyone else seems to get HTTP/1.0 and I'm not aware that current Curl versions would do HTTP/2.0 without specifically being told to) after 180 seconds; a valid response, but took a long time.
     101        $params = array(
     102            'api_v2' => true,
     103            'timeout' => isset($options['timeout']) ? $options['timeout'] : 20
     104        );
    93105        $response = $this->fetch('POST', self::API_URL_V2, $call, $params);
    94106        return $response;
    95107    }
    96    
    97     /**
    98      * Not used
    99      * Uploads a physical file from disk
    100      * Dropbox impose a 150MB limit to files uploaded via the API. If the file
    101      * exceeds this limit or does not exist, an Exception will be thrown
    102      * @param string $file Absolute path to the file to be uploaded
    103      * @param string|bool $filename The destination filename of the uploaded file
    104      * @param string $path Path to upload the file to, relative to root
    105      * @param boolean $overwrite Should the file be overwritten? (Default: true)
    106      * @return object stdClass
    107      */
    108     // public function putFile($file, $filename = false, $path = '', $overwrite = true)
    109     // {
    110     //     if (file_exists($file)) {
    111     //         if (filesize($file) <= 157286400) {
    112     //             $call = 'files/' . $this->root . '/' . $this->encodePath($path);
    113     //             // If no filename is provided we'll use the original filename
    114     //             $filename = (is_string($filename)) ? $filename : basename($file);
    115     //             $params = array(
    116     //                 'filename' => $filename,
    117     //                 'file' => '@' . str_replace('\\', '/', $file) . ';filename=' . $filename,
    118     //                 'overwrite' => (int) $overwrite,
    119     //             );
    120     //             $response = $this->fetch('POST', self::CONTENT_URL, $call, $params);
    121     //             return $response;
    122     //         }
    123     //         throw new Exception('File exceeds 150MB upload limit');
    124     //     }
    125        
    126     //     // Throw an Exception if the file does not exist
    127     //     throw new Exception('Local file ' . $file . ' does not exist');
    128     // }
    129    
    130     /**
    131      * Not used
    132      * Uploads file data from a stream
    133      * Note: This function is experimental and requires further testing
    134      * @todo Add filesize check
    135      * @param resource $stream A readable stream created using fopen()
    136      * @param string $filename The destination filename, including path
    137      * @param boolean $overwrite Should the file be overwritten? (Default: true)
    138      * @return array
    139      */
    140     // public function putStream($stream, $filename, $overwrite = true)
    141     // {
    142     //     $this->OAuth->setInFile($stream);
    143     //     $path = $this->encodePath($filename);
    144     //     $call = 'files_put/' . $this->root . '/' . $path;
    145     //     $params = array('overwrite' => (int) $overwrite);
    146     //     $response = $this->fetch('PUT', self::CONTENT_URL, $call, $params);
    147     //     return $response;
    148     // }
    149108   
    150109    /**
     
    159118     * @return stdClass
    160119     */
     120
     121    public function chunked_upload($file, $path = '', $overwrite = true, $uploadID = null, $offset = 0, $isCommit = false) {
     122        $starting_backup_path_time = time();
     123
     124        $file = str_replace("\\", "/",$file);
     125        if (!file_exists($file)) throw new Exception('Local file ' . $file . ' does not exist');
     126
     127        if (!($handle = @fopen($file, 'r'))) throw new Exception('Could not open ' . $file . ' for reading');
     128
     129        // Seek to the correct position on the file pointer
     130        fseek($handle, $offset);
     131        $to_exit = false;
     132
     133        //Set firstCommit to true so that the upload session start endpoint is called.
     134        $firstCommit = (0 == $offset);
     135
     136        // Read from the file handle until EOF, uploading each chunk
     137        if ($data = fread($handle, $this->chunkSize)) {
     138
     139            // Set the file, request parameters and send the request
     140            $this->OAuth->setInFile($data);
     141
     142            if ($firstCommit) {
     143                $params = array(
     144                    'close' => false,
     145                    'api_v2' => true,
     146                    'content_upload' => true
     147                );
     148                $response = $this->fetch('POST', self::CONTENT_URL_V2, 'files/upload_session/start', $params);
     149                $firstCommit = false;
     150
     151            } else {
     152                $params = array(
     153                    'cursor' => array(
     154                        'session_id' => $uploadID,
     155                        // If you send it as a string, Dropbox will be unhappy
     156                        'offset' => (int)$offset
     157                    ),
     158                    'api_v2' => true,
     159                    'content_upload' => true
     160                );
     161                $response = $this->append_upload($params, false);
     162            }
     163
     164            // On subsequent chunks, use the upload ID returned by the previous request
     165            if (isset($response['body']->session_id)) {
     166                $uploadID = $response['body']->session_id;
     167            }
     168
     169            /*
     170                API v2 no longer returns the offset, we need to manually work this out. So check that there are no errors and update the offset as well as calling the callback method.
     171             */
     172            if (!isset($response['body']->error)) {
     173                $offset = ftell($handle);
     174                $output['response']= $response;
     175                if($isCommit ==false){
     176
     177                    $output['offset']= $offset;
     178                    $output['upload_id']= $uploadID;
     179                }
     180                $this->OAuth->setInFile(null);
     181            }
     182
     183        }
     184        // Complete the chunked upload
     185        if ($isCommit) {
     186            $filename = (is_string($filename)) ? $filename : basename($file);
     187            $params = array(
     188                'cursor' => array(
     189                    'session_id' => $uploadID,
     190                    'offset' => (int)$offset
     191                ),
     192                'commit' => array(
     193                    'path' => '/' . $this->encodePath($path .'/'. $filename),
     194                    'mode' => 'overwrite'
     195                ),
     196                'api_v2' => true,
     197                'content_upload' => true
     198            );
     199            $response = $this->append_upload($params, true);
     200            $offset = ftell($handle);
     201            $output['response']= $response;
     202        }
     203
     204        fclose($handle);
     205        return $output;
     206    }
     207   
    161208    public function chunkedUpload($file, $filename = false, $path = '', $overwrite = true, $offset = 0, $uploadID = null, $callback = null) {
    162209
     
    175222                // Read from the file handle until EOF, uploading each chunk
    176223                while ($data = fread($handle, $this->chunkSize)) {
    177                    
    178                     // Set the file, request parameters and send the request
     224
     225                    // Set the file, request parameters and send the request
    179226                    $this->OAuth->setInFile($data);
    180227
     
    257304//                 $params['cursor']['offset'] = $responseCheck[1];
    258305//                 $response = $this->append_upload($params, $last_call);
     306            } elseif (isset($responseCheck) && strpos($responseCheck[0], 'closed') !== false) {
     307                throw new Exception("Upload with upload_id {$params['cursor']['session_id']} already completed");
    259308            } else {
    260309                throw $e;
     
    265314   
    266315    /**
    267      * Downloads a file
    268      * Returns the base filename, raw file data and mime type returned by Fileinfo
    269      * @param string $file Path to file, relative to root, including path
    270      * @param string $outFile Filename to write the downloaded file to
    271      * @param string $revision The revision of the file to retrieve
    272      * @param boolean $allow_resume - append to the file if it already exists
    273      * @return array
    274      */
    275     public function getFile($file, $outFile = false, $revision = null, $allow_resume = false) {
     316     * Chunked downloads a file from Dropbox, it will return false if a file handle is not passed and will return true if the call was successful.
     317     *
     318     * @param string $file Path - to file, relative to root, including path
     319     * @param resource $outFile - the local file handle
     320     * @param array $options    - any extra options to be passed e.g headers
     321     * @return boolean          - a boolean to indicate success or failure
     322     */
     323    public function download($file, $outFile = null, $options = array()) {
    276324        // Only allow php response format for this call
    277325        if ($this->responseFormat !== 'php') {
    278326            throw new Exception('This method only supports the `php` response format');
    279327        }
    280        
    281         $handle = null;
    282         if ($outFile !== false) {
    283             // Create a file handle if $outFile is specified
    284             if ($allow_resume && file_exists($outFile)) {
    285                if (!$handle = fopen($outFile, 'a')) {
    286                    throw new Exception("Unable to open file handle for $outFile");
    287                } else {
    288                    $this->OAuth->setOutFile($handle);
    289                    $params['headers'] = array('Range: bytes='.filesize($outFile).'-');
    290                }
    291             }
    292             elseif (!$handle = fopen($outFile, 'w')) {
    293                 throw new Exception("Unable to open file handle for $outFile");
    294             } else {
    295                 $this->OAuth->setOutFile($handle);
    296             }
    297         }
    298        
    299         $file = $this->encodePath($file);       
    300         $call = 'files/download';
    301         $params = array('path' => '/' . $file, 'api_v2' => true, 'content_download' => true);
    302         $response = $this->fetch('GET', self::CONTENT_URL_V2, $call, $params);
    303        
    304         // Close the file handle if one was opened
    305         if ($handle) fclose($handle);
    306 
    307         return array(
    308             'name' => ($outFile) ? $outFile : basename($file),
    309             'mime' => $this->getMimeType(($outFile) ? $outFile : $response['body'], $outFile),
    310             'meta' => json_decode($response['headers']['dropbox-api-result']),
    311             'data' => $response['body'],
    312         );
    313     }
    314    
    315     /**
    316      * Not used
    317      * Retrieves file and folder metadata
    318      * @param string $path The path to the file/folder, relative to root
    319      * @param string $rev Return metadata for a specific revision (Default: latest rev)
    320      * @param int $limit Maximum number of listings to return
    321      * @param string $hash Metadata hash to compare against
    322      * @param bool $list Return contents field with response
    323      * @param bool $deleted Include files/folders that have been deleted
    324      * @return object stdClass
    325      */
    326    public function metaData($path = null, $rev = null, $limit = 10000, $hash = false, $list = true, $deleted = false) {
    327         $call = '2/files/get_metadata' ;
    328         $params = array(
    329             'path' => '/' . $this->normalisePath($path),
    330             'api_v2' => true
    331         );
    332 
    333         return $this->fetch('POST', self::API_URL_V2, $call, $params);
    334     }
    335    
    336     /**
    337      * Not used
    338      * Return "delta entries", intructing you how to update
    339      * your application state to match the server's state
    340      * Important: This method does not make changes to the application state
    341      * @param null|string $cursor Used to keep track of your current state
    342      * @return array Array of delta entries
    343      */
    344     // public function delta($cursor = null)
    345     // {
    346     //     $call = 'delta';
    347     //     $params = array('cursor' => $cursor);
    348     //     $response = $this->fetch('POST', self::API_URL, $call, $params);
    349     //     return $response;
    350     // }
    351    
    352     /**
    353      * Not used
    354      * Obtains metadata for the previous revisions of a file
    355      * @param string Path to the file, relative to root
    356      * @param integer Number of revisions to return (1-1000)
    357      * @return array
    358      */
    359     // public function revisions($file, $limit = 10)
    360     // {
    361     //     $call = 'revisions/' . $this->root . '/' . $this->encodePath($file);
    362     //     $params = array(
    363     //         'rev_limit' => ($limit < 1) ? 1 : (($limit > 1000) ? 1000 : (int) $limit),
    364     //     );
    365     //     $response = $this->fetch('GET', self::API_URL, $call, $params);
    366     //     return $response;
    367     // }
    368    
    369     /**
    370      * Not used
    371      * Restores a file path to a previous revision
    372      * @param string $file Path to the file, relative to root
    373      * @param string $revision The revision of the file to restore
    374      * @return object stdClass
    375      */
    376     // public function restore($file, $revision)
    377     // {
    378     //     $call = 'restore/' . $this->root . '/' . $this->encodePath($file);
    379     //     $params = array('rev' => $revision);
    380     //     $response = $this->fetch('POST', self::API_URL, $call, $params);
    381     //     return $response;
    382     // }
    383    
    384     /**
    385      * Returns metadata for all files and folders that match the search query
     328
     329        if ($outFile) {
     330            $this->OAuth->setOutFile($outFile);
     331
     332            $params = array('path' => '/' . $file, 'api_v2' => true, 'content_download' => true);
     333
     334            if (isset($options['headers'])) {
     335                foreach ($options['headers'] as $key => $header) {
     336                    $headers[] = $key . ': ' . $header;
     337                }
     338                $params['headers'] = $headers;
     339            }
     340
     341            $file = $this->encodePath($file);       
     342            $call = 'files/download';
     343
     344            $response = $this->fetch('GET', self::CONTENT_URL_V2, $call, $params);
     345
     346            fclose($outFile);
     347
     348            return true;
     349        } else {
     350            return false;
     351        }
     352    }
     353   
     354    /**
     355     * Calls the relevant method to return metadata for all files and folders that match the search query
    386356     * @param mixed $query The search string. Must be at least 3 characters long
    387357     * @param string [$path=''] The path to the folder you want to search in
    388358     * @param integer [$limit=1000] Maximum number of results to return (1-1000)
    389      * @param integer [$start=0] Result number to start from
     359     * @param integer [$cursor=''] A Dropbox ID to start the search from
    390360     * @return array
    391361     */
    392     public function search($query, $path = '', $limit = 1000, $start = 0) {
    393         $call = '2/files/search';
     362    public function search($query, $path = '', $limit = 1000, $cursor = '') {
     363        if (empty($cursor)) {
     364            return $this->start_search($query, $path, $limit);
     365        } else {
     366            return $this->continue_search($cursor);
     367        }
     368    }
     369
     370    /**
     371     * This method will start a search for all files and folders that match the search query
     372     *
     373     * @param mixed   $query - the search string, must be at least 3 characters long
     374     * @param string  $path  - the path to the folder you want to search in
     375     * @param integer $limit - maximum number of results to return (1-1000)
     376     *
     377     * @return array - an array of search results
     378     */
     379    private function start_search($query, $path, $limit) {
     380        $call = '2/files/search_v2';
    394381        $path = $this->encodePath($path);
    395382        // APIv2 requires that the path match this regex: String(pattern="(/(.|[\r\n])*)?|(ns:[0-9]+(/.*)?)")
    396383        if ($path && '/' != substr($path, 0, 1)) $path = "/$path";
    397384        $params = array(
    398             'path' => $path,
    399385            'query' => $query,
    400             'start' => $start,
    401             'max_results' => ($limit < 1) ? 1 : (($limit > 1000) ? 1000 : (int) $limit),
     386            'options' => array(
     387                'path' => $path,
     388                'max_results' => ($limit < 1) ? 1 : (($limit > 1000) ? 1000 : (int) $limit),
     389            ),
    402390            'api_v2' => true,
    403391        );
     
    405393        return $response;
    406394    }
    407    
    408     /**
    409      * Not used
    410      * Creates and returns a shareable link to files or folders
    411      * The link returned is for a preview page from which the user an choose to
    412      * download the file if they wish. For direct download links, see media().
    413      * @param string $path The path to the file/folder you want a sharable link to
    414      * @return object stdClass
    415      */
    416     // public function shares($path, $shortUrl = true)
    417     // {
    418     //     $call = 'shares/' . $this->root . '/' .$this->encodePath($path);
    419     //     $params = array('short_url' => ($shortUrl) ? 1 : 0);
    420     //     $response = $this->fetch('POST', self::API_URL, $call, $params);
    421     //     return $response;
    422     // }
    423    
    424     /**
    425      * Not used
    426      * Returns a link directly to a file
    427      * @param string $path The path to the media file you want a direct link to
    428      * @return object stdClass
    429      */
    430     // public function media($path)
    431     // {
    432     //     $call = 'media/' . $this->root . '/' . $this->encodePath($path);
    433     //     $response = $this->fetch('POST', self::API_URL, $call);
    434     //     return $response;
    435     // }
    436    
    437     /**
    438      * Not used
    439      * Gets a thumbnail for an image
    440      * @param string $file The path to the image you wish to thumbnail
    441      * @param string $format The thumbnail format, either JPEG or PNG
    442      * @param string $size The size of the thumbnail
    443      * @return array
    444      */
    445     // public function thumbnails($file, $format = 'JPEG', $size = 'small')
    446     // {
    447     //     // Only allow php response format for this call
    448     //     if ($this->responseFormat !== 'php') {
    449     //         throw new Exception('This method only supports the `php` response format');
    450     //     }
    451        
    452     //     $format = strtoupper($format);
    453     //     // If $format is not 'PNG', default to 'JPEG'
    454     //     if ($format != 'PNG') $format = 'JPEG';
    455        
    456     //     $size = strtolower($size);
    457     //     $sizes = array('s', 'm', 'l', 'xl', 'small', 'medium', 'large');
    458     //     // If $size is not valid, default to 'small'
    459     //     if (!in_array($size, $sizes)) $size = 'small';
    460        
    461     //     $call = 'thumbnails/' . $this->root . '/' . $this->encodePath($file);
    462     //     $params = array('format' => $format, 'size' => $size);
    463     //     $response = $this->fetch('GET', self::CONTENT_URL, $call, $params);
    464        
    465     //     return array(
    466     //         'name' => basename($file),
    467     //         'mime' => $this->getMimeType($response['body']),
    468     //         'meta' => json_decode($response['headers']['x-dropbox-metadata']),
    469     //         'data' => $response['body'],
    470     //     );
    471     // }
    472    
    473     /**
    474      * Not used
    475      * THIS IS NOT AVAILABLE IN V2.
    476      * Creates and returns a copy_ref to a file
    477      * This reference string can be used to copy that file to another user's
    478      * Dropbox by passing it in as the from_copy_ref parameter on /fileops/copy
    479      * @param $path File for which ref should be created, relative to root
    480      * @return array
    481      */
    482     // public function copyRef($path)
    483     // {
    484     //     $call = 'copy_ref/' . $this->root . '/' . $this->encodePath($path);
    485     //     $response = $this->fetch('GET', self::API_URL, $call);
    486     //     return $response;
    487     // }
    488    
    489     /**
    490      * Not used
    491      * Copies a file or folder to a new location
    492      * @param string $from File or folder to be copied, relative to root
    493      * @param string $to Destination path, relative to root
    494      * @param null|string $fromCopyRef Must be used instead of the from_path
    495      * @return object stdClass
    496      */
    497     // public function copy($from, $to, $fromCopyRef = null)
    498     // {
    499     //     $call = 'fileops/copy';
    500     //     $params = array(
    501     //         'root' => $this->root,
    502     //         'from_path' => $this->normalisePath($from),
    503     //         'to_path' => $this->normalisePath($to),
    504     //     );
    505        
    506     //     if ($fromCopyRef) {
    507     //         $params['from_path'] = null;
    508     //         $params['from_copy_ref'] = $fromCopyRef;
    509     //     }
    510        
    511     //     $response = $this->fetch('POST', self::API_URL, $call, $params);
    512     //     return $response;
    513     // }
    514    
    515     /**
    516      * Not used
    517      * Creates a folder
    518      * @param string New folder to create relative to root
    519      * @return object stdClass
    520      */
    521     // public function create($path)
    522     // {
    523     //     $call = 'fileops/create_folder';
    524     //     $params = array('root' => $this->root, 'path' => $this->normalisePath($path));
    525     //     $response = $this->fetch('POST', self::API_URL, $call, $params);
    526     //     return $response;
    527     // }
     395
     396    /**
     397     * This method will continue a previous search for all files and folders that match the previous search query
     398     *
     399     * @param string $cursor - a Dropbox ID to continue the search
     400     *
     401     * @return array - an array of search results
     402     */
     403    private function continue_search($cursor) {
     404        $call = '2/files/search/continue_v2';
     405        $params = array(
     406            'cursor' => $cursor,
     407            'api_v2' => true,
     408        );
     409        $response = $this->fetch('POST', self::API_URL_V2, $call, $params);
     410        return $response;
     411    }
    528412   
    529413    /**
     
    533417     */
    534418    public function delete($path) {
    535         $call = '2/files/delete';
     419        $call = '2/files/delete_v2';
    536420        $params = array('path' => '/' . $this->normalisePath($path), 'api_v2' => true);
    537421        $response = $this->fetch('POST', self::API_URL_V2, $call, $params);
    538422        return $response;
    539423    }
    540    
    541     /**
    542      * Not used
    543      * Moves a file or folder to a new location
    544      * @param string $from File or folder to be moved, relative to root
    545      * @param string $to Destination path, relative to root
    546      * @return object stdClass
    547      */
    548     // public function move($from, $to)
    549     // {
    550     //     $call = 'fileops/move';
    551     //     $params = array(
    552     //             'root' => $this->root,
    553     //             'from_path' => $this->normalisePath($from),
    554     //             'to_path' => $this->normalisePath($to),
    555     //     );
    556     //     $response = $this->fetch('POST', self::API_URL, $call, $params);
    557     //     return $response;
    558     // }
    559    
     424
    560425    /**
    561426     * Intermediate fetch function
     
    619484        $this->callback = $function;
    620485    }
     486
     487    public function getFile($file, $outFile = false, $revision = null, $allow_resume = false) {
     488        // Only allow php response format for this call
     489        if ($this->responseFormat !== 'php') {
     490            throw new Exception('This method only supports the `php` response format');
     491        }
     492       
     493        $handle = null;
     494        if ($outFile !== false) {
     495            // Create a file handle if $outFile is specified
     496            if ($allow_resume && file_exists($outFile)) {
     497               if (!$handle = fopen($outFile, 'a')) {
     498                   throw new Exception("Unable to open file handle for $outFile");
     499               } else {
     500                   $this->OAuth->setOutFile($handle);
     501                   $params['headers'] = array('Range: bytes='.filesize($outFile).'-');
     502               }
     503            }
     504            elseif (!$handle = fopen($outFile, 'w')) {
     505                throw new Exception("Unable to open file handle for $outFile");
     506            } else {
     507                $this->OAuth->setOutFile($handle);
     508            }
     509        }
     510       
     511        $file = $this->encodePath($file);       
     512        $call = 'files/download';
     513        $params = array('path' => '/' . $file, 'api_v2' => true, 'content_download' => true);
     514        $response = $this->fetch('GET', self::CONTENT_URL_V2, $call, $params);
     515       
     516        // Close the file handle if one was opened
     517        if ($handle) fclose($handle);
     518
     519        return array(
     520            'name' => ($outFile) ? $outFile : basename($file),
     521            'mime' => $this->getMimeType(($outFile) ? $outFile : $response['body'], $outFile),
     522            'meta' => json_decode($response['headers']['dropbox-api-result']),
     523            'data' => $response['body'],
     524        );
     525    }
    621526   
    622527    /**
     
    659564        return $this->normalisePath($path);
    660565    }
     566
     567    public function metaData($path = null, $rev = null, $limit = 10000, $hash = false, $list = true, $deleted = false) {
     568        $call = '2/files/get_metadata' ;
     569        $params = array(
     570            'path' => '/' . $this->normalisePath($path),
     571            'api_v2' => true
     572        );
     573
     574        return $this->fetch('POST', self::API_URL_V2, $call, $params);
     575    }
     576
     577    public function putFile($file, $path = '', $overwrite = true) {
     578        if (!file_exists($file)) {
     579            // Throw an Exception if the file does not exist
     580            throw new Exception('Local file ' . $file . ' does not exist');
     581        }
     582        $filesize = iwp_mmb_get_file_size($file);
     583        if ($filesize >= 157286400) {
     584            $output = $this->chunked_upload_single_call_new($file, $path,$overwrite);
     585            return $output;
     586           
     587        }else{
     588            $handle = @fopen($file, 'r');
     589            //Set the file content to $this->InFile
     590            $this->OAuth->setInFile(fread($handle, filesize($file)));
     591            fclose($handle);
     592
     593            $filename = (is_string($filename)) ? $filename : basename($file);
     594            $path = '/' . $this->encodePath($path .'/'. $filename);
     595            $params = array(
     596                'path' => $path,
     597                'mute' => true,
     598                'mode' => 'overwrite',
     599                'api_v2' => true,
     600                'content_upload' => true
     601                );
     602            $response = $this->fetch('POST', self::CONTENT_URL_V2, 'files/upload', $params);
     603            return $response;
     604        }
     605
     606    }
     607
     608        public function chunked_upload_single_call_new($file, $path = '',$overwrite=true){
     609            $file = str_replace("\\", "/",$file);
     610            if (!is_readable($file) or !is_file($file))
     611                throw new Exception("Error: File \"$file\" is not readable or doesn't exist.");
     612            $file_handle=fopen($file,'r');
     613            $uploadID=null;
     614            $offset=0;
     615            $ProgressFunction=null;
     616            while ($data=fread($file_handle, (1024*1024*30))) {  //1024*1024*30 = 30MB
     617                $firstCommit = (0 == $offset);
     618                iwp_mmb_auto_print('dropbox_chucked_upload');
     619              $this->OAuth->setInFile($data);
     620
     621                if ($firstCommit) {
     622                    $params = array(
     623                        'close' => false,
     624                        'api_v2' => true,
     625                        'content_upload' => true
     626                    );
     627                    $response = $this->fetch('POST', self::CONTENT_URL_V2, 'files/upload_session/start', $params);
     628                    $firstCommit = false;
     629
     630                } else {
     631                    $params = array(
     632                        'cursor' => array(
     633                            'session_id' => $uploadID,
     634                            // If you send it as a string, Dropbox will be unhappy
     635                            'offset' => (int)$offset
     636                        ),
     637                        'api_v2' => true,
     638                        'content_upload' => true
     639                    );
     640                    $response = $this->append_upload($params, false);
     641                }
     642
     643                // On subsequent chunks, use the upload ID returned by the previous request
     644                if (isset($response['body']->session_id)) {
     645                    $uploadID = $response['body']->session_id;
     646                }
     647
     648                /*
     649                    API v2 no longer returns the offset, we need to manually work this out. So check that there are no errors and update the offset as well as calling the callback method.
     650                 */
     651                if (!isset($response['body']->error)) {
     652                    $offset = ftell($file_handle);
     653                    $output['response']= $response;
     654                    if($isCommit ==false){
     655
     656                        $output['offset']= $offset;
     657                        $output['upload_id']= $uploadID;
     658                    }
     659                    $this->OAuth->setInFile(null);
     660                }
     661                fseek($file_handle, $offset);
     662            }
     663            fclose($file_handle);
     664            $filename = (is_string($filename)) ? $filename : basename($file);
     665                $params = array(
     666                    'cursor' => array(
     667                        'session_id' => $uploadID,
     668                        'offset' => (int)$offset
     669                    ),
     670                    'commit' => array(
     671                        'path' => '/' . $this->encodePath($path .'/'. $filename),
     672                        'mode' => 'overwrite'
     673                    ),
     674                    'api_v2' => true,
     675                    'content_upload' => true
     676                );
     677                $response = $this->append_upload($params, true);
     678               
     679            return $response;
     680        }
    661681}
  • iwp-client/trunk/lib/Dropbox2/OAuth/Consumer/ConsumerAbstract.php

    r1851728 r2678176  
    2121    // The next endpoint only exists with APIv1
    2222    const OAUTH_UPGRADE = 'oauth2/token_from_oauth1';
     23
     24    private $scopes = array(
     25        'account_info.read',
     26        'files.content.write',
     27        'files.content.read',
     28        'files.metadata.read',
     29    );
    2330   
    2431    /**
     
    2734     */
    2835    private $sigMethod = 'PLAINTEXT';
    29 
    30     private $token = null;
    3136   
    3237    /**
     
    5762            $this->upgradeOAuth();
    5863            $iwp_backup_core->log('OAuth token upgrade successful');
     64        }
     65
     66        if (!empty($access_token) && isset($access_token->refresh_token) && isset($access_token->expires_in)) {
     67            if ($access_token->expires_in < time()) $this->refreshAccessToken();
    5968        }
    6069       
     
    8493    {
    8594        // N.B. This call only exists under API v1 - i.e. there is no APIv2 equivalent. Hence the APIv1 endpoint (API_URL) is used, and not the v2 (API_URL_V2)
    86         $url = IWP_MMB_Dropbox_API::API_URL . self::OAUTH_UPGRADE;
     95        $url = 'https://api.dropbox.com/1/' . self::OAUTH_UPGRADE;
    8796        $response = $this->fetch('POST', $url, '');
    8897        $token = new stdClass();
     
    127136        $this->storage->do_unset('access_token');
    128137        throw new Dropbox_Exception(sprintf(__('You need to re-authenticate with %s, as your existing credentials are not working.', 'InfiniteWP'), 'Dropbox'));
    129      
    130138        return false;
    131     }
    132 
    133     public function setToken($token)
    134     {
    135 
    136         $this->token = $token;
    137 
    138         return $this;
    139139    }
    140140   
     
    151151       
    152152        global $iwp_backup_core;
    153         if (!function_exists('crypt_random_string')) $iwp_backup_core->ensure_phpseclib('Crypt_Random', 'Crypt/Random');
     153        if (!function_exists('crypt_random_string')) $iwp_backup_core->ensure_phpseclib('Crypt_Random');
    154154
    155155        $CSRF = base64_encode(crypt_random_string(16));
    156156        $this->storage->set($CSRF,'CSRF');
    157        
     157        // Prepare request parameters
     158        /*
     159            For OAuth v2 Dropbox needs to use a authorisation url that matches one that is set inside the
     160            Dropbox developer console. In order to check this it needs the client ID for the OAuth v2 app
     161            This will use the default one unless the user is using their own Dropbox App
     162           
     163            Check if the key has dropbox: if so then remove it to stop the request from being invalid
     164        */
    158165        $appkey = $this->storage->get('appkey');
    159166       
     
    163170            $key = $appkey;
    164171        }
     172
     173        if ('' != $this->instance_id) $this->instance_id = ':'.$this->instance_id;
    165174       
    166175        $params = array(
     
    168177            'response_type' => 'code',
    169178            'redirect_uri' => empty($key) ? $this->callback : $this->callbackhome,
    170             'state' => empty($key) ? $CSRF.$this->callbackhome : $CSRF,
     179            'state' => empty($key) ? "POST:".$CSRF.$this->instance_id.$this->callbackhome : $CSRF.$this->instance_id,
     180            'scope' => implode(' ', $this->scopes),
     181            'token_access_type' => 'offline'
    171182        );
    172183   
     
    217228            } else {
    218229                $code = base64_decode($code);
    219                 $code = json_decode($code, true);   
     230                $code = json_decode($code, true);
    220231            }
    221232           
     
    227238                after more testing token secret can be removed.
    228239            */
    229            
    230240            $token = new stdClass();
    231241            $token->oauth_token_secret = $code['access_token'];
     
    234244            $token->token_type = $code['token_type'];
    235245            $token->uid = $code['uid'];
     246            $token->refresh_token = $code['refresh_token'];
     247            $token->expires_in = time() + $code['expires_in'] - 30;
    236248            $this->storage->set($token, 'access_token');
    237249            $this->storage->do_unset('upgraded');
     
    243255        }
    244256    }
     257
     258    /**
     259     * This function will make a request to the auth server sending the users refresh token to get a new access token
     260     *
     261     * @return void
     262     */
     263    public function refreshAccessToken() {
     264        global $iwp_backup_core;
     265
     266        $access_token = $this->storage->get('access_token');
     267       
     268        $params = array(
     269            'grant_type' => 'refresh_token',
     270            'refresh_token' => $access_token->refresh_token,
     271        );
     272
     273        $url = IWP_MMB_Dropbox_API::API_URL_V2 . self::ACCESS_TOKEN_METHOD;
     274
     275        $response = $this->fetch('POST', $url, '' , $params);
     276       
     277        if ("200" != $response['code']) {
     278            $iwp_backup_core->log('Failed to refresh access token error code: '.$response['code']);
     279            return;
     280        }
     281
     282        if (empty($response['body'])) {
     283            $iwp_backup_core->log('Failed to refresh access token empty response body');
     284            return;
     285        }
     286
     287        $body = $response['body'];
     288
     289        if (isset($body->access_token) && isset($body->expires_in)) {
     290            $access_token->oauth_token_secret = $body->access_token;
     291            $access_token->oauth_token = $body->access_token;
     292            $access_token->expires_in = time() + $body->expires_in - 30;
     293            $this->storage->set($access_token, 'access_token');
     294            $iwp_backup_core->log('Successfully updated and refreshed the access token');
     295        } else {
     296            $iwp_backup_core->log('Failed to refresh access token missing token and expiry: '.json_encode($body));
     297            return;
     298        }
     299    }
    245300   
    246301    /**
     
    251306     * @return object stdClass
    252307     */
    253    public function getToken()
    254     {
    255         return $this->token;
    256     }
     308    private function getToken()
     309    {
     310        if (!$token = $this->storage->get('access_token')) {
     311            if (!$token = $this->storage->get('request_token')) {
     312                $token = new stdClass();
     313                $token->oauth_token = null;
     314                $token->oauth_token_secret = null;
     315            }
     316        }
     317        return $token;
     318    }
     319   
    257320    /**
    258321     * Generate signed request URL
     
    271334
    272335        // Prepare the standard request parameters differently for OAuth1 and OAuth2; we still need OAuth1 to make the request to the upgrade token endpoint
    273         if (!empty($token)) {
    274             $params = array(
    275                 'access_token' => $token,
    276             );
     336        if (isset($token)) {
     337            if (isset($token->oauth_token)) {
     338                $params = array(
     339                    'access_token' => $token->oauth_token,
     340                );
     341            }else{
     342                $params = array(
     343                    'access_token' => $token,
     344                );
     345            }
    277346
    278347            /*
     
    280349             */
    281350
    282             if (isset($additional['api_v2']) && $additional['api_v2'] == true) {
    283                 unset($additional['api_v2']);
     351            if (isset($additional['api_v2']) && $additional['api_v2'] == true && !isset($additional['refresh_token'])) {
     352                unset($additional['api_v2']);
     353                if (isset($additional['timeout'])) unset($additional['timeout']);
    284354                if (isset($additional['content_download']) && $additional['content_download'] == true) {
    285355                    unset($additional['content_download']);
     356                    $extra_headers = array();
     357                    if (isset($additional['headers'])) {
     358                        foreach ($additional['headers'] as $key => $header) {
     359                            $extra_headers[] = $header;
     360                        }
     361                        unset($additional['headers']);
     362                    }
    286363                    $headers = array(
    287364                        'Authorization: Bearer '.$params['access_token'],
     
    289366                        'Dropbox-API-Arg: '.json_encode($additional),
    290367                    );
     368
     369                    $headers = array_merge($headers, $extra_headers);
    291370                    $additional = '';
    292371                } else if (isset($additional['content_upload']) && $additional['content_upload'] == true) {
     
    309388                    'headers' => $headers,
    310389                );
     390            } elseif (isset($additional['refresh_token'])) {
     391               $extra_headers = array();
     392               if (isset($additional['headers']) && !empty($additional['headers'])) {
     393                   foreach ($additional['headers'] as $key => $header) {
     394                       $extra_headers[] = $key.': '.$header;
     395                   }
     396                   unset($additional['headers']);
     397               }
     398               $headers = array();
     399               $headers[] = 'Authorization: Basic ' . base64_encode($this->consumerKey . ':' . $this->consumerSecret);
     400               // $headers[] = 'Content-Type: application/x-www-form-urlencoded';
     401               // $headers[] = 'Content-Type: application/json';
     402               $headers = array_merge($headers, $extra_headers);
     403
     404               return array(
     405                   'url' => $url . $call,
     406                   'postfields' => $additional,
     407                   'headers' => $headers,
     408               );
    311409            }
    312410        } else {
  • iwp-client/trunk/lib/Dropbox2/OAuth/Consumer/Curl.php

    r2128300 r2678176  
    3636     * @param string $callback
    3737     */
    38     public function __construct($key, $oauth2_id, $secret, Dropbox_StorageInterface $storage, $callback = null, $callbackhome = null, $deauthenticate = false)
     38    public function __construct($key, $oauth2_id, $secret, Dropbox_StorageInterface $storage, $callback = null, $callbackhome = null, $deauthenticate = false, $instance_id = '', $old_auth = false)
    3939    {
    4040        // Check the cURL extension is loaded
     
    4949        $this->callback = $callback;
    5050        $this->callbackhome = $callbackhome;
    51        
    52    //      if ($deauthenticate) {
    53             // $this->deauthenticate();
    54    //      } else {
    55             // $this->authenticate();
    56    //      }
     51        $this->instance_id = $instance_id;
     52       
     53        if ($old_auth == false) {
     54            if ($deauthenticate) {
     55                $this->deauthenticate();
     56            } else {
     57                $this->authenticate();
     58            }
     59        }
    5760    }
    5861   
     
    6669     * @return string|object stdClass
    6770     */
    68     public function fetch($method, $url, $call, array $additional = array())
     71    public function fetch($method, $url, $call, array $additional = array(), $retry_with_header = false)
    6972    {
    7073        // Get the signed request URL
    7174        $request = $this->getSignedRequest($method, $url, $call, $additional);
    72        
     75
    7376        // Initialise and execute a cURL request
    7477        $handle = curl_init($request['url']);
     
    105108            }
    106109        }
    107        
    108         // if (isset($request['headers'])) $options[CURLOPT_HTTPHEADER] = $request['headers'];
    109110
    110111        /*
     
    120121            }
    121122        }
     123
    122124        if (isset($request['headers']) && !empty($request['headers'])) $options[CURLOPT_HTTPHEADER] = $request['headers'];
    123125
     
    142144        } elseif ($method == 'POST') { // POST
    143145            $options[CURLOPT_POST] = true;
    144             $options[CURLOPT_POSTFIELDS] = $request['postfields'];
     146            if (!empty($request['postfields'])) {
     147                $options[CURLOPT_POSTFIELDS] = $request['postfields'];
     148            } elseif (empty($additional['content_upload'])) {
     149                // JSON representation of nullity
     150                $options[CURLOPT_POSTFIELDS] = 'null';
     151            } elseif ($retry_with_header) {
     152                // It's a content upload, and there's no data. Versions of php-curl differ as to whether they add a Content-Length header automatically or not. Dropbox complains if it's not there. Here we have had a Dropbox 400 bad request returned so we try again with the header
     153                $options[CURLOPT_HTTPHEADER] = array_merge($options[CURLOPT_HTTPHEADER], array('Content-Length: 0'));
     154            }
    145155        } elseif ($method == 'PUT' && $this->inFile) { // PUT
    146156            $options[CURLOPT_PUT] = true;
     
    152162        }
    153163
     164        if (isset($additional['timeout'])) {
     165            $options[CURLOPT_TIMEOUT] = $additional['timeout'];
     166        }
     167
    154168        // Set the cURL options at once
    155169        curl_setopt_array($handle, $options);
     
    168182            if (is_string($response)) {
    169183                $response = $this->parse($response);
    170                 $response['code'] = (!empty($response['code'])) ? $response['code'] : $getinfo['http_code'];
    171184            }
    172185           
     
    192205                        $message = json_encode($array);
    193206                    } elseif (strpos($array[0] , 'lookup_failed') !== false ) {
    194                         //re-structure the array so it is correctly formatted for API
    195                         //Note: Dropbox v2 returns different errors at different stages hence this fix
     207                        // re-structure the array so it is correctly formatted for API
     208                        // Note: Dropbox v2 returns different errors at different stages hence this fix
    196209                        $correctOffset = array(
    197210                            '0' => $array[1]->{'.tag'},
    198                             '1' => $array[1]->correct_offset
    199211                        );
     212                        // the lookup_failed response doesn't always return a correct_offset this happens when the lookup fails because the session has been closed e.g the file has already been uploaded but the response didn't make it back to the client so we try again
     213                        if (isset($array[1]->correct_offset)) $correctOffset['1'] = $array[1]->correct_offset;
    200214
    201215                        $message = json_encode($correctOffset);
     
    217231                        throw new Dropbox_NotModifiedException($message, 304);
    218232                    case 400:
     233                        if (!$retry_with_header) return $this->fetch($method, $url, $call, $additional, true);
    219234                        throw new Dropbox_BadRequestException($message, 400);
    220235                    case 404:
     
    225240                        throw new Dropbox_UnsupportedMediaTypeException($message, 415);
    226241                    case 401:
    227                         //401 means oauth token is expired continue to manually handle the exception depending on the situation
    228                         break;
     242                        //401 means oauth token is expired continue to manually handle the exception depending on the situation
     243                        break;
    229244                    case 409:
    230245                        //409 in API V2 every error will return with a 409 to find out what the error is the error description should be checked.                     
     
    254269        // If the status code is 100, the API server must send a final response
    255270        // We need to explode the response again to get the actual response
    256         if (preg_match('#^HTTP/1.1 100#i', $lines[0])) {
     271        if (preg_match('#^HTTP/[\.\d]+ 100#i', $lines[0])) {
    257272            list($headers, $response) = explode("\r\n\r\n", $response, 2);
    258273            $lines = explode("\r\n", $headers);
     
    261276        // Get the HTTP response code from the first line
    262277        $first = array_shift($lines);
    263         $pattern = '#^HTTP/1.1 ([0-9]{3})#i';
     278        $pattern = '#^HTTP/[\.\d]+ ([0-9]{3})#i';
    264279        preg_match($pattern, $first, $matches);
    265280        $code = $matches[1];
     
    280295         if (is_string($body)) {
    281296             $body_lines = explode("\r\n", $body);
    282              if (preg_match('#^HTTP/1.1 100#i', $body_lines[0]) && preg_match('#^HTTP/1.#i', $body_lines[2])) {
     297             if (preg_match('#^HTTP/[\.\d]+ 100#i', $body_lines[0]) && preg_match('#^HTTP/\d#i', $body_lines[2])) {
    283298             return $this->parse($body);
    284299             }
  • iwp-client/trunk/lib/Dropbox2/OAuth/Consumer/WordPress.php

    r1851728 r2678176  
    33/**
    44* OAuth consumer using the WordPress API
    5 * @author David Anderson <[email protected]>
    65* @link https://github.com/DavidAnderson684/Dropbox
    76* @package Dropbox\OAuth
  • iwp-client/trunk/lib/Dropbox2/OAuth/Storage/Encrypter.php

    r1851728 r2678176  
    99 * @subpackage Storage
    1010 */
    11 
    12 /*
    13 Using this was fairly pointless (it encrypts storage credentials at rest). But, it's implemented now, so needs supporting.
    14 Investigation shows that mcrypt and phpseclib native encryption using different padding schemes.
    15 As a result, that which is encrypted by phpseclib native can be decrypted by mcrypt, but not vice-versa. Each can (as you'd expect) decrypt the results of their own encryption.
    16 As a consequence, it makes sense to always encrypt with phpseclib native, and prefer decrypting with with mcrypt if it is available and otherwise fall back to phpseclib.
    17 We could deliberately re-encrypt all loaded information with phpseclib native, but there seems little need for that yet. There can only be a problem if mcrypt is disabled - which pre-July-2015 meant that Dropbox wouldn't work at all. Now, it will force a re-authorisation.
    18 */
    1911
    2012class Dropbox_Encrypter
     
    5850
    5951        // Encryption: we always use phpseclib for this
     52        global $iwp_backup_core;
     53        $ensure_phpseclib = $iwp_backup_core->ensure_phpseclib('Crypt_AES');
     54       
     55        if (is_wp_error($ensure_phpseclib)) {
     56            $iwp_backup_core->log("Failed to load phpseclib classes (".$ensure_phpseclib->get_error_code()."): ".$ensure_phpseclib->get_error_message());
     57            $iwp_backup_core->log("Failed to load phpseclib classes (".$ensure_phpseclib->get_error_code()."): ".$ensure_phpseclib->get_error_message(), 'error');
     58            return false;
     59        }
     60       
     61        $iwp_backup_core->ensure_phpseclib('Crypt_Rijndael');
    6062
    61         global $iwp_backup_core;
    62         $iwp_backup_core->ensure_phpseclib('Crypt_AES', 'Crypt/AES');
    63         $iwp_backup_core->ensure_phpseclib('Crypt_Rijndael', 'Crypt/Rijndael');
    64 
    65         if (!function_exists('crypt_random_string')) require_once($GLOBALS['iwp_mmb_plugin_dir'].'/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php');
     63        if (!function_exists('crypt_random_string')) require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/phpseclib/phpseclib/phpseclib/Crypt/Random.php');
    6664       
    6765        $iv = crypt_random_string(self::IV_SIZE);
     
    9492   
    9593        if (function_exists('mcrypt_decrypt')) {
     94            // @codingStandardsIgnoreLine
    9695            $token = @mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $cipherText, MCRYPT_MODE_CBC, $iv);
    9796        } else {
    9897            global $iwp_backup_core;
    99             $iwp_backup_core->ensure_phpseclib('Crypt_Rijndael', 'Crypt/Rijndael');
     98            $iwp_backup_core->ensure_phpseclib('Crypt_Rijndael');
    10099
    101100            $rijndael = new Crypt_Rijndael();
  • iwp-client/trunk/lib/Dropbox2/OAuth/Storage/WordPress.php

    r2548691 r2678176  
    55 * This can only be used if you have a WordPress environment loaded, such that the (get|update|delete)_option functions are available
    66 * See an example usage in http://wordpress.org/extend/plugins/updraftplus
    7  * @author David Anderson <[email protected]>
    8  * @link https://updraftplus.com
    97 * @package Dropbox\Oauth
    108 * @subpackage Storage
     
    4745        }
    4846
    49         if ($backup_module_object instanceof IWP_MMB_UploadModule) {
    50             $this->backup_module_object = $backup_module_object;
    51         }
     47        $this->backup_module_object = $backup_module_object;
    5248
    5349        $this->option_name_prefix = $option_name_prefix;
     
    7167                    if (!empty($opts[$this->option_name_prefix.$type])) {
    7268                        $gettoken = $opts[$this->option_name_prefix.$type];
    73                         $token = $gettoken;
     69                        if (!empty($opts['email'])) {
     70                            $token = $this->decrypt($gettoken);
     71                        }else{
     72                            $token = $gettoken;
     73                        }
    7474                        return $token;
    7575                    }
     
    100100           
    101101            if ($type == 'access_token'){
    102                 $token = $this->encrypt($token);
     102                if (!empty($opts['email'])) {
     103                    $token = $this->encrypt($token);
     104                }
    103105                $opts[$this->option_name_prefix.$type] = $token;
    104106            } else if ($type == 'request_token' ) {
  • iwp-client/trunk/lib/sftp.php

    r2548691 r2678176  
    336336        }
    337337
     338        // Ensure phpseclib Crypt_Blowfish is loaded, over PEAR's
     339        $iwp_backup_core->ensure_phpseclib('Crypt_Blowfish', 'Crypt/Blowfish');
    338340        if (!$this->ssh->login($user, $pass)) {
    339341            $error_data = null;
  • iwp-client/trunk/pclzip.class.php

    r2548691 r2678176  
    34413441       
    34423442        // ----- Read the file content
     3443      if ($p_header['size'] > 0) {
    34433444        $v_content = @fread($v_file, $p_header['size']);
     3445      }else{
     3446        $v_content = '';
     3447      }
    34443448
    34453449        // ----- Close the file
  • iwp-client/trunk/plugin.compatibility.class.php

    r1851728 r2678176  
    140140    }
    141141
    142     public function fixPantheonGlobals()
     142    public function fixGlobals()
    143143    {
    144         if (!empty($_ENV['PANTHEON_ENVIRONMENT']) && !isset($GLOBALS['hook_suffix'])) {
     144        if (!isset($GLOBALS['hook_suffix'])) {
    145145            $GLOBALS['hook_suffix'] = null;
    146146        }
  • iwp-client/trunk/readme.txt

    r2548706 r2678176  
    11=== InfiniteWP Client ===
    2 Contributors: infinitewp
     2Contributors: infinitewp, amritanandh, rajkuppus
    33Tags: admin, administration, amazon, api, authentication, automatic, dashboard, dropbox, events, integration, manage, multisite, multiple, notification, performance, s3, security, seo, stats, tracking, infinitewp, updates, backup, restore, iwp, infinite
    44Requires at least: 3.1
    5 Tested up to: 5.7.2
     5Tested up to: 5.9
    66Stable tag: trunk
    77
     
    4848
    4949== Changelog ==
     50
     51= 1.9.6 - Feb 14th 2022 =
     52* Feature: Added support for Litespeed Cache.
     53* Improvement: Ensure phpseclib Crypt_Blowfish is loaded over PEAR’s version.
     54* Improvement: Enabled support for new Dropbox OAuth Authentication.
     55* Fix: Enabled version number for InfiniteWP MU plugin loader.
     56* Fix: Undefined array key “hook_suffix” warning.
     57* Fix: Delete SFTP test backup file on the remote server.
     58* Fix: PPL addon editor image not uploaded. (issue happening from 1.9.4.9).
     59* Fix: Fatal error while backing up a 0kb file using the single call method on site installed on site with php8 server.
    5060
    5161= 1.9.4.11 - Jun 16th 2021 =
Note: See TracChangeset for help on using the changeset viewer.