Class: TBM::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/TBM/machine.rb

Overview

The “Machine” class does all the actual interaction with SSH to perform the tunneling.

Instance Method Summary collapse

Constructor Details

#initialize(targets) ⇒ Machine

Initialize the Machine with a set of tunnels to bore

Parameters:

  • tunnels (Array<Target>)

    the tunnels to be bored



11
12
13
# File 'lib/TBM/machine.rb', line 11

def initialize( targets )
  @targets = targets
end

Instance Method Details

#boreObject

Open a connection to the gateway server, and then set up (bore) any tunnels specified in the initialize method.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/TBM/machine.rb', line 17

def bore
  puts "Starting #{APP_NAME} v#{VERSION}"
  puts

  trap("INT") { @cancelled = true }
  host = @targets.first.host
  username = @targets.first.username
  Net::SSH.start( host, username ) do |session|
    puts "Opened connection to #{username}@#{host}:"
    forward_ports( session )
  end

  puts "Shutting down the machine."
rescue Errno::ECONNRESET
  puts "\nConnection lost (reset). Shutting down the machine."
rescue Errno::ETIMEDOUT
  puts "\nConnection lost (timed out). Shutting down the machine."
rescue Errno::EADDRINUSE
  puts "\tPorts already in use, cannot forward.\n\nShutting down the machine."
rescue Errno::EACCES
  puts "\tCould not open all ports; you may need to sudo if port < 1000."
end