ndee 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +11 -0
- data/Rakefile +14 -0
- data/bin/ndee +5 -0
- data/examples/rubychan.de.conf +5 -0
- data/lib/apache_config/node.rb +37 -0
- data/lib/apache_config/virtual_host.rb +25 -0
- data/lib/apache_config/write_back_array.rb +13 -0
- data/lib/apache_config.rb +74 -0
- data/lib/ndee/version.rb +3 -0
- data/lib/ndee.rb +47 -0
- data/ndee.gemspec +22 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d700690c4597900166e3e9ecbe7213d1b89c7e82
|
4
|
+
data.tar.gz: f47c213cb2113015f50923d96f5ad6b267712f71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e053523739d217ec130534c670b25a26d2bc748e1dcede0e6ae28055188032e4669d0ce5e0cb7b82c4c4829bb7b05d7f4e0f12d236a99f98ede723bc6cd094e2
|
7
|
+
data.tar.gz: 76f92ea6b365397f40b6516f6719af12647bf42b28bc4de49be3932d9440cb306b5aeb4b95ddb0932400c571476b2d70725f6398681da18173f8df7451dc8934
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kornelius Kalnbach
|
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.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Run a simple test'
|
4
|
+
task :test do
|
5
|
+
require 'ndee'
|
6
|
+
|
7
|
+
def Ndee.sites_available
|
8
|
+
'./examples'
|
9
|
+
end
|
10
|
+
|
11
|
+
puts Ndee.document_roots_by_domain['rubychan.de'] == '/var/www/rubychan.de/current/public' ? '.' : 'F'
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :test
|
data/bin/ndee
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Apache
|
2
|
+
class Node
|
3
|
+
attr_accessor :name, :content, :children, :parent
|
4
|
+
|
5
|
+
def initialize name, content = nil
|
6
|
+
@name, @content = name, content
|
7
|
+
end
|
8
|
+
|
9
|
+
def [] name
|
10
|
+
r = Array(children).select { |child| child.name.downcase == name.downcase }
|
11
|
+
case r.size
|
12
|
+
when 0
|
13
|
+
self << Node.new(name)
|
14
|
+
when 1
|
15
|
+
r.first
|
16
|
+
else
|
17
|
+
r
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def << node
|
22
|
+
@children ||= []
|
23
|
+
@children << node
|
24
|
+
node.parent = self
|
25
|
+
|
26
|
+
node
|
27
|
+
end
|
28
|
+
|
29
|
+
def isRoot?
|
30
|
+
parent.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def hasChildren?
|
34
|
+
children && children.any?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class VirtualHost
|
2
|
+
def initialize(config)
|
3
|
+
@config = config
|
4
|
+
end
|
5
|
+
|
6
|
+
def domain
|
7
|
+
@config['ServerName'].content
|
8
|
+
end
|
9
|
+
|
10
|
+
def domain=(dom)
|
11
|
+
@config['ServerName'].content = dom
|
12
|
+
end
|
13
|
+
|
14
|
+
def aliases
|
15
|
+
Apache::WriteBackArray.new(@config['ServerAlias'], @config['ServerAlias'].content.to_s.split(/\s+/))
|
16
|
+
end
|
17
|
+
|
18
|
+
def domains
|
19
|
+
[domain] + aliases
|
20
|
+
end
|
21
|
+
|
22
|
+
def document_root
|
23
|
+
@config['DocumentRoot'].content
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# See https://github.com/openminds/apache_config.
|
2
|
+
module Apache
|
3
|
+
autoload :Node, 'apache_config/node'
|
4
|
+
autoload :VirtualHost, 'apache_config/virtual_host'
|
5
|
+
autoload :WriteBackArray, 'apache_config/write_back_array'
|
6
|
+
|
7
|
+
class Config
|
8
|
+
TabSize = " "
|
9
|
+
Comment = /^\s*#\s?(.*?)\s*$/
|
10
|
+
Blank = /^\s+$/
|
11
|
+
Directive = /^\s*(\w+)(?:\s+(.*?)|)$/
|
12
|
+
SectionOpen = /^\s*<\s*(\w+)(?:\s+([^>]+)|\s*)>$/
|
13
|
+
SectionClose = /^\s*<\/\s*(\w+)\s*>$/
|
14
|
+
|
15
|
+
attr_reader :path
|
16
|
+
|
17
|
+
def initialize(path)
|
18
|
+
@path = path
|
19
|
+
@config = parse_config(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def virtual_hosts
|
23
|
+
@config.children.map { |vh| VirtualHost.new(vh) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def save!
|
27
|
+
File.open(@path, 'w') do |f|
|
28
|
+
f.write to_config
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_config(root = nil, indent = "")
|
33
|
+
element = root || @config
|
34
|
+
content = ""
|
35
|
+
|
36
|
+
case
|
37
|
+
when element.isRoot?
|
38
|
+
element.children.map { |c| to_config(c) }.join
|
39
|
+
when element.hasChildren?
|
40
|
+
"#{indent}<#{element.name} #{element.content}>\n" +
|
41
|
+
element.children.map {|c| to_config(c, indent + TabSize) }.join +
|
42
|
+
"#{indent}</#{element.name}>\n"
|
43
|
+
when element.name == :comment
|
44
|
+
"#{indent}# #{element.content}\n"
|
45
|
+
when element.name == :blank
|
46
|
+
"#{indent}\n"
|
47
|
+
else
|
48
|
+
"#{indent}#{element.name} #{element.content}\n"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def parse_config(path)
|
54
|
+
current_child = Node.new("ROOT")
|
55
|
+
|
56
|
+
File.open(path).read.split(/\n/).each do |line|
|
57
|
+
case line
|
58
|
+
when Comment
|
59
|
+
current_child << Node.new(:comment, $1)
|
60
|
+
when Blank
|
61
|
+
current_child << Node.new(:blank)
|
62
|
+
when Directive
|
63
|
+
current_child << Node.new($1, $2)
|
64
|
+
when SectionOpen
|
65
|
+
current_child = current_child << Node.new($1, $2)
|
66
|
+
when SectionClose
|
67
|
+
current_child = current_child.parent
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
current_child
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/ndee/version.rb
ADDED
data/lib/ndee.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "ndee/version"
|
2
|
+
require "apache_config"
|
3
|
+
|
4
|
+
module Ndee
|
5
|
+
def self.document_roots_by_domain
|
6
|
+
{}.tap do |mappings|
|
7
|
+
each_domain do |domain, vhost|
|
8
|
+
mappings[domain] = vhost.document_root
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.sites_available
|
14
|
+
'/etc/apache2/sites-available'
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.each_domain
|
18
|
+
Dir["#{sites_available}/*.conf"].each do |conf|
|
19
|
+
config = Apache::Config.new(conf)
|
20
|
+
|
21
|
+
for vhost in config.virtual_hosts
|
22
|
+
next unless vhost.domain
|
23
|
+
|
24
|
+
for domain in [vhost.domain] + vhost.aliases
|
25
|
+
yield domain, vhost
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.cli!
|
32
|
+
if name = ARGV.first
|
33
|
+
if document_root = document_roots_by_domain[name]
|
34
|
+
if Dir.exist? document_root
|
35
|
+
exec 'cd', document_root
|
36
|
+
else
|
37
|
+
puts "#{document_root} doesn't exist"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts "#{name} not found"
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts 'ndee cds into the DocumentRoot of the given domain.'
|
44
|
+
puts 'Usage: ndee subdomain.example.com'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/ndee.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ndee/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ndee"
|
8
|
+
spec.version = Ndee::VERSION
|
9
|
+
spec.authors = ["Kornelius Kalnbach"]
|
10
|
+
spec.email = ["murphy@rubychan.de"]
|
11
|
+
spec.summary = %q{ndee reads Apache confs and cds into the DocumentRoot of the given domain.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ndee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kornelius Kalnbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-03 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- murphy@rubychan.de
|
44
|
+
executables:
|
45
|
+
- ndee
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/ndee
|
55
|
+
- examples/rubychan.de.conf
|
56
|
+
- lib/apache_config.rb
|
57
|
+
- lib/apache_config/node.rb
|
58
|
+
- lib/apache_config/virtual_host.rb
|
59
|
+
- lib/apache_config/write_back_array.rb
|
60
|
+
- lib/ndee.rb
|
61
|
+
- lib/ndee/version.rb
|
62
|
+
- ndee.gemspec
|
63
|
+
homepage: ''
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: ndee reads Apache confs and cds into the DocumentRoot of the given domain.
|
87
|
+
test_files: []
|