sheepsafe 0.2.3 → 0.2.4

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.
data/README.md CHANGED
@@ -49,6 +49,21 @@ but this setup Works For Me.
49
49
  - After installing the gem, run `sheepsafe install` and follow the
50
50
  prompts for configuring Sheepsafe.
51
51
 
52
+ ## Usage
53
+
54
+ - `sheepsafe`: when run with no arguments, this checks your current
55
+ network and updates settings if necessary.
56
+ - `sheepsafe install`: Run the command-line installer. Fill out the
57
+ prompts and you're ready.
58
+ - `sheepsafe update`: Run when you've upgraded the gem to make sure
59
+ launchd is running the most recent version.
60
+ - `sheepsafe add`: Add the current network to your list of trusted
61
+ networks.
62
+ - `sheepsafe list`: Show the list of trusted networks.
63
+ - `sheepsafe proxy up`: Manually start the SSH SOCKS proxy.
64
+ - `sheepsafe proxy down`: Manually stop the SSH SOCKS proxy.
65
+ - `sheepsafe proxy kick`: Manually restart the SSH SOCKS proxy.
66
+
52
67
  ## Growl
53
68
 
54
69
  If you wish to receive Growl notifications when Sheepsafe is switching
@@ -19,7 +19,7 @@ module Sheepsafe
19
19
  end
20
20
 
21
21
  def run
22
- if ARGV.first == 'proxy' # 'sheepsafe proxy up/down'
22
+ if ARGV.first == 'proxy' # 'sheepsafe proxy up/down/kick'
23
23
  bring_socks_proxy ARGV[1]
24
24
  return
25
25
  end
@@ -32,16 +32,24 @@ module Sheepsafe
32
32
  system "scselect #{@config.trusted_location}"
33
33
  bring_socks_proxy 'down'
34
34
  elsif switch_to_untrusted?
35
+ notified = false
36
+ loop do
37
+ require 'open-uri'
38
+ length = open("http://example.com") {|f| f.meta['content-length'] } rescue nil
39
+ break if length == "596" # successful contact w/ example.com
40
+ notify_warning("Waiting for internet connection before switching") unless notified
41
+ notified = true
42
+ sleep 5
43
+ end
35
44
  notify_warning "Switching to #{@config.untrusted_location} location"
36
- bring_socks_proxy 'up'
37
45
  system "scselect #{@config.untrusted_location}"
46
+ bring_socks_proxy 'up'
38
47
  end
39
48
  @config.last_network = @network
40
49
  @config.write
41
50
  elsif !@network.trusted?
42
51
  # recycle the proxy server on network changes
43
- bring_socks_proxy 'down'
44
- bring_socks_proxy 'up'
52
+ bring_socks_proxy 'restart'
45
53
  end
46
54
  else
47
55
  log("AirPort is off")
@@ -66,7 +74,14 @@ module Sheepsafe
66
74
  end
67
75
 
68
76
  def bring_socks_proxy(direction)
69
- Daemons.run_proc '.sheepsafe.proxy', :ARGV => [direction == 'up' ? 'start' : 'stop'], :dir_mode => :normal, :dir => ENV['HOME'] do
77
+ cmd = case direction
78
+ when 'up' then 'start'
79
+ when 'down' then 'stop'
80
+ when 'kick' then 'restart'
81
+ else
82
+ direction
83
+ end
84
+ Daemons.run_proc('.sheepsafe.proxy', :ARGV => [cmd], :dir_mode => :normal, :dir => ENV['HOME']) do
70
85
  pid = nil
71
86
  trap("TERM") do
72
87
  Process.kill("TERM", pid)
@@ -76,14 +91,14 @@ module Sheepsafe
76
91
  pid = fork do
77
92
  exec("ssh -ND #{@config.socks_port} #{@config.ssh_host}")
78
93
  end
79
- Process.waitpid(pid, 0)
94
+ Process.waitpid(pid)
80
95
  sleep 1
81
96
  end
82
97
  end
83
98
  end
84
99
 
85
100
  def proxy_running?
86
- File.exist?("#{ENV['HOME']}/.sheepsafe.proxy.pid")
101
+ File.exist?("#{ENV['HOME']}/.sheepsafe.proxy.pid") && File.read("#{ENV['HOME']}/.sheepsafe.proxy.pid").to_i > 0
87
102
  end
88
103
 
89
104
  def notify_ok(msg)
@@ -79,6 +79,7 @@ MSG
79
79
  # For details see http://tech.inhelsinki.nl/locationchanger/
80
80
  def write_launchd_plist
81
81
  say "Setting up launchd configuration file #{PLIST_FILE}..."
82
+ Dir.mkdir(File.dirname(PLIST_FILE)) unless File.directory?(File.dirname(PLIST_FILE))
82
83
  plist = <<-PLIST
83
84
  <?xml version="1.0" encoding="UTF-8"?>
84
85
  <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
@@ -138,6 +139,23 @@ PLIST
138
139
  register_launchd_task
139
140
  end
140
141
 
142
+ def add
143
+ @config.trusted_names << @network.ssid
144
+ @config.last_network = nil
145
+ say "Adding #{config.trusted_names[num]} to your trusted locations"
146
+ write_config
147
+ @controller.run
148
+ end
149
+
150
+ def list
151
+ say "Currently trusted locations:"
152
+ puts @config.trusted_names
153
+ end
154
+
155
+ #
156
+ # Needed? Remove current network from trusted
157
+ #
158
+
141
159
  private
142
160
  def update_config_with_network
143
161
  unless config.trusted_location
data/lib/sheepsafe.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Sheepsafe
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
4
4
 
5
5
  require 'sheepsafe/config'
data/sheepsafe.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sheepsafe'
5
- s.version = '0.2.3'
5
+ s.version = '0.2.4'
6
6
  s.date = '2010-11-09'
7
7
 
8
8
  s.rubyforge_project = %q{caldersphere}
@@ -58,8 +58,7 @@ describe Sheepsafe::Controller do
58
58
 
59
59
  it "recycles the proxy server process when on the untrusted network" do
60
60
  network.stub :trusted? => false
61
- controller.should_receive(:bring_socks_proxy).with('down').ordered
62
- controller.should_receive(:bring_socks_proxy).with('up').ordered
61
+ controller.should_receive(:bring_socks_proxy).with('restart')
63
62
  controller.run
64
63
  end
65
64
  end
@@ -94,8 +93,9 @@ describe Sheepsafe::Controller do
94
93
  end
95
94
 
96
95
  context "to untrusted" do
97
- it "changes to the untrusted location" do
96
+ it "changes to the untrusted location after connecting to example.com" do
98
97
  controller.should_receive(:switch_to_untrusted?).and_return true
98
+ controller.should_receive(:open).and_return("596")
99
99
  controller.should_receive(:system).with("scselect untrusted_location")
100
100
  controller.should_receive(:bring_socks_proxy).with('up')
101
101
  controller.run
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheepsafe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Sieger