Adds DB update system

This commit is contained in:
erwanlr
2014-09-10 16:31:04 +02:00
parent d1a7a0ee1f
commit f2d205e576
5 changed files with 11 additions and 14 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -28,11 +28,11 @@ class DbUpdater < Updater
# @return [ String ] The checksum of the associated remote filename
def remote_file_checksum(filename)
url = "#{remote_file_url(filename)}.sha2"
url = "#{remote_file_url(filename)}.sha512"
res = Browser.get(url, request_params)
fail "Unable to get #{url}" unless res && res.code == 200
res.body.chomp
res.body
end
def local_file_path(filename)
@@ -49,6 +49,7 @@ class DbUpdater < Updater
end
def restore_backup(filename)
return unless File.exist?(backup_file_path(filename))
FileUtils.cp(backup_file_path(filename), local_file_path(filename))
end
@@ -65,7 +66,7 @@ class DbUpdater < Updater
fail "Error while downloading #{file_url}" unless res && res.code == 200
File.write(file_path, res.body.chomp)
Digest::MD5.file(file_path).hexdigest
Digest::SHA512.file(file_path).hexdigest
end
def update
@@ -73,13 +74,11 @@ class DbUpdater < Updater
begin
create_backup(filename)
checksum = download(filename)
# p checksum
# unless checksum == remote_file_checksum(filename)
# fail "#{filename}: checksums do not match"
# end
unless checksum == remote_file_checksum(filename)
fail "#{filename}: checksums do not match"
end
rescue => e
# p e
restore_backup(filename)
raise e
ensure

View File

@@ -39,12 +39,10 @@ def main
# Check for updates
if wpscan_options.update
puts 'Updating the DB ..'
puts 'Updating the DB ...'
DbUpdater.new(DATA_DIR).update
puts 'Done.'
exit # remove me
if !@updater.nil?
if @updater.has_local_changes?
print "#{red('[!]')} Local file changes detected, an update will override local changes, do you want to continue updating? [y/n] "