diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b35b430 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby +rvm: + - 2.2.2 +script: ruby test.rb \ No newline at end of file diff --git a/Gemfile b/Gemfile index 8288a4d..f29f606 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,11 @@ source "https://rubygems.org" ruby '2.2.2' gem 'sinatra' -gem 'minitest' \ No newline at end of file + +group :test do + gem 'minitest' +end + +group :production do + gem 'thin' +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 1284596..7f94cc3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,8 @@ GEM remote: https://rubygems.org/ specs: + daemons (1.2.3) + eventmachine (1.0.8) minitest (5.7.0) rack (1.6.4) rack-protection (1.5.3) @@ -9,6 +11,10 @@ GEM rack (~> 1.4) rack-protection (~> 1.4) tilt (>= 1.3, < 3) + thin (1.6.3) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0) + rack (~> 1.0) tilt (2.0.1) PLATFORMS @@ -17,6 +23,7 @@ PLATFORMS DEPENDENCIES minitest sinatra + thin BUNDLED WITH 1.10.5 diff --git a/README.md b/README.md index b289b9e..6915418 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lightsaber +# lightsaber [![Build Status](https://travis-ci.org/captn3m0/lightsaber.svg)](https://travis-ci.org/captn3m0/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. diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..f5966cd --- /dev/null +++ b/app.rb @@ -0,0 +1,15 @@ +require 'rubygems' +require 'bundler/setup' +require 'sinatra' +require 'yaml' + +get '/' do + hostname = request.host + YAML::load_file('redirects.yml').each do |code, zone| + if zone.has_key? hostname + redirect zone[hostname], code + end + end + + halt 404, "#{hostname} hasn't been setup yet." +end \ No newline at end of file diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..1517752 --- /dev/null +++ b/config.ru @@ -0,0 +1,3 @@ +require File.expand_path '../app.rb', __FILE__ + +run Sinatra::Application \ No newline at end of file diff --git a/config.yml b/config.yml index ac08459..d89d0c1 100644 --- a/config.yml +++ b/config.yml @@ -1,4 +1,14 @@ -301: - github.captnemo.in: https://github.com/captn3m0 -302: - fb.captnemo.in: https://facebook.com/captn3m0 \ No newline at end of file +--- + environment: production + chdir: /home/lightsaber/lightsaber + address: 127.0.0.1 + user: lightsaber + group: lightsaber + port: 4567 + pid: /tmp/lightsaber.pid + rackup: /home/lightsaber/lightsaber/config.ru + log: /home/lightsaber/lightsaber/thin.log + max_conns: 1024 + timeout: 5 + max_persistent_conns: 256 + daemonize: true \ No newline at end of file diff --git a/redirects.yml b/redirects.yml new file mode 100644 index 0000000..e774c83 --- /dev/null +++ b/redirects.yml @@ -0,0 +1,6 @@ +--- +301: + github.captnemo.in: https://github.com/captn3m0 + lightsaber.captnemo.in: https://github.com/captn3m0/lightsaber +302: + fb.captnemo.in: https://facebook.com/captn3m0 \ No newline at end of file diff --git a/test.rb b/test.rb index 971f3ad..22474a8 100644 --- a/test.rb +++ b/test.rb @@ -4,14 +4,14 @@ require 'yaml' require 'pp' class TestConfig < Minitest::Test - REDIRECTS = ['301', '302'] + REDIRECTS = [301, 302] def setup - @config = YAML::load_file 'config.yml' + @config = YAML::load_file 'redirects.yml' end def test_redirect_sections - @config.each do |section, zone| - assert REDIRECTS.include? section.to_s + @config.each do |code, zone| + assert REDIRECTS.include? code end end @@ -25,7 +25,7 @@ class TestConfig < Minitest::Test end def resolves_to_lightsaber(domain) - flag = false + flag = domain === "lightsaber.captnemo.in" Resolv::DNS.open do |dns| records = dns.getresources domain, Resolv::DNS::Resource::IN::CNAME records.each do |record|