Adds DB update system
This commit is contained in:
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
@@ -28,11 +28,11 @@ class DbUpdater < Updater
|
|||||||
|
|
||||||
# @return [ String ] The checksum of the associated remote filename
|
# @return [ String ] The checksum of the associated remote filename
|
||||||
def remote_file_checksum(filename)
|
def remote_file_checksum(filename)
|
||||||
url = "#{remote_file_url(filename)}.sha2"
|
url = "#{remote_file_url(filename)}.sha512"
|
||||||
|
|
||||||
res = Browser.get(url, request_params)
|
res = Browser.get(url, request_params)
|
||||||
fail "Unable to get #{url}" unless res && res.code == 200
|
fail "Unable to get #{url}" unless res && res.code == 200
|
||||||
res.body.chomp
|
res.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_file_path(filename)
|
def local_file_path(filename)
|
||||||
@@ -49,6 +49,7 @@ class DbUpdater < Updater
|
|||||||
end
|
end
|
||||||
|
|
||||||
def restore_backup(filename)
|
def restore_backup(filename)
|
||||||
|
return unless File.exist?(backup_file_path(filename))
|
||||||
FileUtils.cp(backup_file_path(filename), local_file_path(filename))
|
FileUtils.cp(backup_file_path(filename), local_file_path(filename))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ class DbUpdater < Updater
|
|||||||
fail "Error while downloading #{file_url}" unless res && res.code == 200
|
fail "Error while downloading #{file_url}" unless res && res.code == 200
|
||||||
File.write(file_path, res.body.chomp)
|
File.write(file_path, res.body.chomp)
|
||||||
|
|
||||||
Digest::MD5.file(file_path).hexdigest
|
Digest::SHA512.file(file_path).hexdigest
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -73,13 +74,11 @@ class DbUpdater < Updater
|
|||||||
begin
|
begin
|
||||||
create_backup(filename)
|
create_backup(filename)
|
||||||
checksum = download(filename)
|
checksum = download(filename)
|
||||||
# p checksum
|
|
||||||
|
|
||||||
# unless checksum == remote_file_checksum(filename)
|
unless checksum == remote_file_checksum(filename)
|
||||||
# fail "#{filename}: checksums do not match"
|
fail "#{filename}: checksums do not match"
|
||||||
# end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
# p e
|
|
||||||
restore_backup(filename)
|
restore_backup(filename)
|
||||||
raise e
|
raise e
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -39,12 +39,10 @@ def main
|
|||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
if wpscan_options.update
|
if wpscan_options.update
|
||||||
puts 'Updating the DB ..'
|
puts 'Updating the DB ...'
|
||||||
DbUpdater.new(DATA_DIR).update
|
DbUpdater.new(DATA_DIR).update
|
||||||
puts 'Done.'
|
puts 'Done.'
|
||||||
|
|
||||||
exit # remove me
|
|
||||||
|
|
||||||
if !@updater.nil?
|
if !@updater.nil?
|
||||||
if @updater.has_local_changes?
|
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] "
|
print "#{red('[!]')} Local file changes detected, an update will override local changes, do you want to continue updating? [y/n] "
|
||||||
|
|||||||
Reference in New Issue
Block a user