kandalf-cdmon_updater 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +15 -2
- data/cdmon_updater.gemspec +10 -2
- data/config/cdmon.yml +8 -0
- data/lib/cdmon.rb +16 -3
- data/lib/config.rb +14 -0
- data/lib/mailer.rb +93 -0
- data/spec/ip_updater_spec.rb +15 -0
- data/spec/mailer_spec.rb +40 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -3
data/README
CHANGED
@@ -22,17 +22,30 @@ general:
|
|
22
22
|
email: root@server
|
23
23
|
log_level: DEBUG
|
24
24
|
service_url: https://dinamico.cdmon.org/onlineService.php
|
25
|
+
send_mail_on_error: no
|
25
26
|
|
26
27
|
users:
|
27
28
|
cdmon_user:
|
28
|
-
hosts:
|
29
|
+
hosts: kandalf.com.ar blog.kandalf.com.ar
|
29
30
|
md5pass: 1278323gfb37875f2749ju6cabd8io89
|
30
31
|
|
32
|
+
mailer:
|
33
|
+
address: relay.someserver.com.ar
|
34
|
+
port: 25
|
35
|
+
domain: kandalf.com.ar
|
36
|
+
user_name: someuser #without @domain
|
37
|
+
password: plain_password
|
38
|
+
|
31
39
|
You should customize the users section with your personal data. The cdmon_user should be replaced with the user you have associated in your CDMon control panel with your domains.
|
32
40
|
As you can have multiple users in CDMon, you can add as many user sections as you need here.
|
33
41
|
The md5pass should be the user's password crypted as an MD5 hash, CDMon provides a website to do this ( https://www.cdmon.com/webapps/encriptar.php ) but you can use the method you like as long as it results on the MD5 hash for your passowrd.
|
34
42
|
|
35
|
-
|
43
|
+
For mail notification you must activate the the send_mail_on_error feature on the general section and properly config your mail server.
|
44
|
+
Also, you have to define a valid email address for the email feature on the general section.
|
45
|
+
|
46
|
+
When these things are set up, an email will be sent to the email address defined on the general section with the message of the error and the time it was raised and the subject of "CDMon Updater ERROR".
|
47
|
+
|
48
|
+
From the general section you should customize the log_level and the email (which is not yet supported but it will be soon).
|
36
49
|
|
37
50
|
After you have your settings, you can run the client manually or you can add the following line to your crontab
|
38
51
|
|
data/cdmon_updater.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cdmon_updater}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Leonardo Mateo"]
|
@@ -27,7 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"config/schedule.rb",
|
28
28
|
"lib/cdmon.rb",
|
29
29
|
"lib/config.rb",
|
30
|
-
"lib/ip_updater.rb"
|
30
|
+
"lib/ip_updater.rb",
|
31
|
+
"lib/mailer.rb",
|
32
|
+
"spec/mailer_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
31
34
|
]
|
32
35
|
s.homepage = %q{http://github.com/kandalf/cdmon_updater}
|
33
36
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -35,6 +38,11 @@ Gem::Specification.new do |s|
|
|
35
38
|
s.rubyforge_project = %q{cdmon_updater}
|
36
39
|
s.rubygems_version = %q{1.3.5}
|
37
40
|
s.summary = %q{A client updater for CDMon dynamic DNS.}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/ip_updater_spec.rb",
|
43
|
+
"spec/spec_helper.rb",
|
44
|
+
"spec/mailer_spec.rb"
|
45
|
+
]
|
38
46
|
|
39
47
|
if s.respond_to? :specification_version then
|
40
48
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/config/cdmon.yml
CHANGED
@@ -3,9 +3,17 @@ general:
|
|
3
3
|
email: root@server
|
4
4
|
log_level: DEBUG
|
5
5
|
service_url: https://dinamico.cdmon.org/onlineService.php
|
6
|
+
send_mail_on_error: no
|
6
7
|
|
7
8
|
users:
|
8
9
|
cdmon_user:
|
9
10
|
hosts: kandalf.com.ar blog.kandalf.com.ar
|
10
11
|
md5pass: 1278323gfb37875f2749ju6cabd8io89
|
11
12
|
|
13
|
+
mailer:
|
14
|
+
address: relay.someserver.com.ar
|
15
|
+
port: 25
|
16
|
+
domain: kandalf.com.ar
|
17
|
+
user_name: someuser #without @domain
|
18
|
+
password: plain_password
|
19
|
+
|
data/lib/cdmon.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'config'
|
3
|
+
require 'mailer'
|
2
4
|
|
3
5
|
module CDMon
|
4
6
|
VERSION = "0.1.0"
|
@@ -8,12 +10,12 @@ module CDMon
|
|
8
10
|
@@logger = Logger.new("/var/log/cdmon.log", 10, 1024000)
|
9
11
|
rescue Errno::EACCES
|
10
12
|
@@logger = Logger.new("#{ENV["HOME"]}/.cdmon.log")
|
11
|
-
|
13
|
+
end
|
12
14
|
@@logger
|
13
|
-
end
|
15
|
+
end
|
14
16
|
|
15
17
|
def self.log_level=(level)
|
16
|
-
case
|
18
|
+
case level
|
17
19
|
when "WARN"
|
18
20
|
logger.level = Logger::WARN
|
19
21
|
when "INFO"
|
@@ -32,5 +34,16 @@ module CDMon
|
|
32
34
|
logger.debug(message)
|
33
35
|
logger.warn(message)
|
34
36
|
logger.error(message)
|
37
|
+
self.send_error_mail(message) if Config.mail_on_error?
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def self.send_error_mail(message)
|
42
|
+
mailer = Mailer.new({"server" => Config.mailer})
|
43
|
+
mailer.from = "cdmon_updater@#{Mailer.domain}"
|
44
|
+
mailer.to = Config.mail_to
|
45
|
+
mailer.subject = "CDMon Updater ERROR"
|
46
|
+
mailer.message = message
|
47
|
+
self.log_all("Cannot send mail") unless mailer.send_mail
|
35
48
|
end
|
36
49
|
end
|
data/lib/config.rb
CHANGED
@@ -11,6 +11,8 @@ module Config
|
|
11
11
|
CDMON_BAD_IP = "badip"
|
12
12
|
CDMON_ERROR_LOGIN = "errorlogin"
|
13
13
|
|
14
|
+
@@config = {}
|
15
|
+
|
14
16
|
def self.load(config_file)
|
15
17
|
@@config = YAML::load_file(config_file)
|
16
18
|
end
|
@@ -23,6 +25,14 @@ module Config
|
|
23
25
|
@@config["users"]
|
24
26
|
end
|
25
27
|
|
28
|
+
def self.mailer
|
29
|
+
@@config["mailer"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.mail_to
|
33
|
+
@@config["general"]["email"] if @@config
|
34
|
+
end
|
35
|
+
|
26
36
|
def self.md5_password_for(user)
|
27
37
|
@@config["users"][user.to_s]["md5pass"] if @@config
|
28
38
|
end
|
@@ -35,6 +45,10 @@ module Config
|
|
35
45
|
@@config["general"]["dns"] if @@config
|
36
46
|
end
|
37
47
|
|
48
|
+
def self.mail_on_error?
|
49
|
+
@@config["general"]["send_mail_on_error"]
|
50
|
+
end
|
51
|
+
|
38
52
|
def self.hosts
|
39
53
|
HOSTS
|
40
54
|
end
|
data/lib/mailer.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'net/smtp'
|
2
|
+
require 'cdmon'
|
3
|
+
|
4
|
+
module CDMon
|
5
|
+
class Mailer < Net::SMTP
|
6
|
+
attr_accessor :subject, :message, :from, :to
|
7
|
+
|
8
|
+
if Config.mailer
|
9
|
+
@@address = Config.mailer["address"]
|
10
|
+
@@port = Config.mailer["port"]
|
11
|
+
@@domain = Config.mailer["domain"]
|
12
|
+
@@credentials[:user_name] = Config.mailer["user_name"]
|
13
|
+
@@credentials[:password] = Config.mailer["password"]
|
14
|
+
else
|
15
|
+
@@address = nil
|
16
|
+
@@port = nil
|
17
|
+
@@credentials = {:user_name => nil, :password => nil}
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(options = {})
|
21
|
+
if options.has_key?("server") && options["server"].is_a?(Hash) && options["server"].keys.any?
|
22
|
+
server_options = options.delete("server")
|
23
|
+
|
24
|
+
@@address = server_options["address"]
|
25
|
+
@@port = server_options["port"]
|
26
|
+
@@domain = server_options["domain"]
|
27
|
+
@@credentials[:user_name] = server_options["user_name"]
|
28
|
+
@@credentials[:password] = server_options["password"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#class methods
|
33
|
+
def self.address
|
34
|
+
@@address
|
35
|
+
end
|
36
|
+
def self.address=(address)
|
37
|
+
@@address = address
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.port
|
41
|
+
@@port
|
42
|
+
end
|
43
|
+
def self.port=(port)
|
44
|
+
@@port = port
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.domain
|
48
|
+
@@domain
|
49
|
+
end
|
50
|
+
def self.domain=(domain)
|
51
|
+
@@domain = domain
|
52
|
+
end
|
53
|
+
def self.credentials
|
54
|
+
@@credentials
|
55
|
+
end
|
56
|
+
def self.credentials=(data = {:user_name => nil, :password => nil})
|
57
|
+
@@credentials = data
|
58
|
+
end
|
59
|
+
|
60
|
+
#instance methods
|
61
|
+
def send_mail
|
62
|
+
body = mail_headers
|
63
|
+
body << "#{Time.now.to_s} - #{@message}"
|
64
|
+
|
65
|
+
begin
|
66
|
+
@to.split(",").each do | to |
|
67
|
+
|
68
|
+
Net::SMTP.start(@@address, @@port, @from, @@credentials[:user_name], @@credentials[:password], :login) do |smtp|
|
69
|
+
|
70
|
+
smtp.send_message(body, @from, to.strip)
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
true
|
75
|
+
rescue
|
76
|
+
CDMon.log_all("Cannot send email")
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def mail_headers
|
83
|
+
body = "From: #{@from} <#{@from}>\n"
|
84
|
+
body << "To: #{@to}<#{@to}>\n"
|
85
|
+
body << "Subject: #{@subject}\n"
|
86
|
+
body << "Date: #{Time.now}\n"
|
87
|
+
body << "Importance:high\n"
|
88
|
+
body << "MIME-Version:1.0\n"
|
89
|
+
body << "\n\n\n"
|
90
|
+
body
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ip_updater'
|
3
|
+
|
4
|
+
describe CDMon::IPUpdater do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@updater = CDMon::IPUpdater.new("/etc/cdmon.yml")
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should update the IP" do
|
12
|
+
"you should have your settings on /etc/cdmon.yml".should_not be_nil
|
13
|
+
#@updater.update
|
14
|
+
end
|
15
|
+
end
|
data/spec/mailer_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mailer'
|
3
|
+
|
4
|
+
describe CDMon::Mailer do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
server_options = {"server" => {"address" => "some.smtp.server", "port" => 25, "user_name" => "user", "password" => "smtp_password"}}
|
8
|
+
|
9
|
+
@mailer = CDMon::Mailer.new(server_options)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have class options set" do
|
13
|
+
CDMon::Mailer.address.should == "some.smtp.server"
|
14
|
+
CDMon::Mailer.port.should == 25
|
15
|
+
CDMon::Mailer.credentials[:user_name].should == "user"
|
16
|
+
CDMon::Mailer.credentials[:password].should == "smtp_password"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have instance attributes" do
|
20
|
+
@mailer.subject = "Test Mail"
|
21
|
+
@mailer.message = "This is the body of the message"
|
22
|
+
@mailer.from = "someuser@someserver.com"
|
23
|
+
@mailer.to = "someotheruser@someserver.com"
|
24
|
+
@mailer.stub!(:send_mail).and_return(true)
|
25
|
+
@mailer.send_mail.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should send mail" do
|
29
|
+
"This is a stub left in blank since I can't publish my smtp access data".should_not be_nil
|
30
|
+
"You should fill your own data on ../config/cdmon.yml".should_not be_nil
|
31
|
+
#Config.load("../config/cdmon.yml")
|
32
|
+
|
33
|
+
#@mailer = CDMon::Mailer.new({"server" => Config.mailer})
|
34
|
+
#@mailer.subject = "Test Mail"
|
35
|
+
#@mailer.message = "This is the body of the message"
|
36
|
+
#@mailer.from = "cdmon_updater@kandalf.com.ar"
|
37
|
+
#@mailer.to = "some_real_address@some_server.com"
|
38
|
+
#@mailer.send_mail.should be_true
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$: << "../lib" << "lib"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kandalf-cdmon_updater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonardo Mateo
|
@@ -32,6 +32,9 @@ files:
|
|
32
32
|
- lib/cdmon.rb
|
33
33
|
- lib/config.rb
|
34
34
|
- lib/ip_updater.rb
|
35
|
+
- lib/mailer.rb
|
36
|
+
- spec/mailer_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
35
38
|
has_rdoc: false
|
36
39
|
homepage: http://github.com/kandalf/cdmon_updater
|
37
40
|
licenses:
|
@@ -59,5 +62,7 @@ rubygems_version: 1.3.5
|
|
59
62
|
signing_key:
|
60
63
|
specification_version: 3
|
61
64
|
summary: A client updater for CDMon dynamic DNS.
|
62
|
-
test_files:
|
63
|
-
|
65
|
+
test_files:
|
66
|
+
- spec/ip_updater_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/mailer_spec.rb
|