obelisk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a01085189b0707363fd87094b315208b20c26575
4
+ data.tar.gz: 203c580d436000cd0e0d386a0d6ede6ab9591c51
5
+ SHA512:
6
+ metadata.gz: 2317681ca35c145bd9e1cc64b9e8e01617f00593256a21dfcbeab71e928ea2811dfdcfe3d49188e93aed580191be91c6468d01c7899334c26e067e6ee01b2b04
7
+ data.tar.gz: 3f4f904e8420eb5b0d3f94374b777f676f7b2bfbf04f81a438d5f05c63833c88a2128edb11a2a9bb55888daa982899ede49e2c080e85a344b37b3e6315e6e293
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ .obelisk.conf
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in obelisk.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 goredar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Obelisk
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'obelisk'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install obelisk
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/obelisk/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,55 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
10
+
11
+ PATCH = 2
12
+ MINOR = 1
13
+ MAJOR = 0
14
+
15
+ desc "Commit patch and release gem"
16
+ task :patch, :commit_message do |t, args|
17
+ update(args[:commit_message]){ |sv,i| i == PATCH ? sv.succ : sv }
18
+ end
19
+
20
+ desc "Commit minor update and release gem"
21
+ task :minor, :commit_message do |t, args|
22
+ update(args[:commit_message]) do |sv,i|
23
+ case i
24
+ when MINOR then sv.succ
25
+ when PATCH then "0"
26
+ else sv
27
+ end
28
+ end
29
+ end
30
+
31
+ desc "Commit major update and release gem"
32
+ task :major, :commit_message do |t, args|
33
+ update(args[:commit_message]){ |sv,i| i == MAJOR ? sv.succ : "0" }
34
+ end
35
+
36
+
37
+ def update(msg)
38
+ # Update version
39
+ File.open "./lib/obelisk/version.rb", "r+" do |f|
40
+ up = f.read.sub(/\d+.\d+.\d+/) { |ver| ver.split('.').map.with_index{ |sv, i| yield sv,i }.join('.') }
41
+ f.seek 0
42
+ f.write up
43
+ end
44
+ puts "Changed version."
45
+ puts "Removed #{File.delete(*Dir['./*.gem'])} old gems"
46
+ # add new files to repo
47
+ %x(git add --all .)
48
+ # commit
49
+ if msg then %x(git commit -a -m "#{msg}")
50
+ else %x(git commit -a --reuse-message=HEAD); end
51
+ %x(git push)
52
+ puts "Pushed to github."
53
+ Dir["./*.gemspec"].each { |spec| puts %x(gem build #{spec}) }
54
+ Dir["./*.gem"].each { |gem| puts %x(gem push #{gem}) }
55
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'obelisk'
7
+ Obelisk.load_conf
8
+
9
+ ARGV << "help" if ARGV.empty?
10
+
11
+ if ARGV.include? "install"
12
+ Obelisk.save_def_conf
13
+ puts "Default configuration file's been saved as #{Obelisk::DEFAULT_CONFIG_PATH}. Change it according to your needs."
14
+ exit
15
+ else
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]
26
+ Commands:
27
+ install - save default config file for obelisk to #{Obelisk::DEFAULT_CONFIG_PATH}
28
+ conf - generate config files for Asterisk and place it to #{$conf[:asterisk_settings][:config_dir]}
29
+ updb - update Rails database for Asterisk Portal}
30
+ exit
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ ; This file is generated by Obelisk <%=Obelisk::VERSION %>
2
+ ; Date: <%= DateTime.now %>
3
+
4
+ <% current_context = nil -%>
5
+ <% users.sort { |a, b| a[:context] <=> b[:context] }.each do |user| -%>
6
+ <% if current_context != user[:context] -%>
7
+ <% current_context = user[:context] -%>
8
+ [<%= current_context %>-ad-users]
9
+
10
+ <% end -%>
11
+ exten => <%= user[:extension] %>,1,Dial(SIP/<%= user[:peer] %>)
12
+ exten => <%= user[:extension] %>,hint,SIP/<%= user[:peer] %>,CustomPresence:<%= user[:peer] %>
13
+ exten => <%= user[:peer] %>,1,Dial(SIP/<%= user[:peer] %>)
14
+ exten => <%= user[:peer] %>,hint,SIP/<%= user[:peer] %>,CustomPresence:<%= user[:peer] %>
15
+
16
+ <% end -%>
@@ -0,0 +1,13 @@
1
+ ; This file is generated by Obelisk <%=Obelisk::VERSION %>
2
+ ; Date: <%= DateTime.now %>
3
+ <% users.each do |user| -%>
4
+
5
+ ; Name: <%= user[:name] %>
6
+ [<%= user[:peer] %>](ad-user)
7
+ secret=<%= user[:secret] %>
8
+ context=<%= user[:context] %>
9
+ <% if user[:callgroup] -%>
10
+ namedcallgroup=<%= user[:callgroup] %>
11
+ namedpickupgroup=<%= user[:callgroup] %>
12
+ <% end -%>
13
+ <% end -%>
@@ -0,0 +1,88 @@
1
+ require "obelisk/version"
2
+
3
+ require "active_directory"
4
+ require "yaml"
5
+ require "erb"
6
+ require "logger"
7
+ require "fileutils"
8
+
9
+ module Obelisk
10
+ DEFAULT_CONFIG_PATH = "#{Dir.home}/.obelisk.conf"
11
+ DEFAULT_CONFIG = {
12
+ :ad_settings => {
13
+ ldap_host: "localhost",
14
+ base_dn: "ou=STAFF,dc=CORP,dc=LOCAL",
15
+ bind_name: "user",
16
+ bind_pass: "pass",
17
+ },
18
+ :mapping => {
19
+ samaccountname: :peer,
20
+ info: :secret,
21
+ facsimiletelephonenumber: :context,
22
+ ipphone: :extension,
23
+ pager: :callgroup,
24
+ # Used for AdressBook generation
25
+ displayname: :name,
26
+ mobile: :mobile,
27
+ homephone: :home,
28
+ company: :company,
29
+ department: :department,
30
+ title: :title,
31
+ },
32
+ :defaults => {
33
+ facsimiletelephonenumber: "from-internal"
34
+ },
35
+ :asterisk_conf_dir => "/tmp/asterisk",
36
+ :erb_file_dir => File.expand_path(File.dirname(__FILE__) + "/../erb")
37
+ }
38
+
39
+ $conf = {}
40
+
41
+ def self.make_erb_conf
42
+ FileUtils.mkdir_p $conf[:asterisk_conf_dir]
43
+ b = binding
44
+ users = get_ad_users
45
+ Dir[File.expand_path "*.erb", $conf[:erb_file_dir]].each do |erb|
46
+ conf_file = File.expand_path File.basename(erb, ".erb"), $conf[:asterisk_conf_dir]
47
+ File.open(conf_file, "w") { |file| file.write ERB.new(IO.read(erb), nil, "-").result(b) }
48
+ end
49
+ end
50
+
51
+ def self.get_ad_users(ou = nil)
52
+ load_conf
53
+ settings = {
54
+ :host => $conf[:ad_settings][:ldap_host],
55
+ :base => (ou ? "ou=#{ou},#{$conf[:ad_settings][:base_dn]}" : $conf[:ad_settings][:base_dn]),
56
+ :port => 389,
57
+ :auth => {
58
+ :method => :simple,
59
+ :username => $conf[:ad_settings][:bind_name],
60
+ :password => $conf[:ad_settings][:bind_pass],
61
+ }
62
+ }
63
+ ActiveDirectory::Base.setup(settings)
64
+ ActiveDirectory::User.find(:all).select{ |u| u.valid_attribute? :info }.map do |u|
65
+ k = $conf[:mapping].values
66
+ v = $conf[:mapping].keys.map { |attr| u.valid_attribute?(attr) ? u.send(attr) : $conf[:defaults][attr] }
67
+ Hash[k.zip v]
68
+ end
69
+ end
70
+
71
+ def self.save_def_conf(file_name = DEFAULT_CONFIG_PATH)
72
+ conf = DEFAULT_CONFIG
73
+ if File.exists? file_name
74
+ merge_proc = proc { |k, o, n| o.is_a?(Hash) && n.is_a?(Hash) ? o.merge(n, &merge_proc) : n }
75
+ conf.merge! YAML.load(IO.read(file_name)), &merge_proc
76
+ end
77
+ File.open(file_name, 'w') { |f| f.write YAML.dump conf }
78
+ end
79
+
80
+ def self.load_conf(file_name = DEFAULT_CONFIG_PATH)
81
+ return unless $conf.empty?
82
+ begin
83
+ $conf = YAML.load IO.read file_name
84
+ rescue
85
+ $conf = DEFAULT_CONFIG
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module Obelisk
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'obelisk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "obelisk"
8
+ spec.version = Obelisk::VERSION
9
+ spec.authors = ["goredar"]
10
+ spec.email = ["goredar@gmail.com"]
11
+ spec.summary = %q{Asterisk AD integration tool}
12
+ spec.description = %q{Generate Asterisk configs and provides integration of Rails app}
13
+ spec.homepage = "https://obelisk.goredar.it"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_runtime_dependency "active_directory"
25
+ end
@@ -0,0 +1,11 @@
1
+ require "test/unit"
2
+ require "obelisk"
3
+
4
+ class ADTestCase < Test::Unit::TestCase
5
+ def test_get_users
6
+ users = Obelisk.get_ad_users
7
+ assert users.count > 0
8
+ users = Obelisk.get_ad_users "non-exists"
9
+ assert_equal 0, users.count
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require "test/unit"
2
+ require "obelisk"
3
+ require "securerandom"
4
+
5
+ class ErbTestCase < Test::Unit::TestCase
6
+ def test_make_erb_conf
7
+ dir = "/tmp/#{SecureRandom.hex}"
8
+ $conf[:asterisk_conf_dir] = dir
9
+ Obelisk.make_erb_conf
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
+ puts %x(cat #{dir}/*)
13
+ File.delete *Dir[File.expand_path "*", dir]
14
+ Dir.rmdir dir
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require "test/unit"
2
+ require "obelisk"
3
+
4
+ class ObeliskTestCase < Test::Unit::TestCase
5
+ def test_save_conf
6
+ test_conf_file = "/tmp/.obelisk.conf"
7
+ File.delete(test_conf_file) if File.exist?(test_conf_file)
8
+ Obelisk.save_def_conf test_conf_file
9
+ assert File.exist?(test_conf_file)
10
+ assert_equal YAML.dump(Obelisk::DEFAULT_CONFIG), IO.read(test_conf_file)
11
+ File.delete(test_conf_file)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obelisk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - goredar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: active_directory
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Generate Asterisk configs and provides integration of Rails app
56
+ email:
57
+ - goredar@gmail.com
58
+ executables:
59
+ - obelisk_cli
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/obelisk_cli
69
+ - erb/extensions.ad.erb
70
+ - erb/sip.ad.erb
71
+ - lib/obelisk.rb
72
+ - lib/obelisk/version.rb
73
+ - obelisk.gemspec
74
+ - test/test_ad.rb
75
+ - test/test_erb.rb
76
+ - test/test_obelisk.rb
77
+ homepage: https://obelisk.goredar.it
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.5
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Asterisk AD integration tool
101
+ test_files:
102
+ - test/test_ad.rb
103
+ - test/test_erb.rb
104
+ - test/test_obelisk.rb