$dest ] ); // Parse the filename to get the type of backup. $filename = pathinfo( $item['filename'] )['filename']; if ( stripos( $item['filename'], '.tar.gz' ) === strlen( $item['filename'] ) - 7 ) { $filename = substr( $item['filename'], 0, -7 ); } elseif ( stripos( $item['filename'], '.tar.bz2' ) === strlen( $item['filename'] ) - 8 ) { $filename = substr( $item['filename'], 0, -8 ); } $filename_parts = explode( '_', $filename ); if ( count( $filename_parts ) > 1 ) { $item['data'] = (array) explode( '-', end( $filename_parts ) ); } $local_file = untrailingslashit( BackWPup::get_plugin_data( 'TEMP' ) ) . "/{$item['filename']}"; $downloadurl = wp_nonce_url( $item['downloadurl'], 'backwpup_action_nonce' ); $downloadhref = '#TB_inline?height=300&inlineId=tb_download_file&width=640&height=412'; $downloadtrigger = 'download-backup'; // Add the download URL and dataset. $item['dataset-download'] = [ 'data-jobid' => $job_data['id'], 'data-destination' => $dest, 'data-file' => $item['file'], 'data-local-file' => $local_file, 'data-nonce' => wp_create_nonce( 'backwpup_action_nonce' ), 'data-url' => $downloadurl, 'data-href' => $downloadhref, ]; $item['download-trigger'] = $downloadtrigger; // If the user can restore, add the restore URL. if ( current_user_can( 'backwpup_restore' ) && ! empty( $item['restoreurl'] ) ) { $item['dataset-restore'] = [ 'label' => __( 'Restore Backup', 'backwpup' ), 'data-url' => wp_nonce_url( add_query_arg( [ 'step' => 1, 'trigger_download' => 1, ], $item['restoreurl'] ), 'restore-backup_' . $job_data['id'] ), ]; } elseif ( current_user_can( 'backwpup_restore' ) ) { $item['dataset-restore'] = [ 'label' => __( 'Restore Backup', 'backwpup' ), 'data-url' => network_admin_url( 'admin.php?page=backwpuprestore' ), ]; } // If the user can delete, add the delete URL. if ( current_user_can( 'backwpup_backups_delete' ) ) { $item['dataset-delete'] = [ 'data-url' => wp_nonce_url( add_query_arg( [ 'page' => 'backwpupbackups', 'action' => 'delete', 'jobdest-top' => $job_data['id'] . '_' . $dest, 'backupfiles[]' => esc_attr( $item['file'] ), 'paged' => $page, ], network_admin_url( 'admin.php' ) ), 'bulk-backups' ), ]; } } ); return $items; } /*** * Checks if the input string contains path traversal sequences like "..", "../", or "..\". * * @param string $input The input string to check. * @return bool True if the input contains path traversal sequences, false otherwise. */ private static function contains_path_traversal( string $input ): bool { return preg_match( '#(^|[\\\\/])\.\.([\\\\/]|$)#', $input ) === 1; } }