diff --git a/lib/common/common_helper.rb b/lib/common/common_helper.rb index ab756e20..6e271cfc 100644 --- a/lib/common/common_helper.rb +++ b/lib/common/common_helper.rb @@ -94,12 +94,6 @@ def missing_db_file? false end -def update_db - print 'Updating the DB ...' - DbUpdater.new(DATA_DIR).update - puts ' Done.' -end - # Define colors def colorize(text, color_code) if $COLORSWITCH diff --git a/lib/common/updater/db_updater.rb b/lib/common/updater/db_updater.rb index 049b4e28..67a1da37 100644 --- a/lib/common/updater/db_updater.rb +++ b/lib/common/updater/db_updater.rb @@ -65,7 +65,7 @@ class DbUpdater < Updater end def delete_backup(filename) - FileUtils.rm(backup_file_path(filename), force: true) + FileUtils.rm(backup_file_path(filename)) end # @return [ String ] The checksum of the downloaded file @@ -75,31 +75,42 @@ class DbUpdater < Updater res = Browser.get(file_url, request_params) fail "Error while downloading #{file_url}" unless res.code == 200 - File.write(file_path, res.body.chomp) + File.write(file_path, res.body) local_file_checksum(filename) end - def update + def update(verbose = false) FILES.each do |filename| begin + puts "[+] Checking #{filename}" if verbose db_checksum = remote_file_checksum(filename) # Checking if the file needs to be updated - next if File.exist?(local_file_path(filename)) && - db_checksum == local_file_checksum(filename) + if File.exist?(local_file_path(filename)) && db_checksum == local_file_checksum(filename) + puts ' [i] Already Up-To-Date' if verbose + next + end + puts ' [i] Needs to be updated' if verbose create_backup(filename) + puts ' [i] Backup Created' if verbose + puts ' [i] Downloading new file' dl_checksum = download(filename) + puts " [i] Downloaded File Checksum: #{dl_checksum}" if verbose unless dl_checksum == db_checksum fail "#{filename}: checksums do not match" end rescue => e + puts ' [i] Restoring Backup due to error' if verbose restore_backup(filename) raise e ensure - delete_backup(filename) + if File.exist?(backup_file_path(filename)) + puts ' [i] Deleting Backup' if verbose + delete_backup(filename) + end end end end diff --git a/wpscan.rb b/wpscan.rb index f140500e..d3e51643 100755 --- a/wpscan.rb +++ b/wpscan.rb @@ -43,7 +43,11 @@ def main wpscan_options.to_h.merge(max_threads: wpscan_options.threads) ) - update_db if wpscan_options.update || missing_db_file? + if wpscan_options.update || missing_db_file? + puts 'Updating the DB ...' + DbUpdater.new(DATA_DIR).update(wpscan_options.verbose) + puts 'Done.' + end # Check for updates if wpscan_options.update