DB Update: fixes a bug due to .chomp, Adds verbose output

This commit is contained in:
erwanlr
2014-09-12 19:18:56 +02:00
parent f818778e0a
commit 3e94ca11df
3 changed files with 22 additions and 13 deletions

View File

@@ -94,12 +94,6 @@ def missing_db_file?
false false
end end
def update_db
print 'Updating the DB ...'
DbUpdater.new(DATA_DIR).update
puts ' Done.'
end
# Define colors # Define colors
def colorize(text, color_code) def colorize(text, color_code)
if $COLORSWITCH if $COLORSWITCH

View File

@@ -65,7 +65,7 @@ class DbUpdater < Updater
end end
def delete_backup(filename) def delete_backup(filename)
FileUtils.rm(backup_file_path(filename), force: true) FileUtils.rm(backup_file_path(filename))
end end
# @return [ String ] The checksum of the downloaded file # @return [ String ] The checksum of the downloaded file
@@ -75,31 +75,42 @@ class DbUpdater < Updater
res = Browser.get(file_url, request_params) res = Browser.get(file_url, request_params)
fail "Error while downloading #{file_url}" unless res.code == 200 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) local_file_checksum(filename)
end end
def update def update(verbose = false)
FILES.each do |filename| FILES.each do |filename|
begin begin
puts "[+] Checking #{filename}" if verbose
db_checksum = remote_file_checksum(filename) db_checksum = remote_file_checksum(filename)
# Checking if the file needs to be updated # Checking if the file needs to be updated
next if File.exist?(local_file_path(filename)) && if File.exist?(local_file_path(filename)) && db_checksum == local_file_checksum(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) create_backup(filename)
puts ' [i] Backup Created' if verbose
puts ' [i] Downloading new file'
dl_checksum = download(filename) dl_checksum = download(filename)
puts " [i] Downloaded File Checksum: #{dl_checksum}" if verbose
unless dl_checksum == db_checksum unless dl_checksum == db_checksum
fail "#{filename}: checksums do not match" fail "#{filename}: checksums do not match"
end end
rescue => e rescue => e
puts ' [i] Restoring Backup due to error' if verbose
restore_backup(filename) restore_backup(filename)
raise e raise e
ensure ensure
delete_backup(filename) if File.exist?(backup_file_path(filename))
puts ' [i] Deleting Backup' if verbose
delete_backup(filename)
end
end end
end end
end end

View File

@@ -43,7 +43,11 @@ def main
wpscan_options.to_h.merge(max_threads: wpscan_options.threads) 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 # Check for updates
if wpscan_options.update if wpscan_options.update