commit ab78b5e144a801bd5e3e477603cd1c6176d9abde Author: Abhay Rana Date: Sat Aug 22 17:50:03 2015 +0530 Initial commit :bom: diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9b948ef --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..8288a4d --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" +ruby '2.2.2' + +gem 'sinatra' +gem 'minitest' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..1284596 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b289b9e --- /dev/null +++ b/README.md @@ -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/). \ No newline at end of file diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..ac08459 --- /dev/null +++ b/config.yml @@ -0,0 +1,4 @@ +301: + github.captnemo.in: https://github.com/captn3m0 +302: + fb.captnemo.in: https://facebook.com/captn3m0 \ No newline at end of file diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..971f3ad --- /dev/null +++ b/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 \ No newline at end of file