obelisk 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/obelisk_cli +46 -24
- data/erb/extensions.ad.erb +0 -1
- data/erb/sip.ad.erb +0 -1
- data/lib/obelisk.rb +44 -24
- data/lib/obelisk/version.rb +1 -1
- data/test/test_erb.rb +13 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c847ea4d549f8d213b7107d9d7b712222bd0458a
|
4
|
+
data.tar.gz: 0f397ee7d0c430ad7f31837512b7431c7c83c652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41393c14c86b8cc4662f260b021cacc0dfa722a067792a568fb775ad21b86b427c30ad5d7f5946079bef29e8cc4414ccf9a09ac0b56c48889f03eaecae61f046
|
7
|
+
data.tar.gz: adb3540fd474e7a57fde7e3266c8f719e445f90b2bbf38a1abbaf8cbd4d5402e60e49b2ed95eb9bfe3009dfd9cf9c0d40f47c16ae63c85ab2cd3630e2ab692be
|
data/bin/obelisk_cli
CHANGED
@@ -3,31 +3,53 @@
|
|
3
3
|
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
4
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
5
|
|
6
|
-
require
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
ARGV.each do |arg|
|
17
|
-
case arg
|
18
|
-
when "conf"
|
19
|
-
Obelisk.make_erb_conf
|
20
|
-
puts "All files has been generated."
|
21
|
-
when "updb"
|
22
|
-
puts "Not implemented yet"
|
23
|
-
else
|
24
|
-
puts %{Usage: obelisk_cli install
|
25
|
-
obelisk_cli conf [updb]
|
6
|
+
require "optparse"
|
7
|
+
require "securerandom"
|
8
|
+
require "obelisk"
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
VALID_COMMANDS = %w{install generate update}
|
12
|
+
|
13
|
+
op = OptionParser.new do |opts|
|
14
|
+
opts.banner =
|
15
|
+
%Q{Usage: obelisk_cli [options] command
|
26
16
|
Commands:
|
27
|
-
install
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
install Copy or merge configuration file for Obelisk
|
18
|
+
generate Generate config files for Asterisk
|
19
|
+
update Replace config files for Asterisk in case of any change
|
20
|
+
Options:}
|
21
|
+
opts.on("-o", "--outdir [DIR]", "Output directory for generated config files") { |dir| options[:dir] = dir }
|
22
|
+
opts.on("-r", "--restart", "Restart Asterisk in case of config change") { options[:restart] = true }
|
23
|
+
opts.on("-c", "--config [FILE]", "Specify config FILE for Obelisk") { |file| options[:config] = file }
|
24
|
+
opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
|
25
|
+
end
|
26
|
+
|
27
|
+
op.parse!
|
28
|
+
|
29
|
+
ARGV.select! { |arg| VALID_COMMANDS.include? arg }
|
30
|
+
(puts op.help; exit 1) if ARGV.empty?
|
31
|
+
|
32
|
+
Obelisk.load_conf options[:config]
|
33
|
+
$conf[:asterisk_conf_dir] = options[:dir] if options[:dir]
|
34
|
+
|
35
|
+
ARGV.each do |arg|
|
36
|
+
case arg
|
37
|
+
when "install"
|
38
|
+
if Obelisk.save_def_conf options[:config]
|
39
|
+
puts "Found and updated config file. Please, check it."
|
40
|
+
else
|
41
|
+
puts "Default configuration file's been saved. Change it accordingly."
|
42
|
+
end
|
43
|
+
when "generate"
|
44
|
+
Obelisk.make_erb_conf :force => true, :restart => options[:restart]
|
45
|
+
puts "All files has been generated."
|
46
|
+
when "update"
|
47
|
+
if Obelisk.make_erb_conf(:restart => options[:restart])
|
48
|
+
puts "Asterisk config files have been updated"
|
49
|
+
else
|
50
|
+
puts "Already up to date."
|
31
51
|
end
|
52
|
+
else
|
53
|
+
puts op
|
32
54
|
end
|
33
55
|
end
|
data/erb/extensions.ad.erb
CHANGED
data/erb/sip.ad.erb
CHANGED
data/lib/obelisk.rb
CHANGED
@@ -10,42 +10,57 @@ module Obelisk
|
|
10
10
|
DEFAULT_CONFIG_PATH = "#{Dir.home}/.obelisk.conf"
|
11
11
|
DEFAULT_CONFIG = {
|
12
12
|
:ad_settings => {
|
13
|
-
ldap_host:
|
14
|
-
base_dn:
|
15
|
-
bind_name:
|
16
|
-
bind_pass:
|
13
|
+
ldap_host: "localhost",
|
14
|
+
base_dn: "ou=STAFF,dc=CORP,dc=LOCAL",
|
15
|
+
bind_name: "user",
|
16
|
+
bind_pass: "pass",
|
17
17
|
},
|
18
18
|
:mapping => {
|
19
|
-
samaccountname:
|
20
|
-
info:
|
21
|
-
facsimiletelephonenumber:
|
22
|
-
ipphone:
|
23
|
-
pager:
|
19
|
+
samaccountname: :peer,
|
20
|
+
info: :secret,
|
21
|
+
facsimiletelephonenumber: :context,
|
22
|
+
ipphone: :extension,
|
23
|
+
pager: :callgroup,
|
24
24
|
# Used for AdressBook generation
|
25
|
-
displayname:
|
26
|
-
mobile:
|
27
|
-
homephone:
|
28
|
-
company:
|
29
|
-
department:
|
30
|
-
title:
|
25
|
+
displayname: :name,
|
26
|
+
mobile: :mobile,
|
27
|
+
homephone: :home,
|
28
|
+
company: :company,
|
29
|
+
department: :department,
|
30
|
+
title: :title,
|
31
31
|
},
|
32
32
|
:defaults => {
|
33
|
-
facsimiletelephonenumber:
|
33
|
+
facsimiletelephonenumber: "from-internal"
|
34
34
|
},
|
35
|
-
:asterisk_conf_dir =>
|
36
|
-
:
|
35
|
+
:asterisk_conf_dir => "/tmp/asterisk",
|
36
|
+
:asterisk_restart_command => %q{asterisk -x "core restart gracefully"},
|
37
|
+
:erb_file_dir => File.expand_path(File.dirname(__FILE__) + "/../erb")
|
37
38
|
}
|
38
39
|
|
39
40
|
$conf = {}
|
40
41
|
|
41
|
-
def self.make_erb_conf
|
42
|
-
|
42
|
+
def self.make_erb_conf(params = {})
|
43
|
+
params[:conf_dir] ||= $conf[:asterisk_conf_dir]
|
44
|
+
params[:force] ||= false
|
45
|
+
params[:restart] ||= false
|
46
|
+
FileUtils.mkdir_p params[:conf_dir]
|
43
47
|
b = binding
|
48
|
+
up = false
|
44
49
|
users = get_ad_users
|
45
50
|
Dir[File.expand_path "*.erb", $conf[:erb_file_dir]].each do |erb|
|
46
|
-
conf_file = File.expand_path File.basename(erb, ".erb"),
|
47
|
-
File.open(conf_file, "w")
|
51
|
+
conf_file = File.expand_path File.basename(erb, ".erb"), params[:conf_dir]
|
52
|
+
File.open(conf_file, File.exists?(conf_file) ? "r+" : "w+") do |file|
|
53
|
+
content = ERB.new(IO.read(erb), nil, "-").result(b)
|
54
|
+
if content != file.read || params[:force]
|
55
|
+
file.seek 0
|
56
|
+
file.truncate 0
|
57
|
+
file.write content
|
58
|
+
up = true
|
59
|
+
end
|
60
|
+
end
|
48
61
|
end
|
62
|
+
system $conf[:asterisk_restart_command] if up && params[:restart]
|
63
|
+
up
|
49
64
|
end
|
50
65
|
|
51
66
|
def self.get_ad_users(ou = nil)
|
@@ -68,16 +83,21 @@ module Obelisk
|
|
68
83
|
end
|
69
84
|
end
|
70
85
|
|
71
|
-
def self.save_def_conf(file_name =
|
86
|
+
def self.save_def_conf(file_name = nil)
|
87
|
+
file_name ||= DEFAULT_CONFIG_PATH
|
72
88
|
conf = DEFAULT_CONFIG
|
89
|
+
updated = false
|
73
90
|
if File.exists? file_name
|
74
91
|
merge_proc = proc { |k, o, n| o.is_a?(Hash) && n.is_a?(Hash) ? o.merge(n, &merge_proc) : n }
|
75
92
|
conf.merge! YAML.load(IO.read(file_name)), &merge_proc
|
93
|
+
updated = true
|
76
94
|
end
|
77
95
|
File.open(file_name, 'w') { |f| f.write YAML.dump conf }
|
96
|
+
updated
|
78
97
|
end
|
79
98
|
|
80
|
-
def self.load_conf(file_name =
|
99
|
+
def self.load_conf(file_name = nil)
|
100
|
+
file_name ||= DEFAULT_CONFIG_PATH
|
81
101
|
return unless $conf.empty?
|
82
102
|
begin
|
83
103
|
$conf = YAML.load IO.read file_name
|
data/lib/obelisk/version.rb
CHANGED
data/test/test_erb.rb
CHANGED
@@ -4,13 +4,18 @@ require "securerandom"
|
|
4
4
|
|
5
5
|
class ErbTestCase < Test::Unit::TestCase
|
6
6
|
def test_make_erb_conf
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
begin
|
8
|
+
dir = "/tmp/#{SecureRandom.hex}"
|
9
|
+
assert Obelisk.make_erb_conf :conf_dir => dir
|
10
|
+
assert Dir.exists? dir
|
11
|
+
assert_equal Dir[File.expand_path "*.erb", $conf[:erb_file_dir]].count, Dir[File.expand_path "*", dir].count
|
12
|
+
assert ! Obelisk.make_erb_conf(:conf_dir => dir)
|
13
|
+
assert Obelisk.make_erb_conf :conf_dir => dir, :force => true
|
14
|
+
assert ! Obelisk.make_erb_conf(:conf_dir => dir)
|
15
|
+
#puts %x(cat #{dir}/*)
|
16
|
+
ensure
|
17
|
+
File.delete *Dir[File.expand_path "*", dir]
|
18
|
+
Dir.rmdir dir
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obelisk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goredar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|