Skip to content
Permalink
Browse files

Initial commit :bom:

  • Loading branch information...
captn3m0 committed Aug 22, 2015
0 parents commit ab78b5e144a801bd5e3e477603cd1c6176d9abde
Showing with 104 additions and 0 deletions.
  1. +12 −0 .editorconfig
  2. +5 −0 Gemfile
  3. +22 −0 Gemfile.lock
  4. +24 −0 README.md
  5. +4 −0 config.yml
  6. +37 −0 test.rb
@@ -0,0 +1,12 @@
root = true

[*]
# Extensions we have: coffee, js, yml, json
# and follow same settings for all of these
charset = "utf8"
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
@@ -0,0 +1,5 @@
source "https://rubygems.org"
ruby '2.2.2'

gem 'sinatra'
gem 'minitest'
@@ -0,0 +1,22 @@
GEM
remote: https://rubygems.org/
specs:
minitest (5.7.0)
rack (1.6.4)
rack-protection (1.5.3)
rack
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
tilt (2.0.1)

PLATFORMS
ruby

DEPENDENCIES
minitest
sinatra

BUNDLED WITH
1.10.5
@@ -0,0 +1,24 @@
# lightsaber

Lightsaber is a simple DNS Redirect service. It offers 301/302 redirects for
your domains. The configuration is kept public on this github repository itself.

## Usage

To add a DNS record, point your domain via a CNAME entry to `lightsaber.captnemo.in`.

Next, you will need to do the following:

1. Fork this repo
2. Edit the config.yml file and add your redirect in the relevant section
3. File a Pull Request with your edit

Once the Pull Request is approved, the redirect will automatically be deployed
via Travis.

If you do not wish to make your domain redirects public, or give away your domain
names, you can self host this as well.

## License

Released under the [MIT License](http://nemo.mit-license.org/).
@@ -0,0 +1,4 @@
301:
github.captnemo.in: https://github.com/captn3m0
302:
fb.captnemo.in: https://facebook.com/captn3m0
37 test.rb
@@ -0,0 +1,37 @@
require 'minitest/autorun'
require 'resolv'
require 'yaml'
require 'pp'

class TestConfig < Minitest::Test
REDIRECTS = ['301', '302']
def setup
@config = YAML::load_file 'config.yml'
end

def test_redirect_sections
@config.each do |section, zone|
assert REDIRECTS.include? section.to_s
end
end

def test_each_domain
@config.each do |section, zone|
zone.each do |domain, redirect|
assert resolves_to_lightsaber(domain),
"DNS for #{domain} isn't setup yet. See README"
end
end
end

def resolves_to_lightsaber(domain)
flag = false
Resolv::DNS.open do |dns|
records = dns.getresources domain, Resolv::DNS::Resource::IN::CNAME
records.each do |record|
flag||=record.name.to_s === "lightsaber.captnemo.in"
end
end
flag
end
end

0 comments on commit ab78b5e

Please sign in to comment.
You can’t perform that action at this time.