comuna 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb8c165d1a0f3d9af514f8b083bd1099d478271c
4
+ data.tar.gz: 3519be5b45b75bbe0d909d53ecf2ecd18b549515
5
+ SHA512:
6
+ metadata.gz: 2a20266a9b47da1bb21f0f794cf0ccaa2d8888f3e53a0fe239750ec7d9101c29d6702610bae6295ddd35d386bd5b4a8a19fc8c04bf6567c3ffd9e30bda93db19
7
+ data.tar.gz: 400b3a5d4b2cdffb33d02dad608b3be121805fcdbf96002c487bf09bb0f57192f537214f1a12b56da38fe6beaef1e4ad2aa3e60a18107ed833067621679d4ad6
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in comuna.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Edgar Cabrera
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Comuna
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/comuna`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'comuna'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install comuna
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/comuna.
36
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "comuna"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'comuna/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "comuna"
8
+ spec.version = Comuna::VERSION
9
+ spec.authors = ["Edgar Cabrera"]
10
+ spec.email = ["edgar@cafeinacode.com"]
11
+ spec.licenses = ['MIT']
12
+
13
+ spec.summary = %q{Small, easy to configure DNS server for local networks.}
14
+ spec.description = %q{Leverages the power of RubyDNS and the simplicity of YAML for a simple DNS server for local networks.}
15
+ spec.homepage = "https://github.com/aleandros/comuna"
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"]
29
+
30
+ spec.add_dependency 'rubydns', '~> 1.0'
31
+ spec.add_dependency 'thor', '~> 0.19'
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.11"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'comuna/server'
3
+ require 'comuna/config'
4
+ require 'thor'
5
+
6
+ module Comuna
7
+ class ComunaCLI < Thor
8
+ desc 'server', 'Start server'
9
+ def server
10
+ config = Config.new
11
+ Server.new(config).call
12
+ end
13
+ end
14
+ end
15
+
16
+ Comuna::ComunaCLI.start(ARGV)
@@ -0,0 +1,5 @@
1
+ require "comuna/version"
2
+
3
+ module Comuna
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'yaml'
2
+
3
+ module Comuna
4
+ class Config
5
+ attr_reader :interfaces, :upstream,
6
+ :matches
7
+
8
+ def initialize
9
+ load!
10
+ end
11
+
12
+ def load!
13
+ extract_with_defaults!(parsed)
14
+ end
15
+
16
+ def raw
17
+ if File.exist?('config.yml')
18
+ File.read('config.yml')
19
+ elsif File.exist?('config.yaml')
20
+ File.read('config.yaml')
21
+ else
22
+ ''
23
+ end
24
+ end
25
+
26
+ def parsed
27
+ read = YAML.load(raw)
28
+ read.is_a?(Hash) ? read : {}
29
+ end
30
+
31
+ def extract_with_defaults!(config)
32
+ port = config.fetch('port', 5300)
33
+
34
+ @interfaces = config.fetch('interfaces', [[:udp, '0.0.0.0', port],
35
+ [:tcp, '0.0.0.0', port]])
36
+ @upstream = config.fetch('upstream', [[:udp, '8.8.8.8', 53],
37
+ [:tcp, '8.8.8.8', 53]])
38
+ @matches = config.fetch('matches', {myself: '0.0.0.0'})
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubydns'
2
+ require 'logger'
3
+
4
+ module Comuna
5
+ IN = Resolv::DNS::Resource::IN
6
+ Name = Resolv::DNS::Name
7
+
8
+ class Server
9
+ def initialize(config)
10
+ @interfaces = config.interfaces
11
+ @upstream_ifaces = config.upstream
12
+ @matches = config.matches
13
+ end
14
+
15
+ def call
16
+ matches = @matches
17
+ upstr = upstream
18
+
19
+ RubyDNS::run_server(:listen => @interfaces) do
20
+ @logger.level = Logger::INFO
21
+
22
+ matches.each do |(name, address)|
23
+ match(/#{name}/, IN::A) do |transaction|
24
+ transaction.respond!(address)
25
+ end
26
+ end
27
+
28
+ otherwise do |transaction|
29
+ transaction.passthrough!(upstr)
30
+ end
31
+ end
32
+ end
33
+
34
+ def upstream
35
+ RubyDNS::Resolver.new(@upstream_ifaces)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Comuna
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comuna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Edgar Cabrera
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubydns
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Leverages the power of RubyDNS and the simplicity of YAML for a simple
70
+ DNS server for local networks.
71
+ email:
72
+ - edgar@cafeinacode.com
73
+ executables:
74
+ - comuna
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - comuna.gemspec
86
+ - exe/comuna
87
+ - lib/comuna.rb
88
+ - lib/comuna/config.rb
89
+ - lib/comuna/server.rb
90
+ - lib/comuna/version.rb
91
+ homepage: https://github.com/aleandros/comuna
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ allowed_push_host: https://rubygems.org
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Small, easy to configure DNS server for local networks.
116
+ test_files: []
117
+ has_rdoc: