isLink() ) { $files_size += $file->getSize(); } } return $files_size; } /** * Get an absolute path if it is relative * * @param string $path * * @return string */ public static function get_absolute_path( $path = '/' ) { $path = str_replace( '\\', '/', $path ); $content_path = trailingslashit( str_replace( '\\', '/', WP_CONTENT_DIR ) ); //use WP_CONTENT_DIR as root folder if ( empty( $path ) || $path === '/' ) { $path = $content_path; } //make relative path to absolute if ( substr( $path, 0, 1 ) !== '/' && ! preg_match( '#^[a-zA-Z]:/#', $path ) ) { $path = $content_path . $path; } return $path; } /** * * Check is folder readable and exists create it if not * add .htaccess or index.html file in folder to prevent directory listing * * @param string $folder the folder to check * @param bool $donotbackup Create a file that the folder will not backuped * * @return string with error message if one */ public static function check_folder( $folder, $donotbackup = FALSE ) { $folder = BackWPup_File::get_absolute_path( $folder ); $folder = untrailingslashit( $folder ); //check that is not home of WP $uploads = BackWPup_File::get_upload_dir(); if ( $folder === untrailingslashit( str_replace( '\\', '/', ABSPATH ) ) || $folder === untrailingslashit( str_replace( '\\', '/', dirname( ABSPATH ) ) ) || $folder === untrailingslashit( str_replace( '\\', '/', WP_PLUGIN_DIR ) ) || $folder === untrailingslashit( str_replace( '\\', '/', WP_CONTENT_DIR ) ) || $folder === untrailingslashit( $uploads ) || $folder === '/' ) { return sprintf( __( 'Folder %1$s not allowed, please use another folder.', 'backwpup' ), $folder ); } //open base dir check if ( ! BackWPup_File::is_in_open_basedir( $folder ) ) { return sprintf( __( 'Folder %1$s is not in open basedir, please use another folder.', 'backwpup' ), $folder ); } //create folder if it not exists if ( ! is_dir( $folder ) ) { if ( ! wp_mkdir_p( $folder ) ) { return sprintf( __( 'Cannot create folder: %1$s', 'backwpup' ), $folder ); } } //check is writable dir if ( ! is_writable( $folder ) ) { return sprintf( __( 'Folder "%1$s" is not writable', 'backwpup' ), $folder ); } //create files for securing folder if ( get_site_option( 'backwpup_cfg_protectfolders' ) ) { $server_software = strtolower( $_SERVER[ 'SERVER_SOFTWARE' ] ); //IIS if ( strstr( $server_software, 'microsoft-iis' ) ) { if ( ! file_exists( $folder . '/Web.config' ) ) { file_put_contents( $folder . '/Web.config', "" . PHP_EOL . "\t" . PHP_EOL . "\t\t" . PHP_EOL . "\t\t\t" . PHP_EOL . "\t\t" . PHP_EOL . "\t" . PHP_EOL . "" ); } } //Nginx elseif ( strstr( $server_software, 'nginx' ) ) { if ( ! file_exists( $folder . '/index.php' ) ) { file_put_contents( $folder . '/index.php', "" . PHP_EOL . "" . PHP_EOL . "Deny from all" . PHP_EOL . "" . PHP_EOL . "" . PHP_EOL . "" . PHP_EOL . "Deny from all" . PHP_EOL . "" . PHP_EOL . "" . PHP_EOL . "" . PHP_EOL . "Deny from all" . PHP_EOL . "" . PHP_EOL . "" ); } if ( ! file_exists( $folder . '/index.php' ) ) { file_put_contents( $folder . '/index.php', "