sheepsafe 0.2.5 → 0.2.6
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/History.txt +6 -0
- data/lib/sheepsafe/config.rb +7 -0
- data/lib/sheepsafe/controller.rb +36 -7
- data/lib/sheepsafe.rb +1 -1
- data/sheepsafe.gemspec +2 -2
- data/spec/sheepsafe_spec.rb +17 -0
- metadata +4 -4
data/History.txt
CHANGED
data/lib/sheepsafe/config.rb
CHANGED
data/lib/sheepsafe/controller.rb
CHANGED
@@ -9,22 +9,37 @@ module Sheepsafe
|
|
9
9
|
class Controller
|
10
10
|
LOG_FILE = Sheepsafe::Config::FILE.sub(/\.yml/, '.log')
|
11
11
|
|
12
|
+
class TeeStdout
|
13
|
+
def initialize(controller)
|
14
|
+
@stdout, @controller = $stdout, controller
|
15
|
+
end
|
16
|
+
|
17
|
+
def write(*args,&block)
|
18
|
+
@stdout.write(*args, &block)
|
19
|
+
@controller.with_log_file {|f| f.write(*args, &block) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(meth, *args, &block)
|
23
|
+
@stdout.send(meth, *args, &block)
|
24
|
+
@controller.with_log_file {|f| f.send(meth, *args, &block) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
12
28
|
def initialize(config = nil, network = nil, logger = nil)
|
13
29
|
@config = config || Sheepsafe::Config.new
|
14
30
|
@network = network || Sheepsafe::Network.new(@config)
|
15
|
-
@logger = logger
|
16
|
-
|
17
|
-
Logger.new(STDOUT)
|
18
|
-
end
|
31
|
+
@logger = logger
|
32
|
+
$stdout = TeeStdout.new(self)
|
19
33
|
end
|
20
34
|
|
21
35
|
def run
|
36
|
+
log("Sheepsafe starting")
|
37
|
+
|
22
38
|
if ARGV.first == 'proxy' # 'sheepsafe proxy up/down/kick'
|
23
39
|
bring_socks_proxy ARGV[1]
|
24
40
|
return
|
25
41
|
end
|
26
42
|
|
27
|
-
log("Sheepsafe starting")
|
28
43
|
if network_up?
|
29
44
|
if network_changed?
|
30
45
|
if switch_to_trusted?
|
@@ -88,11 +103,17 @@ module Sheepsafe
|
|
88
103
|
exit 0
|
89
104
|
end
|
90
105
|
sleep 2 # wait a bit before starting proxy
|
106
|
+
exit_count = 0
|
107
|
+
ssh_command = "ssh #{@config.ssh_args}"
|
91
108
|
loop do
|
92
109
|
pid = fork do
|
93
|
-
exec(
|
110
|
+
exec(ssh_command)
|
94
111
|
end
|
95
112
|
Process.waitpid(pid)
|
113
|
+
exit_count += 1
|
114
|
+
if exit_count % 2 == 1 && exit_count < 10
|
115
|
+
log "command exited #{exit_count} times:\n#{}\nlast time with #{$?.exitstatus}"
|
116
|
+
end
|
96
117
|
sleep 1
|
97
118
|
end
|
98
119
|
end
|
@@ -117,7 +138,15 @@ module Sheepsafe
|
|
117
138
|
end
|
118
139
|
|
119
140
|
def log(msg)
|
120
|
-
@logger
|
141
|
+
if @logger
|
142
|
+
@logger.info(msg)
|
143
|
+
else
|
144
|
+
with_log_file {|f| Logger.new(f).info(msg) }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def with_log_file(&block)
|
149
|
+
File.open(LOG_FILE, (File::WRONLY | File::APPEND), &block)
|
121
150
|
end
|
122
151
|
end
|
123
152
|
end
|
data/lib/sheepsafe.rb
CHANGED
data/sheepsafe.gemspec
CHANGED
data/spec/sheepsafe_spec.rb
CHANGED
@@ -104,6 +104,23 @@ describe Sheepsafe::Controller do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
describe Sheepsafe::Config, "#ssh_args" do
|
108
|
+
let(:config) { Sheepsafe::Config.new({"ssh_host" => "dummyhost", "socks_port" => "1234"}) }
|
109
|
+
|
110
|
+
it "should include -ND socks_port with SOCKS proxy port" do
|
111
|
+
config.ssh_args.should =~ /-ND 1234/
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not include -p ssh_port if none is specified" do
|
115
|
+
config.ssh_args.should == "-ND 1234 dummyhost"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should include -p ssh_port if present" do
|
119
|
+
config.ssh_port = "2323"
|
120
|
+
config.ssh_args.should == "-p 2323 -ND 1234 dummyhost"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
107
124
|
describe Sheepsafe::Network do
|
108
125
|
let(:current_network) { Sheepsafe::Network.new }
|
109
126
|
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nick Sieger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-31 00:00:00 -06:00
|
19
19
|
default_executable: sheepsafe
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|