gestio2masq 0.1.4 → 0.1.6

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: 8dfd30c9c5e99572bd37dc0794a998ba179f0b9d
4
- data.tar.gz: fcc607f12edb58b03154303ce321e8ab20547e1a
3
+ metadata.gz: fd03a774fbdf430652788b68007b6076dcbb3751
4
+ data.tar.gz: d691394909c932898ed0e8751cb265dbe2f96b45
5
5
  SHA512:
6
- metadata.gz: 93397dc8926c166729e80814d63eec42139100738431a99c326dec49fab9794a7d7560ce33738219195202bc5fbd64b94bc69ae92a399e626380bbf008223d7d
7
- data.tar.gz: 996de291df6f8ee269f843a29c3fd63e471e20e18886d10734a24090cac549c053824e934652f54421b46ac93708cf17c196dd8f9218a31955791b8693ceaa5f
6
+ metadata.gz: a9e906059ded069a4adc9a12b1d9f57f27b7e43f28e3d65f9ae86c4c3a274042cb3bb4acb96b785c5ef28d5a0873e5d12de007603f172781a2915c58f2a35ea0
7
+ data.tar.gz: d17967e5d28542be39b2203183e587d8c387a851b6c408024af16153ee302b658e46bcc6d1ef10bf289aab91d866916635750237db9e00c3eb8851054565ef2c
@@ -1,3 +1,7 @@
1
+ 0.1.5
2
+ * fix duplicate license, move changelog
3
+ * filter out ipv6 addresses (they caused a crash)
4
+
1
5
  0.1.4
2
6
  * Add license
3
7
  * readme updates
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 svdasein
3
+ Copyright (c) 2015 David A. Parker
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Gestio2masq
2
2
  [![Gem Version](https://badge.fury.io/rb/gestio2masq.svg)](http://badge.fury.io/rb/gestio2masq)
3
3
 
4
- gestio2masq generates [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) configuration files from [GestióIP](http://www.gestioip.net/) mysql databases.
5
- Or at least, it does this for *me*. YMMV.
4
+ gestio2masq generates [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) configuration files from IPAM data in
5
+ a [GestióIP](http://www.gestioip.net/) mysql database.
6
6
 
7
7
 
8
8
 
@@ -18,7 +18,7 @@ or
18
18
 
19
19
  $ gem install gestio2masq
20
20
 
21
- Once installed, copy the example config file to /etc/ and edit. The config file is self documenting :->
21
+ Once installed, copy the example config file to /etc/ and edit (or use command line switches, see below).
22
22
 
23
23
  ###gestio2masq requires some custom fields in gestioip.
24
24
 
@@ -16,13 +16,13 @@ defaults = {
16
16
  opts = Trollop::options do
17
17
  usage '[options]'
18
18
  version %Q{Version #{Gestio2masq::VERSION}}
19
- opt :config, 'Config file path', :short=>'c', :type=>:string
20
- opt :destdir, 'Destination dir', :short=>'t', :type=>:string
21
- opt :sqlhost, 'Database host', :short=>'h', :type=>:string
22
- opt :database, 'Database name', :short=>'d', :type=>:string
23
- opt :sqluser, 'Database user', :short=>'u', :type=>:string
24
- opt :sqlpass, 'Database password', :short=>'p', :type=>:string
25
- opt :verbose, 'Verbose output', :short=>'v'
19
+ opt :config, 'Config file path', :short => 'c', :type => :string
20
+ opt :destdir, 'Destination dir', :short => 't', :type => :string
21
+ opt :sqlhost, 'Database host', :short => 'h', :type => :string
22
+ opt :database, 'Database name', :short => 'd', :type => :string
23
+ opt :sqluser, 'Database user', :short => 'u', :type => :string
24
+ opt :sqlpass, 'Database password', :short => 'p', :type => :string
25
+ opt :verbose, 'Verbose output', :short => 'v'
26
26
  end
27
27
 
28
28
  config_file = opts[:config]||defaults[:config]
@@ -42,27 +42,27 @@ if config.nil? or (config.class != Hash)
42
42
  config = Hash.new
43
43
  else
44
44
  # symbolize hash keys (json format compatibility)
45
- config = Hash[config.map{|(k,v)| [k.to_sym,v]}]
45
+ config = Hash[config.map { |(k, v)| [k.to_sym, v] }]
46
46
  end
47
47
 
48
48
  # Precedence (low to high): defaults, config file, command line
49
- config = defaults.merge(config).merge(Hash(opts.select {|k,v| !v.nil?}))
49
+ config = defaults.merge(config).merge(Hash(opts.select { |k, v| !v.nil? }))
50
50
 
51
51
  begin
52
- mysql = Mysql2::Client.new(
53
- :host => config[:sqlhost],
54
- :username => config[:sqluser],
55
- :password => config[:sqlpass],
56
- :database => config[:database]
57
- )
52
+ mysql = Mysql2::Client.new(
53
+ :host => config[:sqlhost],
54
+ :username => config[:sqluser],
55
+ :password => config[:sqlpass],
56
+ :database => config[:database]
57
+ )
58
58
  rescue
59
- puts %Q(Error connecting to database #{config[:database]} on host #{config[:sqlhost]} as #{config[:sqluser]}.)
60
- exit(status=1)
59
+ puts %Q(Error connecting to database #{config[:database]} on host #{config[:sqlhost]} as #{config[:sqluser]}.)
60
+ exit(status=1)
61
61
  end
62
62
 
63
- networks_data = mysql.query('select * from net',:symbolize_keys => true)
64
- ranges_data = mysql.query('select * from ranges',:symbolize_keys => true)
65
- hosts_data = mysql.query('select * from host order by hostname',:symbolize_keys => true)
63
+ networks_data = mysql.query('select * from net', :symbolize_keys => true)
64
+ ranges_data = mysql.query('select * from ranges', :symbolize_keys => true)
65
+ hosts_data = mysql.query('select * from host order by hostname', :symbolize_keys => true)
66
66
  hosts_extra_data = mysql.query('select custom_host_column_entries.*,custom_host_columns.name
67
67
  from custom_host_column_entries,custom_host_columns
68
68
  where custom_host_columns.id = custom_host_column_entries.cc_id',
@@ -70,69 +70,91 @@ hosts_extra_data = mysql.query('select custom_host_column_entries.*,custom_host_
70
70
  nets_extra_data = mysql.query('select custom_net_column_entries.*,custom_net_columns.name
71
71
  from custom_net_column_entries,custom_net_columns
72
72
  where custom_net_columns.id = custom_net_column_entries.cc_id',
73
- :symbolize_keys => true)
73
+ :symbolize_keys => true)
74
74
 
75
75
  networks = Hash.new
76
76
  networks_data.each { |net|
77
- # Merge custom network columns in with "regular" columns
78
- nets_extra_data.select { |each| each[:net_id] == net[:red_num] } .each { |entry|
79
- net[entry[:name].to_sym] = entry[:entry]
80
- }
81
- net[:bitmask] = IPAddress.parse("#{net[:red]}/#{net[:BM]}").netmask
82
- networks[net[:red_num]] = net
77
+ # Merge custom network columns in with "regular" columns
78
+ nets_extra_data.select { |each| each[:net_id] == net[:red_num] }.each { |entry|
79
+ net[entry[:name].to_sym] = entry[:entry]
80
+ }
81
+ begin
82
+ net[:bitmask] = IPAddress.parse("#{net[:red]}/#{net[:BM]}").netmask
83
+ networks[net[:red_num]] = net
84
+ rescue
85
+ puts "IP address #{net[:red]}/#{net[:BM]} won't parse - rejecting"
86
+ end
83
87
  }
84
88
 
85
89
  ranges_entries = Array.new
86
90
  ranges_data.each { |range|
87
- network = networks[range[:red_num].to_i]
88
- start_ip = IPAddress::IPv4.parse_u32(range[:start_ip].to_i)
89
- end_ip = IPAddress::IPv4.parse_u32(range[:end_ip].to_i)
90
- ranges_entries.push("dhcp-range=#{network[:optiontag]},#{start_ip},#{end_ip},#{network[:bitmask]},#{network[:dynleasetime]}")
91
+ if network = networks[range[:red_num].to_i]
92
+ begin
93
+ start_ip = IPAddress::IPv4.parse_u32(range[:start_ip].to_i)
94
+ end_ip = IPAddress::IPv4.parse_u32(range[:end_ip].to_i)
95
+ ranges_entries.push("dhcp-range=#{network[:optiontag]},#{start_ip},#{end_ip},#{network[:bitmask]},#{network[:dynleasetime]}")
96
+ rescue
97
+ puts "Range #{range[:start_ip]}-#{range[:end_ip]} won't parse - rejecting"
98
+ end
99
+ end
91
100
  }
92
101
 
93
102
  hosts_entries = Array.new
94
103
  dhcp_hosts_entries = Array.new
95
104
  cnames_entries = Array.new
96
105
  hosts_data.each { |host|
97
- host[:ipaddress] = IPAddress::IPv4.parse_u32(host[:ip].to_i)
98
- # Merge custom host columns in with "regular" columns
99
- hosts_extra_data.select { |each| each[:host_id] == host[:id] } .each { |entry|
100
- host[entry[:name].to_sym] = entry[:entry]
101
- }
102
- # make hosts point to the network they belong to
103
- host[:network] = networks[host[:red_num]]
104
- if host[:hostname].size > 0
105
- if host[:MAC]
106
- # static dhcp assignment
107
- if host[:optiontag]
108
- dhcp_hosts_entries.push("#{host[:MAC]},set:#{host[:optiontag]},#{host[:hostname].split('.').shift},#{host[:ipaddress]},#{host[:network][:leasetime]}")
109
- else
110
- dhcp_hosts_entries.push("#{host[:MAC]},#{host[:hostname].split('.').shift},#{host[:ipaddress]},#{host[:network][:leasetime]}")
111
- end
112
- end
113
- # hostname
114
- hosts_entries.push("#{host[:ipaddress]}\t#{host[:hostname]}.#{host[:network][:domain]}")
115
- if host[:CNAMEs]
116
- host[:CNAMEs].split(':').each { |cname|
117
- cnames_entries.push("cname=#{cname},#{host[:hostname]}.#{host[:network][:domain]}")
118
- }
119
- end
120
- end
106
+ begin
107
+ host[:ipaddress] = IPAddress::IPv4.parse_u32(host[:ip].to_i)
108
+ rescue
109
+ puts "Host #{host[:ip]} won't parse - rejecting"
110
+ next
111
+ end
112
+ # Merge custom host columns in with "regular" columns
113
+ hosts_extra_data.select { |each| each[:host_id] == host[:id] }.each { |entry|
114
+ host[entry[:name].to_sym] = entry[:entry]
115
+ }
116
+ # make hosts point to the network they belong to
117
+ host[:network] = networks[host[:red_num]]
118
+ if host[:hostname].size > 0
119
+ if host[:MAC]
120
+ # static dhcp assignment
121
+ if host[:optiontag]
122
+ dhcp_hosts_entries.push("#{host[:MAC]},set:#{host[:optiontag]},#{host[:hostname].split('.').shift},#{host[:ipaddress]},#{host[:network][:leasetime]}")
123
+ else
124
+ dhcp_hosts_entries.push("#{host[:MAC]},#{host[:hostname].split('.').shift},#{host[:ipaddress]},#{host[:network][:leasetime]}")
125
+ end
126
+ end
127
+ # hostname
128
+ if host[:network] and host[:network][:domain]
129
+ hosts_entries.push("#{host[:ipaddress]}\t#{host[:hostname]}.#{host[:network][:domain]}")
130
+ else
131
+ hosts_entries.push("#{host[:ipaddress]}\t#{host[:hostname]}")
132
+ end
133
+ if host[:CNAMEs]
134
+ host[:CNAMEs].split(':').each { |cname|
135
+ if host[:network] and host[:network][:domain]
136
+ cnames_entries.push("cname=#{cname},#{host[:hostname]}.#{host[:network][:domain]}")
137
+ else
138
+ cnames_entries.push("cname=#{cname},#{host[:hostname]}")
139
+ end
140
+ }
141
+ end
142
+ end
121
143
  }
122
144
  puts "="*80 if config[:verbose]
123
145
  puts "RANGES: #{ranges_entries.size}"
124
- File.new(%Q(#{config[:destdir]}/dnsmasq.d/ranges),'w').puts(ranges_entries.join("\n"))
146
+ File.new(%Q(#{config[:destdir]}/dnsmasq.d/ranges), 'w').puts(ranges_entries.join("\n"))
125
147
  puts(ranges_entries.join("\n")) if config[:verbose]
126
148
  puts "="*80 if config[:verbose]
127
149
  puts "CNAMES: #{cnames_entries.size}"
128
- File.new(%Q(#{config[:destdir]}/dnsmasq.d/cnames),'w').puts(cnames_entries.join("\n"))
150
+ File.new(%Q(#{config[:destdir]}/dnsmasq.d/cnames), 'w').puts(cnames_entries.join("\n"))
129
151
  puts(cnames_entries.join("\n")) if config[:verbose]
130
152
  puts "="*80 if config[:verbose]
131
153
  puts "DHCP HOSTS: #{dhcp_hosts_entries.size}"
132
- File.new(%Q(#{config[:destdir]}/dnsmasq-dhcp-hosts.conf),'w').puts(dhcp_hosts_entries.join("\n"))
154
+ File.new(%Q(#{config[:destdir]}/dnsmasq-dhcp-hosts.conf), 'w').puts(dhcp_hosts_entries.join("\n"))
133
155
  puts(dhcp_hosts_entries.join("\n")) if config[:verbose]
134
156
  puts "="*80 if config[:verbose]
135
157
  puts "HOSTS: #{hosts_entries.size}"
136
- File.new(%Q(#{config[:destdir]}/dnsmasq-hosts.conf),'w').puts(hosts_entries.join("\n"))
158
+ File.new(%Q(#{config[:destdir]}/dnsmasq-hosts.conf), 'w').puts(hosts_entries.join("\n"))
137
159
  puts(hosts_entries.join("\n")) if config[:verbose]
138
160
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Executable that generates DNSmasq conifguration files from Gestioip data}
13
13
  spec.description = %q{This gem provides an executable that generates dnsmasq dns and dhcp configuration from a
14
14
  gestioip mysql database.}
15
- spec.homepage = "http://github.com/svdasein/gestio2masq"
15
+ spec.homepage = "http://gitlab.com/svdasein/gestio2masq"
16
16
  spec.license = "MIT"
17
17
 
18
18
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -1,3 +1,3 @@
1
1
  module Gestio2masq
2
- VERSION='0.1.4'
3
- end
2
+ VERSION='0.1.6'
3
+ end
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.1.4
4
+ version: 0.1.6
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-15 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ extra_rdoc_files: []
92
92
  files:
93
93
  - ".gitignore"
94
94
  - ".travis.yml"
95
+ - CHANGELOG
95
96
  - Gemfile
96
97
  - LICENSE.txt
97
98
  - README.md
@@ -99,11 +100,9 @@ files:
99
100
  - exe/gestio2masq
100
101
  - gestio2masq.gemspec
101
102
  - lib/gestio2masq.rb
102
- - lib/gestio2masq/CHANGELOG
103
- - lib/gestio2masq/LICENSE.txt
104
103
  - lib/gestio2masq/examples/gestio2masq.conf
105
104
  - lib/gestio2masq/version.rb
106
- homepage: http://github.com/svdasein/gestio2masq
105
+ homepage: http://gitlab.com/svdasein/gestio2masq
107
106
  licenses:
108
107
  - MIT
109
108
  metadata:
@@ -125,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  version: '0'
126
125
  requirements: []
127
126
  rubyforge_project:
128
- rubygems_version: 2.4.6
127
+ rubygems_version: 2.6.11
129
128
  signing_key:
130
129
  specification_version: 4
131
130
  summary: Executable that generates DNSmasq conifguration files from Gestioip data
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 David A. Parker
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.