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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee63c9bc04ce277b3a8a20388b3127a18d12f66b
4
- data.tar.gz: a2a5e7d0554110a056e6cd1dd03a83201837f59b
3
+ metadata.gz: 65088fa3e4ed65a2ce64d3dcf84d9cce96e409d8
4
+ data.tar.gz: 2f89247a9a85e2d09d1c91f831e5c62dea4610da
5
5
  SHA512:
6
- metadata.gz: 87cb0c1c6f6ccaf2987d8704bc69d75e0eff99b1a06af9a7f9e7147b85c3fb275249a6cb30ad737f56cf4f4dc06b5711ad44123c9ec7fdeca4176d216ecd7d72
7
- data.tar.gz: 23ce26dbd432af58f6a24a7364fdc4b31cfbcd4344db0eee084f0a43ccd36bf9062e95eecf3202aa452148ec24b13255873795e1286268e18fb6f40e27a58275
6
+ metadata.gz: c8359539bea228722fbfe131c4513cbfd7bc6c91b310b0955dca400ac9d297d1b050edd6fffc20983911c7862ec263c93de3b2f5ac7b8b1df43323f4ee917980
7
+ data.tar.gz: 4d5dc36294f46f5cf8000ff6aec95787963dfeef938e2a7ddc16a85c8bfdb060efa685dfdcc2e288bd917eb2c1f94bdcbece1c93d64d8883f95a6940cef8a174
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
  gem "mysql2"
4
4
  gem "ipaddress"
5
+ gem "trollop"
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Gestio2masq
2
+ [![Gem Version](https://badge.fury.io/rb/gestio2masq.svg)](http://badge.fury.io/rb/gestio2masq)
2
3
 
3
4
  gestio2masq generates dnsmasq configuration files from gestioip mysql databases. Or at least, it does this
4
5
  *for me*. YMMV.
data/exe/gestio2masq CHANGED
@@ -1,27 +1,58 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'mysql2'
3
3
  require 'ipaddress'
4
- require 'json'
4
+ require 'yaml'
5
+ require 'trollop'
5
6
 
6
- config_file = '/etc/gestio2masq.conf'
7
- begin
8
- config = JSON.parse(File.read(config_file))
9
- rescue
10
- puts %Q(Error reading config from file #{config_file})
11
- exit(status=1)
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
- dest_dir = config['destdir']
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['sqlhost'],
19
- :username => config['sqluser'],
20
- :password => config['sqlpass'],
21
- :database => config['database']
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['database']} on host #{config['sqlhost']} as #{config['sqluser']}.)
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(#{dest_dir}/dnsmasq.d/ranges),'w').puts(ranges_entries.join("\n"))
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(#{dest_dir}/dnsmasq.d/cnames),'w').puts(cnames_entries.join("\n"))
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(#{dest_dir}/dnsmasq-dhcp-hosts.conf),'w').puts(dhcp_hosts_entries.join("\n"))
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(#{dest_dir}/dnsmasq-hosts.conf),'w').puts(hosts_entries.join("\n"))
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'
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 a executable that generates dnsmasq dns and dhcp configuration from a gestioip\
13
- database. Currently only mysql databases are supported}
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
- "sqlhost":"<ipaddr>",
3
- "sqluser":"<username>",
4
- "sqlpass":"<password>",
5
- "database":"gestioip",
6
- "destdir":"/etc"
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.7
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-14 00:00:00.000000000 Z
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 a executable that generates dnsmasq dns and dhcp configuration from a gestioip\
43
- database. Currently only mysql databases are supported
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: