gestio2masq 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b77c3b4e9d5e1d49e2c6cffc98155938ab09b7f2
4
+ data.tar.gz: df554ebd30c4ae3f42909b5aa3fcfcc652009c29
5
+ SHA512:
6
+ metadata.gz: d2540149179dcb5ff52d388c431fc53d509971d2e2ca4be6c26f67c745bc9d7d66722e633c526e31b50c84143c6768752addd5a45bee4063ed43f5e36dee887e
7
+ data.tar.gz: 5fd08553d7c200afba8c0b9ed6a415cb7d6cd3d50f7145d4eb4d1d39097a8058c8859f83b5e0e1598bba64c14e3e6c7add8ebbf85d7ef706ee52d6f6c4f35f3a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "mysql2"
4
+ gem "ipaddress"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 svdasein
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.
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # Gestio2masq
2
+
3
+ gestio2masq generates dnsmasq configuration files from gestioip mysql databases. Or at least, it does this
4
+ *for me*. YMMV.
5
+
6
+
7
+ ## Installation & Configuration
8
+
9
+ First, install it:
10
+
11
+ $ git clone https://github.com/svdasein/gestio2masq.git
12
+ $ cd gestio2masq
13
+ $ bundle install
14
+
15
+ or
16
+
17
+ $ gem install gestio2masq
18
+
19
+ Once installed, copy the example config file to /etc/ and edit. The config file is self documenting :->
20
+
21
+ ###gestio2masq requires some custom fields in gestioip.
22
+
23
+ You can define these via the web interface in Manage/Custom Columns.
24
+
25
+ ####Add the following _network_ fields:
26
+
27
+ ####_domain_
28
+
29
+ The domain name that will fully qualify your host names in a given network
30
+
31
+ ####_leasetime_
32
+
33
+ The static assignment lease time for this network
34
+
35
+ ####_dynleasetime_
36
+
37
+ The dynamic pool lease time for this network
38
+
39
+ ####_optiontag_
40
+
41
+ A unique dnsmasq tag string. Options for a given network will be tagged with this string in dnsmasq configuration.
42
+
43
+ ####Add the following _host_ fields:
44
+
45
+ ####_MAC_
46
+
47
+ Specify this for a host if you want to do static dhcp assignments. Format is 00:00:00:00:00:00
48
+
49
+ ####_CNAMEs_
50
+
51
+ Colon separated list of *fully qualified* cnames. e.g. host.mydomain.net:alias.myotherdomain.net
52
+
53
+ ####_optiontag_
54
+
55
+ If you want to do some custom things for particular hosts in your dnsmasq config, you can specify the tag
56
+ you used to identify that stuff here.
57
+
58
+
59
+
60
+ ### You'll also need to set up dnsmasq so that it uses the files generated by gestio2masq
61
+
62
+ gestio2masq generates the following files:
63
+
64
+ destdir/dnsmasq.d/ranges
65
+ destdir/dnsmasq.d/cnames
66
+ destdir/dnsmasq-dhcp-hosts.conf
67
+ destdir/dnsmasq-hosts.conf
68
+
69
+
70
+ The first two files will be auto-loaded if you launch dnsmasq with ```-7 destdir/dnsmasq.d```
71
+
72
+ The last two need to be pointed to explicitly in your dnsmasq.conf file.
73
+
74
+ Example:
75
+
76
+ ```
77
+ interface=eth0
78
+ no-resolv
79
+ expand-hosts
80
+ stop-dns-rebind
81
+ log-dhcp
82
+ domain=my.net
83
+ local=/my.net/
84
+ domain-needed
85
+ server=8.8.8.8
86
+ cache-size=1000
87
+ clear-on-reload
88
+ dhcp-leasefile=/var/lib/dhcp/dnsmasq.leases
89
+
90
+ #This is where you define the stuff that host optiontags map to:
91
+ #(If you don't do per-host tags this isn't required)
92
+ dhcp-optsfile=/etc/dnsmasq-dhcp-opts.conf
93
+
94
+ #generated by gestio2masq
95
+
96
+ addn-hosts=/etc/dnsmasq-hosts.conf
97
+ dhcp-hostsfile=/etc/dnsmasq-dhcp-hosts.conf
98
+ ```
99
+
100
+
101
+ ## Usage
102
+
103
+ $ gestio2masq
104
+ $ service dnsmasq restart (or equiv)
105
+
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork it ( https://github.com/[my-github-username]/gestio2masq/fork )
110
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
111
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
112
+ 4. Push to the branch (`git push origin my-new-feature`)
113
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/exe/gestio2masq ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+ require 'mysql2'
3
+ require 'ipaddress'
4
+ require 'json'
5
+
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)
12
+ end
13
+
14
+ dest_dir = config['destdir']
15
+
16
+ begin
17
+ mysql = Mysql2::Client.new(
18
+ :host => config['sqlhost'],
19
+ :username => config['sqluser'],
20
+ :password => config['sqlpass'],
21
+ :database => config['database']
22
+ )
23
+ rescue
24
+ puts %Q(Error connecting to database #{config['database']} on host #{config['sqlhost']} as #{config['sqluser']}.)
25
+ exit(status=1)
26
+ end
27
+
28
+ networks_data = mysql.query('select * from net',:symbolize_keys => true)
29
+ ranges_data = mysql.query('select * from ranges',:symbolize_keys => true)
30
+ hosts_data = mysql.query('select * from host order by hostname',:symbolize_keys => true)
31
+ hosts_xtra_data = mysql.query('select custom_host_column_entries.*,custom_host_columns.name from custom_host_column_entries,custom_host_columns where custom_host_columns.id = custom_host_column_entries.cc_id',:symbolize_keys => true)
32
+ nets_extra_data = mysql.query('select custom_net_column_entries.*,custom_net_columns.name from custom_net_column_entries,custom_net_columns where custom_net_columns.id = custom_net_column_entries.cc_id',:symbolize_keys => true)
33
+
34
+ networks = Hash.new
35
+ networks_data.each { |net|
36
+ nets_extra_data.select { |each| each[:net_id] == net[:red_num] } .each { |entry|
37
+ net[entry[:name].to_sym] = entry[:entry]
38
+ }
39
+ net[:bitmask] = IPAddress.parse("#{net[:red]}/#{net[:BM]}").netmask
40
+ networks[net[:red_num]] = net
41
+ }
42
+
43
+ ranges_entries = Array.new
44
+ ranges_data.each { |range|
45
+ network = networks[range[:red_num].to_i]
46
+ start_ip = IPAddress::IPv4.parse_u32(range[:start_ip].to_i)
47
+ end_ip = IPAddress::IPv4.parse_u32(range[:end_ip].to_i)
48
+ ranges_entries.push("dhcp-range=#{network[:optiontag]},#{start_ip},#{end_ip},#{network[:bitmask]},#{network[:dynleasetime]}")
49
+ }
50
+
51
+ hosts_entries = Array.new
52
+ dhcp_hosts_entries = Array.new
53
+ cnames_entries = Array.new
54
+ hosts_data.each { |host|
55
+ host[:ipaddress] = IPAddress::IPv4.parse_u32(host[:ip].to_i)
56
+ hosts_xtra_data.select { |each| each[:host_id] == host[:id] } .each { |entry|
57
+ host[entry[:name].to_sym] = entry[:entry]
58
+ }
59
+ host[:network] = networks[host[:red_num]]
60
+ if host[:hostname].size > 0
61
+ if host[:MAC]
62
+ # static dhcp assignment
63
+ if host[:optiontag]
64
+ dhcp_hosts_entries.push("#{host[:MAC]},set:#{host[:optiontag]},#{host[:hostname].split('.').shift},#{host[:ipaddress]},#{host[:network][:leasetime]}")
65
+ else
66
+ dhcp_hosts_entries.push("#{host[:MAC]},#{host[:hostname].split('.').shift},#{host[:ipaddress]},#{host[:network][:leasetime]}")
67
+ end
68
+ end
69
+ # hostname
70
+ hosts_entries.push("#{host[:ipaddress]}\t#{host[:hostname]}.#{host[:network][:domain]}")
71
+ if host[:CNAMEs]
72
+ host[:CNAMEs].split(':').each { |cname|
73
+ cnames_entries.push("cname=#{cname},#{host[:hostname]}.#{host[:network][:domain]}")
74
+ }
75
+ end
76
+ end
77
+ }
78
+ puts "="*80
79
+ puts "RANGES"
80
+ File.new(%Q(#{dest_dir}/dnsmasq.d/ranges),'w').puts(ranges_entries.join("\n"))
81
+ puts(ranges_entries.join("\n"))
82
+ puts "="*80
83
+ puts "CNAMES"
84
+ File.new(%Q(#{dest_dir}/dnsmasq.d/cnames),'w').puts(cnames_entries.join("\n"))
85
+ puts(cnames_entries.join("\n"))
86
+ puts "="*80
87
+ puts "DHCP HOSTS"
88
+ File.new(%Q(#{dest_dir}/dnsmasq-dhcp-hosts.conf),'w').puts(dhcp_hosts_entries.join("\n"))
89
+ puts(dhcp_hosts_entries.join("\n"))
90
+ puts "="*80
91
+ puts "HOSTS"
92
+ File.new(%Q(#{dest_dir}/dnsmasq-hosts.conf),'w').puts(hosts_entries.join("\n"))
93
+ puts(hosts_entries.join("\n"))
94
+
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gestio2masq"
7
+ spec.version = '0.0.5'
8
+ spec.authors = ["svdasein"]
9
+ spec.email = ["svdasein@github"]
10
+
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}
14
+ spec.homepage = "http://github.com/svdasein/gestio2masq"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib","bin"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.9"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "sqlhost":"<ipaddr>",
3
+ "sqluser":"<username>",
4
+ "sqlpass":"<password>",
5
+ "database":"gestioip",
6
+ "destdir":"/etc"
7
+ }
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gestio2masq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - svdasein
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-14 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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
+ 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
44
+ email:
45
+ - svdasein@github
46
+ executables:
47
+ - gestio2masq
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - ".travis.yml"
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - exe/gestio2masq
58
+ - gestio2masq.gemspec
59
+ - lib/gestio2masq/examples/gestio2masq.conf
60
+ homepage: http://github.com/svdasein/gestio2masq
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ - bin
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Executable that generates DNSmasq conifguration files from Gestioip data
86
+ test_files: []