Skip to content

Commit

Permalink
Merge pull request rapid7#298 from rapid7/restore_backup_with_password
Browse files Browse the repository at this point in the history
adding the ability to include a password when restoring a backup
  • Loading branch information
sgreen-r7 authored Sep 26, 2017
2 parents 100a74b + c6650a4 commit 977225e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/nexpose/maint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ def initialize(name, date, description, version, independent, size)
# It will restart the console after acknowledging receiving the request.
#
# @param [Connection] nsc An active connection to a Nexpose console.
# @param [String] (Optional) The password to use when restoring the backup.
# @return [Boolean] Whether the request was received.
#
def restore(nsc)
def restore(nsc, password = nil)
raise 'Supplied Password is incorrect for restoring this Backup.' if invalid_backup_password?(nsc, password)
parameters = { 'backupid' => @name,
'cmd' => 'restore',
'targetTask' => 'backupRestore' }
'targetTask' => 'backupRestore',
'password' => password }
xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
nsc._maintenance_restart
Expand Down Expand Up @@ -129,5 +132,23 @@ def self.parse(hash)
hash['Platform-Independent'],
hash['Size'])
end

private

def invalid_backup_password?(nsc, password)
!correct_backup_password?(nsc, password) if backup_need_password?(nsc)
end

def backup_need_password?(nsc)
resp = Nexpose::AJAX.get(nsc, '/data/admin/backups/password', Nexpose::AJAX::CONTENT_TYPE::JSON, 'backupID' => name)
resp == 'true'
end

def correct_backup_password?(nsc, password)
raise 'This Backup file requires a Password. Please include a password during the restore command.' if password.nil?
resp = Nexpose::AJAX.post(nsc, "/data/admin/backups/password?backupID=#{name}&password=#{password}", nil, Nexpose::AJAX::CONTENT_TYPE::JSON)
resp == 'true'
end

end
end

0 comments on commit 977225e

Please sign in to comment.