masquito 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -24
- data/bin/masquito +11 -10
- data/config/com.evrone.masquito.plist.erb +8 -4
- data/config/masquito.erb +2 -1
- data/lib/masquito.rb +16 -5
- data/lib/masquito/{dns.rb → daemon.rb} +30 -8
- data/lib/masquito/installer.rb +73 -0
- data/lib/masquito/resolver.rb +42 -0
- data/lib/masquito/settings.rb +1 -1
- data/lib/masquito/version.rb +1 -1
- data/masquito.gemspec +5 -3
- data/test/{dns_test.rb → daemon_test.rb} +3 -5
- metadata +23 -8
- data/lib/masquito/install.rb +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd255a71a9aef95f8d300b2e9ba3aa1930ba541
|
4
|
+
data.tar.gz: ecbec6a6cb3a3c04b20a9bf9de381067e09ca33c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6374cff380b5836a521175d216d48fa69eb1dfa640086b341278097e853c4b0afbbddd829cb6fd6b7d169400f396fdd84756db2deec6b83dbd2abb24f65a8eea
|
7
|
+
data.tar.gz: 8c2bc34be59a1b6b1df55dd4a250d8c88b8f090f912a78c567713bba7b67f9a0864c73132491f7e4c028db381a65ca81c7e311421f5eb75095259c830a032fef
|
data/README.md
CHANGED
@@ -1,51 +1,53 @@
|
|
1
1
|
# Masquito
|
2
2
|
|
3
3
|
This gem is for DNS masquerading for rubists. Everyone knows `Pow`, but what
|
4
|
-
I really don't like that it uses `node.js` to run
|
4
|
+
I really don't like that it uses `node.js` to run Ruby applications. Sometimes
|
5
5
|
we have to run our apps on the certain domain. Masquito allows you to do it,
|
6
6
|
you can create dns records in the similar Pow's way by creating symbolic links
|
7
|
-
to your apps or just files in `.masquito` directory.
|
8
|
-
|
7
|
+
to your apps or just empty files in `.masquito` directory.
|
9
8
|
## Notice:
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
Symbolic links were used by Pow in order to refer your application that will be
|
11
|
+
run automatically, since Masquito doesn't run applications and does just DNS
|
12
|
+
masquerading it's simplier to create just empty files. Check out another gem
|
13
|
+
[https://github.com/route/pump](https://github.com/route/pump) for full Pow's
|
14
|
+
replacement.
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
18
18
|
First of all, uninstall Pow if you have it installed.
|
19
|
-
I suppose you're on rbenv(
|
19
|
+
I suppose you're on rbenv (honestly I haven't checked rvm support).
|
20
20
|
|
21
21
|
Install gem:
|
22
22
|
|
23
23
|
$ gem install masquito
|
24
|
+
$ rbenv rehash
|
24
25
|
|
25
|
-
Run
|
26
|
+
Run this:
|
26
27
|
|
27
|
-
$ masquito
|
28
|
-
$ sudo masquito resolver install
|
28
|
+
$ sudo masquito install
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
for `.dev` domain. You have to run it with sudo because we must write config to
|
34
|
-
`/etc/resolver` path.
|
30
|
+
This command installs masquito server as a daemon that your system will start
|
31
|
+
every boot. This daemon will respond on DNS queries from your system and monitor
|
32
|
+
`~/.masquito` directory for newly created domains.
|
35
33
|
|
36
34
|
## Usage
|
37
35
|
|
38
36
|
Once you have installed masquito you can add domains to ~/.masquito
|
39
37
|
|
40
38
|
$ cd ~/.masquito
|
41
|
-
$ touch
|
39
|
+
$ touch yoursite.com
|
40
|
+
|
41
|
+
It will create for you `yoursite.com` domain with the wild card for all
|
42
|
+
subdomains and you can already ping and use it for the development.
|
42
43
|
|
43
|
-
|
44
|
+
$ ping yoursite.com
|
45
|
+
PING yoursite.com (127.0.0.1): 56 data bytes
|
46
|
+
64 bytes from 127.0.0.1: icmp_seq=0 ttl=53 time=1 ms
|
44
47
|
|
45
|
-
|
48
|
+
$ ping host.sub.yoursite.com
|
49
|
+
PING host.sub.yoursite.com (127.0.0.1): 56 data bytes
|
50
|
+
64 bytes from 127.0.0.1: icmp_seq=0 ttl=53 time=1 ms
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
50
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
-
5. Create new Pull Request
|
52
|
+
Run your favorite application server manually, open up your browser and fill in
|
53
|
+
address with port, that's all.
|
data/bin/masquito
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
lib = File.expand_path('../../lib', __FILE__)
|
4
|
+
$:.unshift(lib) unless $:.include?(lib)
|
5
|
+
|
4
6
|
require 'masquito'
|
5
7
|
|
6
8
|
abort 'Works only on Mac OS X' if RUBY_PLATFORM !~ /darwin/
|
7
9
|
|
8
10
|
command = ARGV[0]
|
9
|
-
subcommand = ARGV[1]
|
10
11
|
filename = File.basename(__FILE__)
|
12
|
+
options = %w(install remove version)
|
11
13
|
|
12
14
|
case command
|
13
15
|
when 'start'
|
14
|
-
Masquito::
|
15
|
-
|
16
|
-
|
17
|
-
unless
|
18
|
-
|
19
|
-
|
20
|
-
Masquito::Install.send("#{command}_#{subcommand}")
|
16
|
+
daemon = Masquito::Daemon.new
|
17
|
+
daemon.start
|
18
|
+
when /install|remove/
|
19
|
+
abort "Run: sudo #{filename} #{command}" unless Process.euid == 0
|
20
|
+
installer = Masquito::Installer.new
|
21
|
+
installer.send(command)
|
21
22
|
when 'version'
|
22
23
|
puts Masquito::VERSION
|
23
24
|
else
|
24
|
-
puts "Usage: #{filename} #{
|
25
|
+
puts "Usage: #{filename} #{options.join(' | ')}"
|
25
26
|
end
|
@@ -6,11 +6,15 @@
|
|
6
6
|
<string>com.evrone.masquito</string>
|
7
7
|
<key>ProgramArguments</key>
|
8
8
|
<array>
|
9
|
-
<string
|
10
|
-
<string
|
11
|
-
<string
|
12
|
-
<string>$SHELL --login -c "<%= masquito_bin %> start"</string>
|
9
|
+
<string><%= RbConfig.ruby %></string>
|
10
|
+
<string><%= ::Masquito::BIN %></string>
|
11
|
+
<string>start</string>
|
13
12
|
</array>
|
13
|
+
<key>EnvironmentVariables</key>
|
14
|
+
<dict>
|
15
|
+
<key>CONFIG_PATH</key>
|
16
|
+
<string><%= ::Masquito::CONFIG_PATH %></string>
|
17
|
+
</dict>
|
14
18
|
<key>KeepAlive</key>
|
15
19
|
<true/>
|
16
20
|
<key>RunAtLoad</key>
|
data/config/masquito.erb
CHANGED
data/lib/masquito.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'pathname'
|
5
|
+
|
1
6
|
module Masquito
|
2
|
-
|
7
|
+
# When user installs Masquito we use his home path, but when it's launched as
|
8
|
+
# daemon with superuser rights there's no home directory at all. That's why
|
9
|
+
# we set environment variable and rely on it.
|
10
|
+
CONFIG_PATH = ENV['CONFIG_PATH'] || File.join(ENV['HOME'], '.masquito')
|
11
|
+
GEM_PATH = File.expand_path('../../', __FILE__)
|
12
|
+
BIN = File.join(GEM_PATH, 'bin', 'masquito')
|
3
13
|
|
4
|
-
autoload :
|
5
|
-
autoload :Settings,
|
6
|
-
autoload :
|
7
|
-
autoload :
|
14
|
+
autoload :Daemon, 'masquito/daemon'
|
15
|
+
autoload :Settings, 'masquito/settings'
|
16
|
+
autoload :Resolver, 'masquito/resolver'
|
17
|
+
autoload :Installer, 'masquito/installer'
|
18
|
+
autoload :VERSION, 'masquito/version'
|
8
19
|
end
|
@@ -2,7 +2,7 @@ require 'socket'
|
|
2
2
|
require 'resolv'
|
3
3
|
|
4
4
|
module Masquito
|
5
|
-
class
|
5
|
+
class Daemon
|
6
6
|
ADDRESS = '127.0.0.1'
|
7
7
|
PORT = 53532
|
8
8
|
|
@@ -12,27 +12,49 @@ module Masquito
|
|
12
12
|
}
|
13
13
|
@@ttl = 10800 # 3 hours
|
14
14
|
|
15
|
-
def initialize(
|
16
|
-
|
17
|
-
@settings =
|
15
|
+
def initialize(config_path = CONFIG_PATH, addr = ADDRESS, port = PORT)
|
16
|
+
@addr, @port = addr, port
|
17
|
+
@settings = Settings.new(config_path)
|
18
|
+
@resolver = Resolver.new(config_path)
|
19
|
+
at_exit { stop }
|
20
|
+
end
|
21
|
+
|
22
|
+
def start
|
23
|
+
start_resolver
|
24
|
+
start_dns_server
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_resolver
|
28
|
+
@resolver_thread = Thread.new { @resolver.start }
|
29
|
+
end
|
30
|
+
|
31
|
+
def start_dns_server
|
32
|
+
puts "Starting Masquito on #{@addr}:#{@port}"
|
18
33
|
|
19
34
|
# Bind port to receive requests
|
20
|
-
socket = UDPSocket.new
|
21
|
-
socket.bind(addr, port)
|
35
|
+
@socket = UDPSocket.new
|
36
|
+
@socket.bind(@addr, @port)
|
22
37
|
|
23
38
|
loop do
|
24
39
|
# Receive and parse query
|
25
|
-
data, sender_addrinfo = socket.recvfrom(512)
|
40
|
+
data, sender_addrinfo = @socket.recvfrom(512)
|
26
41
|
|
27
42
|
Thread.new(data, sender_addrinfo) do |data, sender_addrinfo|
|
28
43
|
sender_port, sender_ip = sender_addrinfo[1], sender_addrinfo[2]
|
29
44
|
query = Resolv::DNS::Message.decode(data)
|
30
45
|
answer = setup_answer(query)
|
31
|
-
socket.send(answer.encode, 0, sender_ip, sender_port) # Send the response
|
46
|
+
@socket.send(answer.encode, 0, sender_ip, sender_port) # Send the response
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
35
50
|
|
51
|
+
def stop
|
52
|
+
@resolver_thread && (@resolver_thread.join(0.5) || @resolver_thread.kill)
|
53
|
+
@resolver.remove_configs
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
36
58
|
# Setup answer
|
37
59
|
def setup_answer(query)
|
38
60
|
# Standard fields
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'lunchy'
|
2
|
+
|
3
|
+
# Lunchy doesn't have uninstall method and also installs all plists to
|
4
|
+
# LaunchAgents. We can send a PR on spare time.
|
5
|
+
class Lunchy
|
6
|
+
CONFIG = { :verbose => false, :write => nil }
|
7
|
+
|
8
|
+
def install(params)
|
9
|
+
raise ArgumentError, "install [file]" if params.empty?
|
10
|
+
filename = params[0]
|
11
|
+
%w(/Library/LaunchDaemons).each do |dir|
|
12
|
+
if File.exist?(File.expand_path(dir))
|
13
|
+
FileUtils.cp filename, File.join(File.expand_path(dir), File.basename(filename))
|
14
|
+
return puts "#{filename} installed to #{dir}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def uninstall(params)
|
20
|
+
raise ArgumentError, "uninstall [file]" if params.empty?
|
21
|
+
filename = params[0]
|
22
|
+
%w(/Library/LaunchDaemons).each do |dir|
|
23
|
+
if File.exist?(File.expand_path(dir))
|
24
|
+
FileUtils.rm_rf(File.join(File.expand_path(dir), File.basename(filename)))
|
25
|
+
return puts "#{filename} removed from #{dir}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module Masquito
|
32
|
+
class Installer
|
33
|
+
SERVICE_NAME = 'com.evrone.masquito'
|
34
|
+
SERVICE_PLIST = "#{SERVICE_NAME}.plist"
|
35
|
+
SERVICE_TEMPLATE_PATH = File.join(GEM_PATH, 'config', "#{SERVICE_PLIST}.erb")
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@lunchy = Lunchy.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def install
|
42
|
+
switch_privileges {
|
43
|
+
FileUtils.mkdir_p(CONFIG_PATH)
|
44
|
+
}
|
45
|
+
|
46
|
+
plist = ERB.new File.read(SERVICE_TEMPLATE_PATH)
|
47
|
+
template = plist.result(binding)
|
48
|
+
|
49
|
+
filename = File.join(Dir.tmpdir, SERVICE_PLIST)
|
50
|
+
File.open(filename, 'w') { |f| f.write(template) }
|
51
|
+
@lunchy.install([filename])
|
52
|
+
@lunchy.start([SERVICE_NAME])
|
53
|
+
File.unlink(filename)
|
54
|
+
|
55
|
+
puts "Daemon was successfully installed."
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove
|
59
|
+
@lunchy.stop([SERVICE_NAME])
|
60
|
+
@lunchy.uninstall([SERVICE_PLIST])
|
61
|
+
puts "You can remove #{CONFIG_PATH} if you don't need these settings"
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def switch_privileges(&block)
|
67
|
+
uid, Process.uid = Process.uid, ENV['SUDO_UID'].to_i
|
68
|
+
Process::UID.switch(&block)
|
69
|
+
ensure
|
70
|
+
Process.uid = uid
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rb-fsevent'
|
2
|
+
|
3
|
+
module Masquito
|
4
|
+
class Resolver
|
5
|
+
RESOLVER_TEMPLATE_PATH = File.join(GEM_PATH, 'config', 'masquito.erb')
|
6
|
+
RESOLVERS_PATH = Pathname.new('/etc/resolver')
|
7
|
+
|
8
|
+
def initialize(config_path)
|
9
|
+
@config_path = config_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def start
|
13
|
+
reset
|
14
|
+
fsevent = FSEvent.new
|
15
|
+
fsevent.watch(@config_path) { reset }
|
16
|
+
fsevent.run
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
remove_configs
|
21
|
+
copy_configs
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_configs
|
25
|
+
resolver = ERB.new File.read(RESOLVER_TEMPLATE_PATH)
|
26
|
+
template = resolver.result(binding)
|
27
|
+
Masquito::Settings.new(CONFIG_PATH).domains.each do |domain|
|
28
|
+
File.open(RESOLVERS_PATH.join(domain.to_s), 'w') { |f| f.write(template) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_configs
|
33
|
+
Dir.foreach(RESOLVERS_PATH) do |name|
|
34
|
+
next if name == '.' or name == '..'
|
35
|
+
path = RESOLVERS_PATH.join(name)
|
36
|
+
if File.new(path).readline == %Q(# Masquito magic comment\n)
|
37
|
+
FileUtils.rm_rf(path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/masquito/settings.rb
CHANGED
data/lib/masquito/version.rb
CHANGED
data/masquito.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
|
2
|
+
$:.unshift(lib) unless $:.include?(lib)
|
3
|
+
|
3
4
|
require 'masquito/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |gem|
|
@@ -7,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
7
8
|
gem.version = Masquito::VERSION
|
8
9
|
gem.authors = ['Dmitry Vorotilin', 'Kir Shatrov']
|
9
10
|
gem.email = ['d.vorotilin@gmail.com', 'kirs@evrone.ru']
|
10
|
-
gem.description = 'Masquito is a
|
11
|
-
gem.summary = '
|
11
|
+
gem.description = 'Masquito is a DNS masquerading server for rubists and their applications'
|
12
|
+
gem.summary = 'Masquerades DNS records'
|
12
13
|
gem.homepage = 'https://github.com/evrone/masquito'
|
13
14
|
|
14
15
|
gem.files = `git ls-files`.split($\)
|
@@ -17,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
17
18
|
gem.require_paths = ['lib']
|
18
19
|
|
19
20
|
gem.add_runtime_dependency 'lunchy'
|
21
|
+
gem.add_runtime_dependency 'rb-fsevent'
|
20
22
|
|
21
23
|
gem.add_development_dependency 'rake'
|
22
24
|
end
|
@@ -4,20 +4,20 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
require 'masquito'
|
6
6
|
|
7
|
-
class
|
7
|
+
class TestMasquitoDaemon < Test::Unit::TestCase
|
8
8
|
TEMP_DIR = File.join(Dir.pwd, 'test/tmp')
|
9
9
|
|
10
10
|
def setup
|
11
11
|
FileUtils.mkdir_p(TEMP_DIR)
|
12
12
|
|
13
13
|
file = File.new(File.join(TEMP_DIR, 'file'), 'w')
|
14
|
-
['
|
14
|
+
['symlink.dev', 'symlink.domain'].each do |name|
|
15
15
|
symlink = File.join(TEMP_DIR, name)
|
16
16
|
FileUtils.ln_s(file.path, symlink)
|
17
17
|
end
|
18
18
|
|
19
19
|
@thread = Thread.new do
|
20
|
-
Masquito::
|
20
|
+
Masquito::Daemon.new(TEMP_DIR, '127.0.0.1', '51234').start_dns_server
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -34,8 +34,6 @@ class TestMasquitoDNS < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
response = Resolv::IPv4.create('127.0.0.1')
|
36
36
|
Resolv::DNS.open(:nameserver => ['127.0.0.1']) do |dns|
|
37
|
-
assert_equal response, dns.getaddress('link.dev.')
|
38
|
-
assert_equal response, dns.getaddress('sym.sym.link.dev.')
|
39
37
|
assert_equal response, dns.getaddress('symlink.dev.')
|
40
38
|
assert_equal response, dns.getaddress('www.symlink.dev.')
|
41
39
|
assert_equal response, dns.getaddress('symlink.domain.')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: masquito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Vorotilin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: lunchy
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rb-fsevent
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rake
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- - '>='
|
40
54
|
- !ruby/object:Gem::Version
|
41
55
|
version: '0'
|
42
|
-
description: Masquito is a
|
56
|
+
description: Masquito is a DNS masquerading server for rubists and their applications
|
43
57
|
email:
|
44
58
|
- d.vorotilin@gmail.com
|
45
59
|
- kirs@evrone.ru
|
@@ -57,12 +71,13 @@ files:
|
|
57
71
|
- config/com.evrone.masquito.plist.erb
|
58
72
|
- config/masquito.erb
|
59
73
|
- lib/masquito.rb
|
60
|
-
- lib/masquito/
|
61
|
-
- lib/masquito/
|
74
|
+
- lib/masquito/daemon.rb
|
75
|
+
- lib/masquito/installer.rb
|
76
|
+
- lib/masquito/resolver.rb
|
62
77
|
- lib/masquito/settings.rb
|
63
78
|
- lib/masquito/version.rb
|
64
79
|
- masquito.gemspec
|
65
|
-
- test/
|
80
|
+
- test/daemon_test.rb
|
66
81
|
- test/settings_test.rb
|
67
82
|
- test/test_helper.rb
|
68
83
|
homepage: https://github.com/evrone/masquito
|
@@ -87,9 +102,9 @@ rubyforge_project:
|
|
87
102
|
rubygems_version: 2.0.3
|
88
103
|
signing_key:
|
89
104
|
specification_version: 4
|
90
|
-
summary:
|
105
|
+
summary: Masquerades DNS records
|
91
106
|
test_files:
|
92
|
-
- test/
|
107
|
+
- test/daemon_test.rb
|
93
108
|
- test/settings_test.rb
|
94
109
|
- test/test_helper.rb
|
95
110
|
has_rdoc:
|
data/lib/masquito/install.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'lunchy'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'pathname'
|
6
|
-
|
7
|
-
module Masquito
|
8
|
-
GEM_PATH = File.expand_path('../../../', __FILE__)
|
9
|
-
TEMPLATE_PLIST_PATH = File.join(GEM_PATH, 'config', 'com.evrone.masquito.plist.erb')
|
10
|
-
PLIST_NAME = File.basename(TEMPLATE_PLIST_PATH, '.erb')
|
11
|
-
SERVICE_NAME = File.basename(PLIST_NAME, '.plist')
|
12
|
-
|
13
|
-
RESOLVER_TEMPLATE_PATH = File.join(GEM_PATH, 'config', 'masquito.erb')
|
14
|
-
RESOLVERS_PATH = Pathname.new('/etc/resolver')
|
15
|
-
|
16
|
-
module Install
|
17
|
-
class << self
|
18
|
-
def daemon_install
|
19
|
-
abort_if_superuser
|
20
|
-
FileUtils.mkdir_p(CONFIG_PATH)
|
21
|
-
|
22
|
-
plist = ERB.new(File.read(TEMPLATE_PLIST_PATH))
|
23
|
-
masquito_bin = File.join(GEM_PATH, 'bin', 'masquito')
|
24
|
-
template = plist.result(binding)
|
25
|
-
|
26
|
-
filename = File.join(Dir.tmpdir, PLIST_NAME)
|
27
|
-
File.open(filename, 'w') { |f| f.write(template) }
|
28
|
-
lunchy.install([filename])
|
29
|
-
lunchy.start([SERVICE_NAME])
|
30
|
-
File.unlink(filename)
|
31
|
-
|
32
|
-
puts 'Daemon was successfully installed.'
|
33
|
-
puts 'Run: sudo masquito resolver install'
|
34
|
-
end
|
35
|
-
|
36
|
-
def daemon_uninstall
|
37
|
-
abort_if_superuser
|
38
|
-
lunchy.stop([SERVICE_NAME])
|
39
|
-
lunchy.uninstall([PLIST_NAME])
|
40
|
-
puts "You can remove #{CONFIG_PATH} if you don't need these settings"
|
41
|
-
end
|
42
|
-
|
43
|
-
def resolver_install
|
44
|
-
abort_unless_superuser
|
45
|
-
resolver = ERB.new(File.read(RESOLVER_TEMPLATE_PATH))
|
46
|
-
template = resolver.result(binding)
|
47
|
-
Masquito::Settings.new.domains.each do |domain|
|
48
|
-
File.open(RESOLVERS_PATH.join(domain.to_s), 'w') { |f| f.write(template) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def resolver_uninstall
|
53
|
-
abort_unless_superuser
|
54
|
-
Masquito::Settings.new.domains.each do |domain|
|
55
|
-
FileUtils.rm_rf(RESOLVERS_PATH.join(domain.to_s))
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def lunchy
|
62
|
-
@lunchy ||= Lunchy.new
|
63
|
-
end
|
64
|
-
|
65
|
-
def abort_unless_superuser
|
66
|
-
unless superuser?
|
67
|
-
abort 'We need superuser privileges, run this command with sudo'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def abort_if_superuser
|
72
|
-
if superuser?
|
73
|
-
abort 'No need superuser privileges, run this command without sudo'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def superuser?
|
78
|
-
[Process.uid, Process.euid] == [0, 0]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class Lunchy
|
85
|
-
CONFIG = { :verbose => false, :write => nil }
|
86
|
-
|
87
|
-
def uninstall(params)
|
88
|
-
raise ArgumentError, "uninstall [file]" if params.empty?
|
89
|
-
filename = params[0]
|
90
|
-
%w(~/Library/LaunchAgents /Library/LaunchAgents).each do |dir|
|
91
|
-
if File.exist?(File.expand_path(dir))
|
92
|
-
FileUtils.rm_rf(File.join(File.expand_path(dir), File.basename(filename)))
|
93
|
-
return puts "#{filename} uninstalled from #{dir}"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|