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_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.
-
.retrieve_products(product_list, title) ⇒ String
private
private method to retrieve the products 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)
99 100 101 102 103 104 105 106 107 |
# File 'lib/cert_bot/mail_agent.rb', line 99 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
48 49 50 51 52 53 |
# File 'lib/cert_bot/mail_agent.rb', line 48 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_cves(wid) ⇒ String (private)
private method to retrieve the cves and create an output string for the mail
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cert_bot/mail_agent.rb', line 58 private_class_method def self.retrieve_cves(wid) cve_list = CertBot::AdvisoryParser.retrieve_cves(wid) cves = "CVEs:" counter = 0 cve_list.each { |cve_id| if (!cve_id.nil?) cves.concat(" ").concat(cve_id) counter += 1 end # 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
94 95 96 97 |
# File 'lib/cert_bot/mail_agent.rb', line 94 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 |
.retrieve_products(product_list, title) ⇒ String (private)
private method to retrieve the products and create an output string for the mail
82 83 84 85 86 87 88 89 |
# File 'lib/cert_bot/mail_agent.rb', line 82 private_class_method def self.retrieve_products(product_list, title) affected_products = "#{title}:\n" product_list.each { |product| 6.times { affected_products.concat(" ") } affected_products.concat(product["name"]).concat("\n") } affected_products 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 41 42 43 |
# 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_products(CertBot::AdvisoryParser.retrieve_affected_products(wid), "Affected versions")}") .concat("#{retrieve_products(CertBot::AdvisoryParser.retrieve_fixed_products(wid), "Fixed versions")}") .concat("WID: #{wid}\n\n") .concat("Best wishes,\n") .concat("Your CERT Bot.") call_smtp(, config) end |