Explain the ./localtunnel_callback hook in the banner and execute CWD/.localtunnel_callback if it exists

This commit is contained in:
Lin Xu 2012-02-21 06:16:54 -08:00
parent aa6248ff72
commit 331bff9991
2 changed files with 8 additions and 3 deletions

View File

@ -28,7 +28,12 @@ require 'localtunnel'
key = nil
options = OptionParser.new do |o|
o.banner = "Usage: localtunnel [options] <localport>"
o.banner =
"Usage: localtunnel [options] <localport>\n\n" +
"The file .localtunnel_callback, if it exists in the current working directory,\n"+
"will be executed with the tunnel endpoint as the first argument once the \n" +
"tunnel is started\n\n"
o.on("-k", "--key FILE", "upload a public key for authentication") do |k|
key = File.exist?(k.to_s) ? File.open(k).read : nil
end
@ -44,4 +49,4 @@ end
t = LocalTunnel::Tunnel.new(local_port, key)
t.register_tunnel
t.start_tunnel
t.start_tunnel

View File

@ -47,7 +47,7 @@ class LocalTunnel::Tunnel
gateway.open_remote(port.to_i, '127.0.0.1', tunnel['through_port'].to_i) do |rp,rh|
puts " " << tunnel['banner'] if tunnel.has_key? 'banner'
if File.exists?(File.expand_path(SHELL_HOOK_FILE))
system "#{SHELL_HOOK_FILE} ""#{tunnel['host']}""" if File.exists?(File.expand_path(SHELL_HOOK_FILE))
system "#{File.expand_path(SHELL_HOOK_FILE)} ""#{tunnel['host']}"""
if !$?.success?
puts " An error occurred executing the callback hook #{SHELL_HOOK_FILE}"
puts " (Make sure it is executable)"