From fc0d8da877459dfff1596c297807ebadabd1b998 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 19 Jun 2024 10:29:28 +0200 Subject: [PATCH] Pro release 4.1.1 --- assets/js/backup-downloader.min.min.js | 1 + assets/js/notice.min.min.js | 1 + backwpup.php | 45 +- changelog.txt | 7 + inc/ThirdParty/Autoptimize.php | 65 ++ inc/ThirdParty/Breeze.php | 72 ++ inc/ThirdParty/HummingbirdPerformance.php | 77 ++ inc/ThirdParty/SGCachepress.php | 67 ++ inc/ThirdParty/W3TotalCache.php | 69 ++ inc/ThirdParty/WPFastestCache.php | 73 ++ inc/ThirdParty/WPOptimize.php | 73 ++ inc/ThirdParty/WPRocket.php | 69 ++ inc/ThirdParty/WPSuperCache.php | 67 ++ inc/ThirdParty/thirdPartyInterface.php | 38 + inc/class-admin.php | 96 +- inc/class-directory.php | 105 ++- inc/class-job.php | 86 +- inc/class-jobtype-file.php | 15 +- inc/class-mysqldump.php | 6 +- inc/class-page-about.php | 119 ++- inc/class-page-restore.php | 439 +++++---- inc/class-page-settings.php | 100 +- inc/class-thirdparties.php | 40 + inc/class-wp-cli.php | 282 +++--- .../plugin-environment-checker/LICENSE | 361 ++++++++ .../Constraints/AbstractVersionConstraint.php | 69 ++ .../src/Constraints/ConstraintInterface.php | 24 + .../src/Constraints/ConstraintsCollection.php | 26 + .../src/Constraints/ExtensionConstraint.php | 42 + .../src/Constraints/PhpConstraint.php | 31 + .../src/Constraints/PluginConstraint.php | 76 ++ .../src/Constraints/WordPressConstraint.php | 34 + .../src/ConstraintsCollectionFactory.php | 22 + .../ConstraintsCollectionFactoryInterface.php | 12 + .../src/EnvironmentChecker.php | 65 ++ .../Exception/ConstraintFailedException.php | 64 ++ .../ConstraintFailedExceptionInterface.php | 28 + languages/backwpup.pot | 356 +++---- readme.md | 81 +- readme.txt | 874 ++---------------- vendor/autoload.php | 20 +- vendor/composer/ClassLoader.php | 137 ++- vendor/composer/InstalledVersions.php | 33 +- vendor/composer/LICENSE | 2 - vendor/composer/autoload_classmap.php | 39 +- vendor/composer/autoload_files.php | 8 +- vendor/composer/autoload_namespaces.php | 2 +- vendor/composer/autoload_psr4.php | 3 +- vendor/composer/autoload_real.php | 60 +- vendor/composer/autoload_static.php | 60 +- vendor/composer/include_paths.php | 2 +- vendor/composer/installed.json | 178 +--- vendor/composer/installed.php | 111 +-- vendor/phpseclib/phpseclib/BACKERS.md | 4 +- .../phpseclib/phpseclib/Crypt/Blowfish.php | 295 +++--- .../phpseclib/Crypt/Common/AsymmetricKey.php | 4 +- .../Crypt/Common/Formats/Keys/OpenSSH.php | 8 +- .../Crypt/Common/Formats/Keys/PKCS8.php | 3 +- .../phpseclib/Crypt/Common/SymmetricKey.php | 2 + .../phpseclib/Crypt/EC/Formats/Keys/PKCS8.php | 14 +- .../Crypt/EC/Formats/Signature/IEEE.php | 66 ++ .../phpseclib/Crypt/EC/PrivateKey.php | 2 +- .../phpseclib/phpseclib/Crypt/RSA.php | 1 + .../phpseclib/phpseclib/Crypt/Rijndael.php | 4 +- .../InvalidPacketLengthException.php | 10 + .../phpseclib/phpseclib/File/ASN1.php | 5 + .../phpseclib/phpseclib/File/X509.php | 3 +- .../phpseclib/phpseclib/Math/BigInteger.php | 5 +- .../Engines/BCMath/Reductions/Barrett.php | 2 +- .../Math/BigInteger/Engines/Engine.php | 16 +- .../phpseclib/Math/BigInteger/Engines/PHP.php | 28 + .../Engines/PHP/Reductions/Barrett.php | 2 +- .../Engines/PHP/Reductions/EvalBarrett.php | 2 +- .../Math/BigInteger/Engines/PHP32.php | 2 +- .../Math/BigInteger/Engines/PHP64.php | 2 +- .../phpseclib/phpseclib/Math/BinaryField.php | 9 + .../phpseclib/Math/PrimeField/Integer.php | 2 +- .../phpseclib/phpseclib/Net/SFTP.php | 30 +- .../phpseclib/phpseclib/Net/SSH2.php | 605 ++++++------ .../phpseclib/phpseclib/bootstrap.php | 10 - views/restore/dashboard.php | 16 +- views/restore/download-log.php | 4 +- views/restore/index.php | 6 +- views/restore/main.php | 52 +- views/restore/notifications.php | 14 +- views/restore/steps/step1_action.php | 64 +- views/restore/steps/step1_top.php | 52 +- views/restore/steps/step2_action.php | 81 +- views/restore/steps/step2_top.php | 51 +- views/restore/steps/step3_action.php | 106 +-- views/restore/steps/step3_top.php | 44 +- views/restore/steps/step4_action.php | 66 +- views/restore/steps/step4_top.php | 8 +- views/restore/steps/step5_action.php | 32 +- views/restore/steps/step5_top.php | 21 +- views/restore/steps/step6_action.php | 26 +- views/restore/steps/step6_top.php | 68 +- 97 files changed, 3829 insertions(+), 2850 deletions(-) create mode 100644 assets/js/backup-downloader.min.min.js create mode 100644 assets/js/notice.min.min.js create mode 100644 inc/ThirdParty/Autoptimize.php create mode 100644 inc/ThirdParty/Breeze.php create mode 100644 inc/ThirdParty/HummingbirdPerformance.php create mode 100644 inc/ThirdParty/SGCachepress.php create mode 100644 inc/ThirdParty/W3TotalCache.php create mode 100644 inc/ThirdParty/WPFastestCache.php create mode 100644 inc/ThirdParty/WPOptimize.php create mode 100644 inc/ThirdParty/WPRocket.php create mode 100644 inc/ThirdParty/WPSuperCache.php create mode 100644 inc/ThirdParty/thirdPartyInterface.php create mode 100644 inc/class-thirdparties.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/LICENSE create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/AbstractVersionConstraint.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/ConstraintInterface.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/ConstraintsCollection.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/ExtensionConstraint.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/PhpConstraint.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/PluginConstraint.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Constraints/WordPressConstraint.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/ConstraintsCollectionFactory.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/ConstraintsCollectionFactoryInterface.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/EnvironmentChecker.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Exception/ConstraintFailedException.php create mode 100644 inc/dependencies/inpsyde/plugin-environment-checker/src/Exception/ConstraintFailedExceptionInterface.php create mode 100644 vendor/phpseclib/phpseclib/phpseclib/Crypt/EC/Formats/Signature/IEEE.php create mode 100644 vendor/phpseclib/phpseclib/phpseclib/Exception/InvalidPacketLengthException.php diff --git a/assets/js/backup-downloader.min.min.js b/assets/js/backup-downloader.min.min.js new file mode 100644 index 00000000..3e43b423 --- /dev/null +++ b/assets/js/backup-downloader.min.min.js @@ -0,0 +1 @@ +window.BWU=window.BWU||{},function(i,s,n,e,t){var r,o,c;function a(){this.closeEventSource(),this.cleanUi(),this.decrypter&&this.decrypter.destruct()}function d(e){e&&(e.style.display="none")}function h(e){e&&(e.style.display="block")}e?"EventSource"in window?(c={showWaitingMessage:function(){h(this.waitingUi)},showProgressUi:function(){h(this.progressUi)},showSuccessMsg:function(){h(this.successUi)},hideWaitingMessage:function(){d(this.waitingUi)},hideProgressUi:function(){d(this.progressUi)},hideNotice:function(){n.Functions.removeMessages(this.containerUi)},hideSuccessMsg:function(){d(this.successUi)},cleanUi:function(){this.hideWaitingMessage(),this.hideProgressUi(),this.hideNotice(),this.hideSuccessMsg(),this.decrypter&&this.decrypter.hide()},done:function(){this.showSuccessMsg(),window.location.href=this.currentTarget.dataset.url,setTimeout(t,3e3)},onMessage:function(e){var t;try{switch((t=JSON.parse(e.data)).state){case n.States.DOWNLOADING:this.cleanUi(),this.showProgressUi(),i("#progresssteps").css({width:t.download_percent+"%"}).text(t.download_percent+"%");break;case n.States.DONE:this.done(t.message)}}catch(e){n.Functions.printMessageError(e.message,this.containerUi),a.call(this)}},onError:function(e){var t=JSON.parse(e.data);switch(this.closeEventSource(),t.message){case n.States.NEED_DECRYPTION_KEY:this.cleanUi(),this.decrypter&&this.decrypter.needDecryption(t.status);break;default:n.Functions.printMessageError(t.message,this.containerUi),a.call(this)}return this},initializeEventSource:function(){s.isUndefined(this.eventSource)&&(this.eventSource=new EventSource(e+"?action=download_backup_file&destination="+this.currentTarget.dataset.destination+"&jobid="+this.currentTarget.dataset.jobid+"&file="+this.currentTarget.dataset.file+"&local_file="+this.currentTarget.dataset.localFile+"&backwpup_action_nonce="+this.currentTarget.dataset.nonce),this.eventSource.onmessage=this.onMessage,this.eventSource.addEventListener("log",this.onError))},closeEventSource:function(){s.isUndefined(this.eventSource)||(this.eventSource.close(),this.eventSource=void 0)},startDownload:function(e){e.preventDefault(),this.currentTarget=e.target,this.showWaitingMessage(),this.initializeEventSource()},decrypt:function(){this.cleanUi(),this.decrypter&&this.decrypter.decrypt({backwpup_action_nonce:this.currentTarget.dataset.nonce,encrypted_file_path:this.currentTarget.dataset.localFile})},construct:function(e){var t=document.querySelector("#tb_container");return!!t&&(s.bindAll(this,"showWaitingMessage","hideWaitingMessage","showProgressUi","hideSuccessMsg","showSuccessMsg","done","onMessage","onError","initializeEventSource","closeEventSource","startDownload","addListeners","decrypt","hideNotice","cleanUi","init"),this.containerUi=t,this.waitingUi=this.containerUi.querySelector("#download-file-waiting"),this.progressUi=this.containerUi.querySelector(".progressbar"),this.successUi=this.containerUi.querySelector("#download-file-success"),this.currentTarget=void 0,this.eventSource=void 0,this.decrypter=e,this)},addListeners:function(){return s.forEach(document.querySelectorAll("#backup-download-link"),function(e){e.addEventListener("click",this.startDownload)}.bind(this)),i("#submit_decrypt_key").on("click",this.decrypt),i("body").on("thickbox:removed",function(){a.call(this)}.bind(this)),this.decrypter&&i("body").on(this.decrypter.ACTION_DECRYPTION_SUCCESS,this.done),this},init:function(){return this.addListeners(),this}},r=Object.create(c),s.isUndefined(n.DecrypterFactory)||(o=n.DecrypterFactory(e,document.querySelector("#decrypt_key"),document.querySelector("#decryption_key"))),r.construct(o)&&r.init()):console.warn("Event Source does not exist in this browser"):console.warn("Missing ajaxurl value.")}(window.jQuery,window._,window.BWU,window.ajaxurl,window.tb_remove); \ No newline at end of file diff --git a/assets/js/notice.min.min.js b/assets/js/notice.min.min.js new file mode 100644 index 00000000..b496e6f3 --- /dev/null +++ b/assets/js/notice.min.min.js @@ -0,0 +1 @@ +!function(i,n){var t={dismiss:function(t){t.preventDefault(),t.stopImmediatePropagation(),n.post(n(t.target).attr("href"),{isAjax:1}),n(t.target).closest(".notice-inpsyde").remove()},construct:function(){var t;return i.bindAll(this,"dismiss","init","addListeners"),0!==(t=n(".notice-inpsyde")).length&&(this.$container=t,this)},addListeners:function(){var t=this.$container.find(".dismiss-button");0 'backwpup', ]; + // Register the third party services. + BackWPup_ThirdParties::register(); + // Load pro features if (self::$is_pro) { $license = new License( @@ -164,8 +167,8 @@ private function __construct() // Work with wp-cli if (defined(\WP_CLI::class) && WP_CLI && method_exists(\WP_CLI::class, 'add_command')) { WP_CLI::add_command('backwpup', \BackWPup_WP_CLI::class); - } - } + } + } /** * @return self @@ -224,20 +227,22 @@ public static function get_plugin_data($name = null) 'version' => 'Version', ], 'plugin' - ); - self::$plugin_data['name'] = trim(self::$plugin_data['name']); - //set some extra vars - self::$plugin_data['basename'] = plugin_basename(__DIR__); - self::$plugin_data['mainfile'] = __FILE__; - self::$plugin_data['plugindir'] = untrailingslashit(__DIR__); - self::$plugin_data['hash'] = get_site_option('backwpup_cfg_hash'); - if (empty(self::$plugin_data['hash']) || strlen(self::$plugin_data['hash']) < 6 - || strlen( - self::$plugin_data['hash'] - ) > 12) { - self::$plugin_data['hash'] = self::get_generated_hash(6); - update_site_option('backwpup_cfg_hash', self::$plugin_data['hash']); - } + ); + self::$plugin_data['name'] = trim( self::$plugin_data['name'] ); + // set some extra vars. + self::$plugin_data['basename'] = plugin_basename( __DIR__ ); + self::$plugin_data['mainfile'] = __FILE__; + self::$plugin_data['plugindir'] = untrailingslashit( __DIR__ ); + self::$plugin_data['pluginincdir'] = untrailingslashit( self::$plugin_data['plugindir'] . '/inc' ); + self::$plugin_data['plugin3rdpartydir'] = untrailingslashit( self::$plugin_data['pluginincdir'] . '/ThirdParty' ); + self::$plugin_data['hash'] = get_site_option( 'backwpup_cfg_hash' ); + if ( empty( self::$plugin_data['hash'] ) || strlen( self::$plugin_data['hash'] ) < 6 + || strlen( + self::$plugin_data['hash'] + ) > 12 ) { + self::$plugin_data['hash'] = self::get_generated_hash( 6 ); + update_site_option( 'backwpup_cfg_hash', self::$plugin_data['hash'] ); + } if (defined('WP_TEMP_DIR') && is_dir(WP_TEMP_DIR)) { self::$plugin_data['temp'] = str_replace( '\\', diff --git a/changelog.txt b/changelog.txt index 8f5a1567..b1b5124a 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,11 @@ == Changelog == += 4.1.1 = +Release date: Jun 18, 2024 + +* Changed: AutoExclude the cache plugin folders from the backup +* Fixed: Problems with the sql dump of the database +* Fixed: Update phpseclib library to fix issues in Windows environment. + = 4.1.0 = Release date: Jun 4, 2024 diff --git a/inc/ThirdParty/Autoptimize.php b/inc/ThirdParty/Autoptimize.php new file mode 100644 index 00000000..f28920a6 --- /dev/null +++ b/inc/ThirdParty/Autoptimize.php @@ -0,0 +1,65 @@ +basedir, $excluded_folders, true ) ) { + $excluded_folders[] = $humming_bird_filesystem->basedir; + } + if ( ! in_array( WPHB_DIR_PATH, $excluded_folders, true ) ) { + $excluded_folders[] = WPHB_DIR_PATH; + } + return $excluded_folders; + } + + /** + * {@inheritdoc} + * + * @param array $excluded_cache_folders + * + * @return mixed + */ + public function exclude_cache_folders( $excluded_cache_folders ) { + if ( + ! is_array( $excluded_cache_folders ) || + ! self::is_active() + ) { + return $excluded_cache_folders; + } + $humming_bird_filesystem = \Hummingbird\Core\Filesystem::instance(); + if ( ! in_array( $humming_bird_filesystem->cache_dir, $excluded_cache_folders, true ) ) { + $excluded_cache_folders[] = $humming_bird_filesystem->cache_dir; + } + if ( ! in_array( $humming_bird_filesystem->gravatar_dir, $excluded_cache_folders, true ) ) { + $excluded_cache_folders[] = $humming_bird_filesystem->gravatar_dir; + } + + return $excluded_cache_folders; + } + + /** + * {@inheritdoc}. + * + * @return bool + */ + public static function is_active(): bool { + return defined( 'WPHB_VERSION' ); + } + + /** + * {@inheritdoc} + * + * @return void + */ + public function init(): void { + if ( self::is_active() ) { + add_filter( 'backwpup_exclusion_plugins_folders', [ $this, 'exclude_folders' ] ); + add_filter( 'backwpup_exclusion_plugins_cache_folders', [ $this, 'exclude_cache_folders' ] ); + } + } +} diff --git a/inc/ThirdParty/SGCachepress.php b/inc/ThirdParty/SGCachepress.php new file mode 100644 index 00000000..b5fc9138 --- /dev/null +++ b/inc/ThirdParty/SGCachepress.php @@ -0,0 +1,67 @@ +get_cache_dir(), $excluded_cache_folders, true ) ) { + $excluded_cache_folders[] = $file_cacher->get_cache_dir(); + } + return $excluded_cache_folders; + } + + /** + * {@inheritdoc}. + * + * @return bool + */ + public static function is_active(): bool { + return defined( 'SiteGround_Optimizer\VERSION' ); + } + + /** + * {@inheritdoc} + * + * @return void + */ + public function init(): void { + if ( self::is_active() ) { + add_filter( 'backwpup_exclusion_plugins_folders', [ $this, 'exclude_folders' ] ); + add_filter( 'backwpup_exclusion_plugins_cache_folders', [ $this, 'exclude_cache_folders' ] ); + } + } +} diff --git a/inc/ThirdParty/W3TotalCache.php b/inc/ThirdParty/W3TotalCache.php new file mode 100644 index 00000000..779fac6a --- /dev/null +++ b/inc/ThirdParty/W3TotalCache.php @@ -0,0 +1,69 @@ + 'cache', + ]; + } + if ( ! in_array( trailingslashit( WPFC_WP_CONTENT_DIR . '/' . $wpfc_cache_path['cachepath'] ), $excluded_cache_folders, true ) ) { + $excluded_cache_folders[] = trailingslashit( WPFC_WP_CONTENT_DIR . '/' . $wpfc_cache_path['cachepath'] ); + } + return $excluded_cache_folders; + } + + /** + * {@inheritDoc} + * + * @return bool + */ + public static function is_active(): bool { + return defined( 'WPFC_WP_CONTENT_BASENAME' ); + } + + /** + * {@inheritDoc} + * + * @return void + */ + public function init(): void { + if ( self::is_active() ) { + add_filter( 'backwpup_exclusion_plugins_folders', [ $this, 'exclude_folders' ] ); + add_filter( 'backwpup_exclusion_plugins_cache_folders', [ $this, 'exclude_cache_folders' ] ); + } + } +} diff --git a/inc/ThirdParty/WPOptimize.php b/inc/ThirdParty/WPOptimize.php new file mode 100644 index 00000000..1ebab5c8 --- /dev/null +++ b/inc/ThirdParty/WPOptimize.php @@ -0,0 +1,73 @@ +init(WordPressNotice::TYPE_ADMIN); // Show notice if PHP < 7.2 $phpNotice = new PhpNotice( new NoticeView(PhpNotice::ID) @@ -472,43 +476,42 @@ public function admin_page_settings($page_hooks) return $page_hooks; } - /** - * Admin Page Restore. - * - * @param array $page_hooks the page hooks list - * - * @return array $page_hooks - */ - public function admin_page_restore($page_hooks) - { - $this->page_hooks['backwpuprestore'] = add_submenu_page( - 'backwpup', - esc_html__('Restore', 'backwpup'), - esc_html__('Restore', 'backwpup'), - 'backwpup_restore', - 'backwpuprestore', - [ - \BackWPup_Page_Restore::class, - 'page', + /** + * Admin Page Restore. + * + * @param array $page_hooks the page hooks list + * + * @return array $page_hooks + */ + public function admin_page_restore( $page_hooks ) { + $this->page_hooks['backwpuprestore'] = add_submenu_page( + 'backwpup', + esc_html__( 'Restore', 'backwpup' ), + esc_html__( 'Restore', 'backwpup' ), + 'backwpup_restore', + 'backwpuprestore', + [ + \BackWPup_Page_Restore::class, + 'page', ] ); - // Register the submenu page (WP take care of capability) but prevent other stuffs to be executed if user - // doesn't have correct privileges. - if (!current_user_can('backwpup_restore')) { - return $page_hooks; - } - - add_action('load-' . $this->page_hooks['backwpuprestore'], [\BackWPup_Admin::class, 'init_general']); - add_action( - 'load-' . $this->page_hooks['backwpuprestore'], - [\BackWPup_Page_Restore::class, 'load'] - ); - add_action( - 'admin_print_scripts-' . $this->page_hooks['backwpuprestore'], - [ - \BackWPup_Page_Restore::class, - 'admin_print_scripts', + // Register the submenu page (WP take care of capability) but prevent other stuffs to be executed if user + // doesn't have correct privileges. + if ( ! current_user_can( 'backwpup_restore' ) ) { + return $page_hooks; + } + + add_action( 'load-' . $this->page_hooks['backwpuprestore'], [ self::class, 'init_general' ] ); + add_action( + 'load-' . $this->page_hooks['backwpuprestore'], + [ \BackWPup_Page_Restore::class, 'load' ] + ); + add_action( + 'admin_print_scripts-' . $this->page_hooks['backwpuprestore'], + [ + \BackWPup_Page_Restore::class, + 'admin_print_scripts', ] ); @@ -803,19 +806,18 @@ public function save_profile_update($user_id) } } - public function init() - { - $restore = new Restore(); - $restore->set_hooks()->init(); - - //Add menu pages - add_filter('backwpup_admin_pages', [$this, 'admin_page_jobs'], 2); - add_filter('backwpup_admin_pages', [$this, 'admin_page_editjob'], 3); - add_filter('backwpup_admin_pages', [$this, 'admin_page_logs'], 4); - add_filter('backwpup_admin_pages', [$this, 'admin_page_backups'], 5); - add_filter('backwpup_admin_pages', [$this, 'admin_page_settings'], 6); - add_filter('backwpup_admin_pages', [$this, 'admin_page_restore'], 7); - add_filter('backwpup_admin_pages', [$this, 'admin_page_about'], 20); + public function init() { + $restore = new Restore(); + $restore->set_hooks()->init(); + + // Add menu pages + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_jobs' ], 2 ); + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_editjob' ], 3 ); + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_logs' ], 4 ); + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_backups' ], 5 ); + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_settings' ], 6 ); + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_restore' ], 7 ); + add_filter( 'backwpup_admin_pages', [ $this, 'admin_page_about' ], 20 ); //Add Menu if (is_multisite()) { diff --git a/inc/class-directory.php b/inc/class-directory.php index b45249ec..e1b730c4 100644 --- a/inc/class-directory.php +++ b/inc/class-directory.php @@ -5,17 +5,96 @@ * * @since 3.4.0 */ -class BackWPup_Directory extends DirectoryIterator -{ - /** - * Creates the iterator. - * - * Fixes the path before calling the parent constructor. - * - * @param string $path - */ - public function __construct($path) - { - parent::__construct(BackWPup_Path_Fixer::fix_path($path)); - } +class BackWPup_Directory extends DirectoryIterator { + + + /** + * The folders list of the plugins to auto exclude + * + * @var array + */ + private static $auto_exclusion_plugins_folders = []; + + /** + * The cache folder list of the plugins to auto exclude + * + * @var array + */ + private static $auto_exclusion_plugin_cache_folders = []; + + /** + * Creates the iterator. + * + * Fixes the path before calling the parent constructor. + * + * @param string $path + */ + public function __construct($path) + { + parent::__construct(BackWPup_Path_Fixer::fix_path($path)); + } + + /** + * Override the current function to avoid the backup of auto exclude plugins listed in self::$_auto_exclusion_plugins + * + * @return object + */ + public function current(): object { + $item = parent::current(); + if ( $item->isDir() && in_array( trailingslashit( $item->getPathname() ), self::get_auto_exclusion_plugin_cache_folders(), true ) ) { + $this->next(); + return $this->current(); + } + return $item; + } + + /** + * Get the folders of the excluded plugins + * + * @return array + */ + public static function get_auto_exclusion_plugins_folders(): array { + if ( 0 === count( self::$auto_exclusion_plugins_folders ) ) { + self::init_auto_exclusion_folders(); + + } + return self::$auto_exclusion_plugins_folders; + } + + /** + * Get the cache folders of the excluded plugins + * + * @return array + */ + public static function get_auto_exclusion_plugin_cache_folders(): array { + if ( 0 === count( self::$auto_exclusion_plugin_cache_folders ) ) { + self::init_auto_exclusion_folders(); + } + return self::$auto_exclusion_plugin_cache_folders; + } + + /** + * Init the excluded folders + * + * @return void + */ + private static function init_auto_exclusion_folders() { + /** + * Filter whether BackWPup will list the plugins in the excluded plugins list. + * + * @param array $excluded_folders List of excluded paths. + */ + $auto_exclusion_plugins_folders = apply_filters( 'backwpup_exclusion_plugins_folders', [] ); + /** + * Filter whether BackWPup will list the cache folders to include in the backup. + * + * @param array $excluded_folders List of excluded paths. + */ + $auto_exclusion_plugins_cache_folders = apply_filters( 'backwpup_exclusion_plugins_cache_folders', [] ); + $auto_exclusion_plugins_folders = ( ! is_array( $auto_exclusion_plugins_folders ) ? [] : $auto_exclusion_plugins_folders ); + $auto_exclusion_plugins_cache_folders = ( ! is_array( $auto_exclusion_plugins_cache_folders ) ? [] : $auto_exclusion_plugins_cache_folders ); + + self::$auto_exclusion_plugins_folders = array_unique( array_map( 'trailingslashit', $auto_exclusion_plugins_folders ) ); + self::$auto_exclusion_plugin_cache_folders = array_unique( array_map( 'trailingslashit', $auto_exclusion_plugins_cache_folders ) ); + } } diff --git a/inc/class-job.php b/inc/class-job.php index 032f697f..4b7eb992 100755 --- a/inc/class-job.php +++ b/inc/class-job.php @@ -1900,9 +1900,9 @@ private function create_archive() private function encrypt_archive() { $encryptionType = get_site_option('backwpup_cfg_encryption'); - // Substeps is number of 128 KB chunks - $blockSize = 128 * 1024; - $this->substeps_todo = $this->backup_filesize; + // Substeps is number of 128 KB chunks + $blockSize = 128 * 1024; + $this->substeps_todo = $this->backup_filesize; if (!isset($this->steps_data[$this->step_working]['encrypted_filename'])) { $this->steps_data[$this->step_working]['encrypted_filename'] = $this->backup_folder . $this->backup_file . '.encrypted'; @@ -1911,17 +1911,17 @@ private function encrypt_archive() } } - if (!isset($this->steps_data[$this->step_working]['key'])) { - $this->steps_data[$this->step_working]['OutFilePos'] = 0; - $this->steps_data[$this->step_working]['aesIv'] = \phpseclib3\Crypt\Random::string(16); - switch ($encryptionType) { - case self::ENCRYPTION_SYMMETRIC: + if ( ! isset( $this->steps_data[ $this->step_working ]['key'] ) ) { + $this->steps_data[ $this->step_working ]['OutFilePos'] = 0; + $this->steps_data[ $this->step_working ]['aesIv'] = \phpseclib3\Crypt\Random::string( 16 ); + switch ( $encryptionType ) { + case self::ENCRYPTION_SYMMETRIC: $this->steps_data[$this->step_working]['key'] = pack('H*', get_site_option('backwpup_cfg_encryptionkey')); break; - case self::ENCRYPTION_ASYMMETRIC: - $this->steps_data[$this->step_working]['key'] = \phpseclib3\Crypt\Random::string(32); - break; + case self::ENCRYPTION_ASYMMETRIC: + $this->steps_data[ $this->step_working ]['key'] = \phpseclib3\Crypt\Random::string( 32 ); + break; } if (empty($this->steps_data[$this->step_working]['key'])) { @@ -1958,19 +1958,19 @@ private function encrypt_archive() return false; } - $encryptor = null; - $key = $this->steps_data[$this->step_working]['key']; - $aesIv = $this->steps_data[$this->step_working]['aesIv']; + $encryptor = null; + $key = $this->steps_data[ $this->step_working ]['key']; + $aesIv = $this->steps_data[ $this->step_working ]['aesIv']; - switch ($encryptionType) { - case self::ENCRYPTION_SYMMETRIC: - $encryptor = new EncryptionStream($aesIv, $key, Utils::streamFor($fileOut)); - break; + switch ( $encryptionType ) { + case self::ENCRYPTION_SYMMETRIC: + $encryptor = new EncryptionStream( $aesIv, $key, Utils::streamFor( $fileOut ) ); + break; - case self::ENCRYPTION_ASYMMETRIC: - $rsaPubKey = get_site_option('backwpup_cfg_publickey'); - $encryptor = new EncryptionStream($aesIv, $key, Utils::streamFor($fileOut), $rsaPubKey); - break; + case self::ENCRYPTION_ASYMMETRIC: + $rsaPubKey = get_site_option( 'backwpup_cfg_publickey' ); + $encryptor = new EncryptionStream( $aesIv, $key, Utils::streamFor( $fileOut ), $rsaPubKey ); + break; } if ($encryptor === null) { @@ -1979,29 +1979,29 @@ private function encrypt_archive() return false; } - $fileIn->seek($this->substeps_done); - $encryptor->seek($this->steps_data[$this->step_working]['OutFilePos']); - - while (!$fileIn->eof()) { - $data = $fileIn->read($blockSize); - $outBytes = $encryptor->write($data); - $this->substeps_done += $blockSize; - $this->steps_data[$this->step_working]['OutFilePos'] += $outBytes; - $this->update_working_data(); - // Should we restart? - $restartTime = $this->get_restart_time(); - if ($restartTime <= 0) { - $fileIn->close(); - $encryptor->close(); - $this->do_restart_time(true); - } - } - $fileIn->close(); + $fileIn->seek( $this->substeps_done ); + $encryptor->seek( $this->steps_data[ $this->step_working ]['OutFilePos'] ); + + while ( ! $fileIn->eof() ) { + $data = $fileIn->read( $blockSize ); + $outBytes = $encryptor->write( $data ); + $this->substeps_done += $blockSize; + $this->steps_data[ $this->step_working ]['OutFilePos'] += $outBytes; + $this->update_working_data(); + // Should we restart? + $restartTime = $this->get_restart_time(); + if ( $restartTime <= 0 ) { + $fileIn->close(); + $encryptor->close(); + $this->do_restart_time( true ); + } + } + $fileIn->close(); $encryptor->close(); - $this->log( - sprintf(__('Encrypted %s of data.', 'backwpup'), size_format($this->substeps_done, 2)), - E_USER_NOTICE + $this->log( + sprintf( __( 'Encrypted %s of data.', 'backwpup' ), size_format( $this->substeps_done, 2 ) ), + E_USER_NOTICE ); // Remove the original file then rename the encrypted file diff --git a/inc/class-jobtype-file.php b/inc/class-jobtype-file.php index 715378fc..f2d42c82 100644 --- a/inc/class-jobtype-file.php +++ b/inc/class-jobtype-file.php @@ -528,13 +528,14 @@ private function show_folder($id, $jobid, $path) $dir = new BackWPup_Directory($folder); $excludes = BackWPup_Option::get($jobid, 'backup' . $id . 'excludedirs'); - foreach ($dir as $file) { - if (!$file->isDot() && $file->isDir() && !in_array(trailingslashit($file->getPathname()), $this->get_exclude_dirs($folder), true)) { - $donotbackup = file_exists($file->getPathname() . '/.donotbackup'); - $folder_size = (get_site_option('backwpup_cfg_showfoldersize')) ? ' (' . size_format(BackWPup_File::get_folder_size($file->getPathname()), 2) . ')' : ''; - $title = ''; - if ($donotbackup) { - $excludes[] = $file->getFilename(); + foreach ( $dir as $file ) { + // List only the folders without thoses listed by auto exclude! + if ( ! $file->isDot() && $file->isDir() && ! in_array( trailingslashit( $file->getPathname() ), $this->get_exclude_dirs( $folder, $dir::get_auto_exclusion_plugins_folders() ), true ) ) { + $donotbackup = file_exists( $file->getPathname() . '/.donotbackup' ); + $folder_size = ( get_site_option( 'backwpup_cfg_showfoldersize' ) ) ? ' (' . size_format( BackWPup_File::get_folder_size( $file->getPathname() ), 2 ) . ')' : ''; + $title = ''; + if ( $donotbackup ) { + $excludes[] = $file->getFilename(); $title = ' title="' . esc_attr__('Excluded by .donotbackup file!', 'backwpup') . '"'; } echo '