-
Notifications
You must be signed in to change notification settings - Fork 5
/
domain_checker.rb
69 lines (57 loc) · 1.75 KB
/
domain_checker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'dotenv'
Dotenv.load
require 'mail'
require 'subexec'
def run_domain_check
# only continue if there are domains to check
if !ENV['DOMAINS'].nil? && ENV['DOMAINS'].length > 0
# put the domains into an array
domains = ENV['DOMAINS'].split(',').map{|x| x.strip}
outputs = []
# run the whois command for each domain
domains.each do |domain|
result = Subexec.run "whois #{domain} | grep 'Domain Status'"
outputs << [domain, result.output]
end
# write the body in the format of domain / output message
body = ''
outputs.each do |output|
body << output[0].gsub("\n", "<br />")
body << "<br />"
body << output[1].gsub("\n", "<br />")
body << "<br />"
body << "-------------------------------------------------------"
body << "<br /><br />"
end
# set the mail settings
if ENV['ENVIRONMENT'] == 'production'
Mail.defaults do
delivery_method :smtp,
address: ENV['FEEDBACK_SMTP_ADDRESS'],
port: '587',
user_name: ENV['FEEDBACK_SMTP_AUTH_USER'],
password: ENV['FEEDBACK_SMTP_AUTH_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true
end
else
Mail.defaults do
delivery_method :smtp,
address: 'localhost',
port: 1025
end
end
mail = Mail.new do
from ENV['FEEDBACK_FROM_EMAIL']
to ENV['FEEDBACK_TO_EMAIL']
subject ENV['EMAIL_SUBJECT']
html_part do
content_type 'text/html; charset=UTF-8'
body body
end
end
# mail[:body] = body
# send the email
mail.deliver!
end
end