gestio2masq 0.0.7 → 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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/exe/gestio2masq +48 -17
- data/gestio2masq.gemspec +3 -3
- data/lib/gestio2masq/CHANGELOG +35 -0
- data/lib/gestio2masq/examples/gestio2masq.conf +7 -7
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65088fa3e4ed65a2ce64d3dcf84d9cce96e409d8
|
4
|
+
data.tar.gz: 2f89247a9a85e2d09d1c91f831e5c62dea4610da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8359539bea228722fbfe131c4513cbfd7bc6c91b310b0955dca400ac9d297d1b050edd6fffc20983911c7862ec263c93de3b2f5ac7b8b1df43323f4ee917980
|
7
|
+
data.tar.gz: 4d5dc36294f46f5cf8000ff6aec95787963dfeef938e2a7ddc16a85c8bfdb060efa685dfdcc2e288bd917eb2c1f94bdcbece1c93d64d8883f95a6940cef8a174
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/exe/gestio2masq
CHANGED
@@ -1,27 +1,58 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'mysql2'
|
3
3
|
require 'ipaddress'
|
4
|
-
require '
|
4
|
+
require 'yaml'
|
5
|
+
require 'trollop'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
defaults = {
|
8
|
+
:config => '/etc/gestio2masq.conf',
|
9
|
+
:destdir => '/etc',
|
10
|
+
:sqlhost => 'localhost',
|
11
|
+
:database => 'gestioip',
|
12
|
+
:sqluser => 'root'
|
13
|
+
}
|
14
|
+
|
15
|
+
opts = Trollop::options do
|
16
|
+
opt :config, 'Config file path', :short=>'c', :type=>:string
|
17
|
+
opt :destdir, 'Destination dir', :short=>'t', :type=>:string
|
18
|
+
opt :sqlhost, 'Database host', :short=>'h', :type=>:string
|
19
|
+
opt :database, 'Database name', :short=>'d', :type=>:string
|
20
|
+
opt :sqluser, 'Database user', :short=>'u', :type=>:string
|
21
|
+
opt :sqlpass, 'Database password', :short=>'p', :type=>:string
|
22
|
+
end
|
23
|
+
|
24
|
+
config_file = opts[:config]||defaults[:config]
|
25
|
+
|
26
|
+
config = nil
|
27
|
+
if File.exist?(config_file)
|
28
|
+
begin
|
29
|
+
config = YAML.load(File.read(config_file))
|
30
|
+
rescue => detail
|
31
|
+
puts detail.backtrace
|
32
|
+
puts %Q(Error reading config from file #{config_file})
|
33
|
+
exit(1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if config.nil? or (config.class != Hash)
|
38
|
+
config = Hash.new
|
39
|
+
else
|
40
|
+
# symbolize hash keys (json format compatibility)
|
41
|
+
config = Hash[config.map{|(k,v)| [k.to_sym,v]}]
|
12
42
|
end
|
13
43
|
|
14
|
-
|
44
|
+
# Precedence (low to high): defaults, config file, command line
|
45
|
+
config = defaults.merge(config).merge(Hash(opts.select {|k,v| !v.nil?}))
|
15
46
|
|
16
47
|
begin
|
17
48
|
mysql = Mysql2::Client.new(
|
18
|
-
:host => config[
|
19
|
-
:username => config[
|
20
|
-
:password => config[
|
21
|
-
:database => config[
|
49
|
+
:host => config[:sqlhost],
|
50
|
+
:username => config[:sqluser],
|
51
|
+
:password => config[:sqlpass],
|
52
|
+
:database => config[:database]
|
22
53
|
)
|
23
54
|
rescue
|
24
|
-
puts %Q(Error connecting to database #{config[
|
55
|
+
puts %Q(Error connecting to database #{config[:database]} on host #{config[:sqlhost]} as #{config[:sqluser]}.)
|
25
56
|
exit(status=1)
|
26
57
|
end
|
27
58
|
|
@@ -83,18 +114,18 @@ hosts_data.each { |host|
|
|
83
114
|
}
|
84
115
|
puts "="*80
|
85
116
|
puts "RANGES"
|
86
|
-
File.new(%Q(#{
|
117
|
+
File.new(%Q(#{config[:destdir]}/dnsmasq.d/ranges),'w').puts(ranges_entries.join("\n"))
|
87
118
|
puts(ranges_entries.join("\n"))
|
88
119
|
puts "="*80
|
89
120
|
puts "CNAMES"
|
90
|
-
File.new(%Q(#{
|
121
|
+
File.new(%Q(#{config[:destdir]}/dnsmasq.d/cnames),'w').puts(cnames_entries.join("\n"))
|
91
122
|
puts(cnames_entries.join("\n"))
|
92
123
|
puts "="*80
|
93
124
|
puts "DHCP HOSTS"
|
94
|
-
File.new(%Q(#{
|
125
|
+
File.new(%Q(#{config[:destdir]}/dnsmasq-dhcp-hosts.conf),'w').puts(dhcp_hosts_entries.join("\n"))
|
95
126
|
puts(dhcp_hosts_entries.join("\n"))
|
96
127
|
puts "="*80
|
97
128
|
puts "HOSTS"
|
98
|
-
File.new(%Q(#{
|
129
|
+
File.new(%Q(#{config[:destdir]}/dnsmasq-hosts.conf),'w').puts(hosts_entries.join("\n"))
|
99
130
|
puts(hosts_entries.join("\n"))
|
100
131
|
|
data/gestio2masq.gemspec
CHANGED
@@ -4,13 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "gestio2masq"
|
7
|
-
spec.version = '0.0
|
7
|
+
spec.version = '0.1.0'
|
8
8
|
spec.authors = ["svdasein"]
|
9
9
|
spec.email = ["svdasein@github"]
|
10
10
|
|
11
11
|
spec.summary = %q{Executable that generates DNSmasq conifguration files from Gestioip data}
|
12
|
-
spec.description = %q{This gem provides
|
13
|
-
|
12
|
+
spec.description = %q{This gem provides an executable that generates dnsmasq dns and dhcp configuration from a
|
13
|
+
gestioip mysql database.}
|
14
14
|
spec.homepage = "http://github.com/svdasein/gestio2masq"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
0.1.0
|
2
|
+
|
3
|
+
* Added defaults and command line options.
|
4
|
+
|
5
|
+
defaults = {
|
6
|
+
:config => '/etc/gestio2masq.conf',
|
7
|
+
:destdir => '/etc',
|
8
|
+
:sqlhost => 'localhost',
|
9
|
+
:database => 'gestioip',
|
10
|
+
:sqluser => 'root'
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
gestio2masq --help
|
15
|
+
Options:
|
16
|
+
-c, --config=<s> Config file path
|
17
|
+
-t, --destdir=<s> Destination dir
|
18
|
+
-h, --sqlhost=<s> Database host
|
19
|
+
-d, --database=<s> Database name
|
20
|
+
-u, --sqluser=<s> Database user
|
21
|
+
-p, --sqlpass=<s> Database password
|
22
|
+
-e, --help Show this message
|
23
|
+
|
24
|
+
|
25
|
+
Order of precedence, low to high:
|
26
|
+
|
27
|
+
defaults
|
28
|
+
config file values
|
29
|
+
command line options
|
30
|
+
|
31
|
+
|
32
|
+
* Changed config file format to YAML. Note that the JSON form will still work, but you should really
|
33
|
+
convert it to YAML.
|
34
|
+
|
35
|
+
* got rid of dest_dir; just using config hash directly
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
---
|
2
|
+
:database: gestioip
|
3
|
+
:sqlhost: <ipaddr>
|
4
|
+
:sqluser: <username>
|
5
|
+
:sqlpass: <password>
|
6
|
+
:destdir: "/etc"
|
7
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gestio2masq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- svdasein
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,8 +39,8 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: |-
|
42
|
-
This gem provides
|
43
|
-
|
42
|
+
This gem provides an executable that generates dnsmasq dns and dhcp configuration from a
|
43
|
+
gestioip mysql database.
|
44
44
|
email:
|
45
45
|
- svdasein@github
|
46
46
|
executables:
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- Rakefile
|
57
57
|
- exe/gestio2masq
|
58
58
|
- gestio2masq.gemspec
|
59
|
+
- lib/gestio2masq/CHANGELOG
|
59
60
|
- lib/gestio2masq/examples/gestio2masq.conf
|
60
61
|
homepage: http://github.com/svdasein/gestio2masq
|
61
62
|
licenses:
|