Class: Nexpose::Email

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

Overview

Configuration structure for e-mail notification.

The send_as and send_to_acl_as attributes are optional, but one of them is required for sending reports via e-mail. The send_as attribute is required for sending e-mails to users who are not on the report access list. The send_to_acl attribute is required for sending e-mails to report access list members.

E-mails and attachments are sent via the Internet in clear text and are not encrypted. If you do not set a valid value for either attribute, the application will save the report but not send it via e-mail. If you set a valid value for the send_as attribute but not for the send_to_acl_as attribute, the application will send the report via e-mail to non-access-list members only. If you set a valid value for the send_to_acl_as attribute, the application will send the report via e-mail to access-list members only. If you set a valid value for both attributes, the application will send reports via e-mail to access-list members and non-members.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(to_all_authorized, send_to_owner_as, send_to_acl_as, send_as) ⇒ Email

Returns a new instance of Email.



50
51
52
53
54
55
56
57
# File 'lib/nexpose/common.rb', line 50

def initialize(to_all_authorized, send_to_owner_as, send_to_acl_as, send_as)
  @to_all_authorized = to_all_authorized
  @send_to_owner_as = send_to_owner_as
  @send_to_acl_as = send_to_acl_as
  @send_as = send_as

  @recipients = []
end

Instance Attribute Details

#recipientsObject

Recipients will be in form of email address.

Array<String>

E-mail addresses of additional report recipients (i.e., not already on the report access list).



48
49
50
# File 'lib/nexpose/common.rb', line 48

def recipients
  @recipients
end

#send_asObject

Send as file attachment or zipped file to individuals who are not members of the report access list.

String

Attachment format, ‘file’ | ‘zip’.



30
31
32
# File 'lib/nexpose/common.rb', line 30

def send_as
  @send_as
end

#send_to_acl_asObject

Send to users on the report access list.

String

Attachment format ‘file’ | ‘zip’



36
37
38
# File 'lib/nexpose/common.rb', line 36

def send_to_acl_as
  @send_to_acl_as
end

#send_to_owner_asObject

Format to send to users on the report access list.

String

Attachment format ‘file’ | ‘zip’ | ‘url’



39
40
41
# File 'lib/nexpose/common.rb', line 39

def send_to_owner_as
  @send_to_owner_as
end

#senderObject

Sender that e-mail will be attributed to.

String

an email address



42
43
44
# File 'lib/nexpose/common.rb', line 42

def sender
  @sender
end

#smtp_relay_serverObject

SMTP relay server.

String

the IP address, host name or FQDN of the SMTP server.



45
46
47
# File 'lib/nexpose/common.rb', line 45

def smtp_relay_server
  @smtp_relay_server
end

#to_all_authorizedObject

Send to all the authorized users of sites, groups, and assets.

Fixnum

1 | 0



33
34
35
# File 'lib/nexpose/common.rb', line 33

def to_all_authorized
  @to_all_authorized
end

Class Method Details

.parse(xml) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nexpose/common.rb', line 78

def self.parse(xml)
  xml.elements.each('//Email') do |email|
    config = Email.new(email.attributes['toAllAuthorized'] == '1',
                       email.attributes['sendToOwnerAs'],
                       email.attributes['sendToAclAs'],
                       email.attributes['sendAs'])

    xml.elements.each('//Sender') do |sender|
      config.sender = sender.text
    end
    xml.elements.each('//SmtpRelayServer') do |server|
      config.smtp_relay_server = server.text
    end
    xml.elements.each('//Recipient') do |recipient|
      config.recipients << recipient.text
    end
    return config
  end
  nil
end

Instance Method Details

#to_xmlObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nexpose/common.rb', line 59

def to_xml
  xml = '<Email'
  xml << %( toAllAuthorized='#{@to_all_authorized ? 1 : 0}')
  xml << %( sendToOwnerAs='#{@send_to_owner_as}') if @send_to_owner_as
  xml << %( sendToAclAs='#{@send_to_acl_as}') if @send_to_acl_as
  xml << %( sendAs='#{@send_as}') if @send_as
  xml << '>'
  xml << %(<Sender>#{@sender}</Sender>) if @sender
  xml << %(<SmtpRelayServer>#{@smtp_relay_server}</SmtpRelayServer>) if @smtp_relay_server
  if @recipients
    xml << '<Recipients>'
    @recipients.each do |recipient|
      xml << %(<Recipient>#{recipient}</Recipient>)
    end
    xml << '</Recipients>'
  end
  xml << '</Email>'
end