28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'bin/pairkit', line 28
def share(*ports)
public_key = get_or_generate_ssh_key()
response = RestClient.post(SERVER_WEB + "/share",
:public_key => public_key,
:ports => ports)
share_result = J.load(response, :symbolize_keys => true)
forwarded_ports = share_result[:remote_port_forwards].collect{ |remote_port, local_port| [remote_port, local_port] }
reverse_tunnel_args = forwarded_ports.collect{ |ports| "-R #{ports[0]}:localhost:#{ports[1]}" }
setup_reverse_tunnel_cmd = "ssh -N #{reverse_tunnel_args.join(' ')} #{share_result[:ssh_user_name]}@#{share_result[:ssh_host]}"
puts "Running: #{setup_reverse_tunnel_cmd}"
pids = []
pids << Kernel.fork { `#{setup_reverse_tunnel_cmd}` }
puts "OK! We're forwarding ports as long as you keep this process running."
puts ""
forwarded_ports.each do |ports|
puts "pairkit.com:#{ports[0]} -> localhost:#{ports[1]}"
end
puts ""
puts "When you're ready to kill the port forwards, type Control+C."
trap("SIGINT") do
pids.each {|pid| Process.kill("HUP", pid) }
puts "Thank you, come again! =-)"
exit!
end
cmd = nil
while cmd != "quit" do
cmd = STDIN.gets
end
end
|