Module: CertBot::MailAgent
- Defined in:
- lib/cert_bot/mail_agent.rb
Overview
Module to handle the mail creation and propagation of the message for a given rss item
Class Method Summary collapse
- .call_smtp(message, config) ⇒ Object private
-
.create_introduction_string(update_status) ⇒ String
private
private method to create the mail introduction based on the update state of the advisory.
-
.retrieve_affected_products(wid) ⇒ String
private
private method to retrieve the affected products and create an output string for the mail.
-
.retrieve_cves(wid) ⇒ String
private
private method to retrieve the cves and create an output string for the mail.
-
.retrieve_cvss_score(wid) ⇒ String
private
private method to retrieve the cvss score and create an output string for the mail.
-
.send_mail(item, config_file) ⇒ String
method to generate a mail for a given item of the rss feed.
Class Method Details
.call_smtp(message, config) ⇒ Object (private)
96 97 98 99 100 101 102 103 104 |
# File 'lib/cert_bot/mail_agent.rb', line 96 private_class_method def self.call_smtp(, config) Net::SMTP.start(config.config_hash["address"], config.config_hash["port"], helo: config.config_hash["helo"], user: config.config_hash["user"], secret: config.config_hash["password"], authtype: config.config_hash["authtype"], tls_verify: config.config_hash["tls_verify"], tls_hostname: config.config_hash["tls_hostname"]) do |smtp| smtp.(, config.config_hash["from"], config.config_hash["to"]) end nil end |
.create_introduction_string(update_status) ⇒ String (private)
private method to create the mail introduction based on the update state of the advisory
45 46 47 48 49 50 |
# File 'lib/cert_bot/mail_agent.rb', line 45 private_class_method def self.create_introduction_string(update_status) if (CertBot::Data::UpdateStatus.get_mapping_for(update_status) == :new) return "Our CERT RSS Feed received a new security advisory:\n\n" end "Our CERT RSS Feed received an updated security advisory:\n\n" end |
.retrieve_affected_products(wid) ⇒ String (private)
private method to retrieve the affected products and create an output string for the mail
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cert_bot/mail_agent.rb', line 77 private_class_method def self.retrieve_affected_products(wid) product_list = CertBot::AdvisoryParser.retrieve_affected_products(wid) affected_products = "Affected versions:\n" product_list.each { |product| 6.times { affected_products.concat(" ") } affected_products.concat(product["name"]).concat("\n") } affected_products end |
.retrieve_cves(wid) ⇒ String (private)
private method to retrieve the cves and create an output string for the mail
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cert_bot/mail_agent.rb', line 55 private_class_method def self.retrieve_cves(wid) cve_list = CertBot::AdvisoryParser.retrieve_cves(wid) cves = "CVEs:" counter = 0 cve_list.each { |cve_id| cves.concat(" ").concat(cve_id) counter += 1 # write only 5 cve per line then make linebreak if (counter == 5) cves.concat("\n") 5.times { cves.concat(" ") } counter = 0 end } cves end |
.retrieve_cvss_score(wid) ⇒ String (private)
private method to retrieve the cvss score and create an output string for the mail
91 92 93 94 |
# File 'lib/cert_bot/mail_agent.rb', line 91 private_class_method def self.retrieve_cvss_score(wid) cvss_score = CertBot::AdvisoryParser.retrieve_cvss_score(wid) "CVSS Score (#{cvss_score["version"]}): #{cvss_score["temporalscore"]/10.0}\n" end |
.send_mail(item, config_file) ⇒ String
method to generate a mail for a given item of the rss feed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cert_bot/mail_agent.rb', line 15 def self.send_mail(item, config_file) wid = item.link.split("=")[1] = item.pubDate.localtime config = CertBot::Configuration.new(Pathname.new(config_file)) update_status = CertBot::AdvisoryParser.retrieve_update_status(wid) = "From: CERT RSS <#{config.config_hash["from"]}>\n" .concat("To: #{config.config_hash["to"]}\n") .concat("Subject: CERT Report (#{wid}) - #{item.title.split(":")[0]}\n\n") .concat(create_introduction_string(update_status)) .concat("Title: #{item.title}\n") .concat("Description: #{item.description}\n") .concat("Link: #{item.link}\n") .concat("Date: #{}\n") .concat("Status: #{update_status}\n") .concat("Severity: #{item.category.content}\n") .concat(retrieve_cvss_score(wid)) .concat("#{retrieve_cves(wid)}") .concat("\n#{retrieve_affected_products(wid)}") .concat("WID: #{wid}\n\n") .concat("Best wishes,\n") .concat("Your CERT Bot.") call_smtp(, config) end |