obelisk 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c847ea4d549f8d213b7107d9d7b712222bd0458a
4
- data.tar.gz: 0f397ee7d0c430ad7f31837512b7431c7c83c652
3
+ metadata.gz: 18e420a4fdaa33cb7ae3a0178d90260005be6071
4
+ data.tar.gz: 6a8bcb0b9c5a5bea95f983f5465616ecf662038d
5
5
  SHA512:
6
- metadata.gz: 41393c14c86b8cc4662f260b021cacc0dfa722a067792a568fb775ad21b86b427c30ad5d7f5946079bef29e8cc4414ccf9a09ac0b56c48889f03eaecae61f046
7
- data.tar.gz: adb3540fd474e7a57fde7e3266c8f719e445f90b2bbf38a1abbaf8cbd4d5402e60e49b2ed95eb9bfe3009dfd9cf9c0d40f47c16ae63c85ab2cd3630e2ab692be
6
+ metadata.gz: afa63bdd1d323ebb87491a61d3ca046c092365e318b1be6c4fb483714a084605389d9cee98f7458d017947e0fa33db1143f4e9bd73c36c5733d0b6a3a28731c9
7
+ data.tar.gz: 7634d667b0a77d38bdd7476646647b6101647794facb8ca48a09360254b74691241a1c39b0593c684fd6deac3e5f3746df46b4fc546004bb2164a24f243044e7
data/bin/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
data/bin/obelisk_cli CHANGED
@@ -1,55 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'obelisk_cli' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
2
8
 
3
- lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
- $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
5
12
 
6
- require "optparse"
7
- require "securerandom"
8
- require "obelisk"
13
+ require 'rubygems'
14
+ require 'bundler/setup'
9
15
 
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
16
- Commands:
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."
51
- end
52
- else
53
- puts op
54
- end
55
- end
16
+ load Gem.bin_path('obelisk', 'obelisk_cli')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
@@ -7,9 +7,9 @@
7
7
  [<%= current_context %>-ad-users]
8
8
 
9
9
  <% end -%>
10
- exten => <%= user[:extension] %>,1,Dial(SIP/<%= user[:peer] %>)
11
- exten => <%= user[:extension] %>,hint,SIP/<%= user[:peer] %>,CustomPresence:<%= user[:peer] %>
12
- exten => <%= user[:peer] %>,1,Dial(SIP/<%= user[:peer] %>)
13
- exten => <%= user[:peer] %>,hint,SIP/<%= user[:peer] %>,CustomPresence:<%= user[:peer] %>
10
+ exten => <%= user[:extension] %>,1,Dial(SIP/<%= user[:login] %>)
11
+ exten => <%= user[:extension] %>,hint,SIP/<%= user[:login] %>,CustomPresence:<%= user[:login] %>
12
+ exten => <%= user[:login] %>,1,Dial(SIP/<%= user[:login] %>)
13
+ exten => <%= user[:login] %>,hint,SIP/<%= user[:login] %>,CustomPresence:<%= user[:login] %>
14
14
 
15
15
  <% end -%>
data/erb/sip.ad.erb CHANGED
@@ -2,7 +2,7 @@
2
2
  <% users.each do |user| -%>
3
3
 
4
4
  ; Name: <%= user[:name] %>
5
- [<%= user[:peer] %>](ad-user)
5
+ [<%= user[:login] %>](ad-user)
6
6
  secret=<%= user[:secret] %>
7
7
  context=<%= user[:context] %>
8
8
  <% if user[:callgroup] -%>
data/lib/obelisk.rb CHANGED
@@ -5,6 +5,8 @@ require "yaml"
5
5
  require "erb"
6
6
  require "logger"
7
7
  require "fileutils"
8
+ require "curb"
9
+ require "json"
8
10
 
9
11
  module Obelisk
10
12
  DEFAULT_CONFIG_PATH = "#{Dir.home}/.obelisk.conf"
@@ -16,7 +18,7 @@ module Obelisk
16
18
  bind_pass: "pass",
17
19
  },
18
20
  :mapping => {
19
- samaccountname: :peer,
21
+ samaccountname: :login,
20
22
  info: :secret,
21
23
  facsimiletelephonenumber: :context,
22
24
  ipphone: :extension,
@@ -34,6 +36,7 @@ module Obelisk
34
36
  },
35
37
  :asterisk_conf_dir => "/tmp/asterisk",
36
38
  :asterisk_restart_command => %q{asterisk -x "core restart gracefully"},
39
+ :obelisk_portal_update_url => "http://localhost:3000/contacts/updatedb",
37
40
  :erb_file_dir => File.expand_path(File.dirname(__FILE__) + "/../erb")
38
41
  }
39
42
 
@@ -43,6 +46,7 @@ module Obelisk
43
46
  params[:conf_dir] ||= $conf[:asterisk_conf_dir]
44
47
  params[:force] ||= false
45
48
  params[:restart] ||= false
49
+ params[:updb] ||= false
46
50
  FileUtils.mkdir_p params[:conf_dir]
47
51
  b = binding
48
52
  up = false
@@ -60,9 +64,18 @@ module Obelisk
60
64
  end
61
65
  end
62
66
  system $conf[:asterisk_restart_command] if up && params[:restart]
67
+ update_rails_db users if up && params[:updb]
63
68
  up
64
69
  end
65
70
 
71
+ def self.update_rails_db(users)
72
+ users.each { |u| u.delete :secret }
73
+ c = Curl::Easy.http_post $conf[:obelisk_portal_update_url], JSON.dump(users) do |curl|
74
+ curl.headers['Accept'] = 'application/json'
75
+ curl.headers['Content-Type'] = 'application/json'
76
+ end
77
+ end
78
+
66
79
  def self.get_ad_users(ou = nil)
67
80
  load_conf
68
81
  settings = {
@@ -78,7 +91,7 @@ module Obelisk
78
91
  ActiveDirectory::Base.setup(settings)
79
92
  ActiveDirectory::User.find(:all).select{ |u| u.valid_attribute? :info }.map do |u|
80
93
  k = $conf[:mapping].values
81
- v = $conf[:mapping].keys.map { |attr| u.valid_attribute?(attr) ? u.send(attr) : $conf[:defaults][attr] }
94
+ v = $conf[:mapping].keys.map { |attr| u.valid_attribute?(attr) ? u.send(attr).force_encoding("UTF-8") : $conf[:defaults][attr] }
82
95
  Hash[k.zip v]
83
96
  end
84
97
  end
@@ -1,3 +1,3 @@
1
1
  module Obelisk
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/obelisk.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
-
23
+
24
24
  spec.add_runtime_dependency "active_directory"
25
+ spec.add_runtime_dependency "curb"
25
26
  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.2.0
4
+ version: 0.2.1
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-27 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,11 +52,27 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: curb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Generate Asterisk configs and provides integration of Rails app
56
70
  email:
57
71
  - goredar@gmail.com
58
72
  executables:
73
+ - bundler
59
74
  - obelisk_cli
75
+ - rake
60
76
  extensions: []
61
77
  extra_rdoc_files: []
62
78
  files:
@@ -65,7 +81,9 @@ files:
65
81
  - LICENSE.txt
66
82
  - README.md
67
83
  - Rakefile
84
+ - bin/bundler
68
85
  - bin/obelisk_cli
86
+ - bin/rake
69
87
  - erb/extensions.ad.erb
70
88
  - erb/sip.ad.erb
71
89
  - lib/obelisk.rb