Class: Nexpose::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/maint.rb

Overview

Details about an existing backup on the security console.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, date, description, version, independent, size) ⇒ Backup

Returns a new instance of Backup.



86
87
88
89
90
91
92
93
# File 'lib/nexpose/maint.rb', line 86

def initialize(name, date, description, version, independent, size)
  @name                 = name
  @date                 = date
  @description          = description
  @version              = version
  @platform_independent = independent
  @size                 = size
end

Instance Attribute Details

#dateObject (readonly)

Date the backup was made.



75
76
77
# File 'lib/nexpose/maint.rb', line 75

def date
  @date
end

#descriptionObject (readonly)

Description of the backup.



77
78
79
# File 'lib/nexpose/maint.rb', line 77

def description
  @description
end

#nameObject (readonly)

Filename



73
74
75
# File 'lib/nexpose/maint.rb', line 73

def name
  @name
end

#platform_independentObject (readonly)

Whether the backup is platform-idependent or not.



81
82
83
# File 'lib/nexpose/maint.rb', line 81

def platform_independent
  @platform_independent
end

#sizeObject (readonly)

Size of backup file on disk, in Bytes. Can be used to estimate the amount of time the backup may take to load.



84
85
86
# File 'lib/nexpose/maint.rb', line 84

def size
  @size
end

#versionObject (readonly)

Nexpose version the console was on when the backup was made.



79
80
81
# File 'lib/nexpose/maint.rb', line 79

def version
  @version
end

Class Method Details

.parse(hash) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/nexpose/maint.rb', line 127

def self.parse(hash)
  new(hash['Download'],
      Time.at(hash['Date'].to_i / 1000),
      hash['Description'],
      hash['Version'],
      hash['Platform-Independent'],
      hash['Size'])
end

Instance Method Details

#delete(nsc) ⇒ Boolean

Remove this backup file from the security console.

Parameters:

  • nsc (Connection)

    An active connection to a Nexpose console.

Returns:

  • (Boolean)

    If the backup was removed.



119
120
121
122
123
124
125
# File 'lib/nexpose/maint.rb', line 119

def delete(nsc)
  parameters = { 'backupid' => @name,
                 'cmd' => 'deleteBackup',
                 'targetTask' => 'backupRestore' }
  xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
  !!(xml =~ /succeded="true"/)
end

#restore(nsc, password = nil) ⇒ Boolean

Restore this backup to the Nexpose console. It will restart the console after acknowledging receiving the request.

Parameters:

  • nsc (Connection)

    An active connection to a Nexpose console.

  • (Optional) (String)

    The password to use when restoring the backup.

Returns:

  • (Boolean)

    Whether the request was received.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/nexpose/maint.rb', line 102

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',
                 'password' => password }
  xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
  if !!(xml =~ /succeded="true"/)
    nsc._maintenance_restart
  end
end