net-ssh-gateway-2.0.0/0000755000004100000410000000000013110347012014551 5ustar www-datawww-datanet-ssh-gateway-2.0.0/Rakefile0000644000004100000410000000025013110347012016213 0ustar www-datawww-datarequire "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |t| t.libs = ["lib", "test"] t.pattern = "test/**/*_test.rb" end task :default => :test net-ssh-gateway-2.0.0/Gemfile0000644000004100000410000000014413110347012016043 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in net-ssh-gateway.gemspec gemspec net-ssh-gateway-2.0.0/net-ssh-gateway.gemspec0000644000004100000410000000237013110347012021140 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'net/ssh/gateway/version' Gem::Specification.new do |spec| spec.name = "net-ssh-gateway" spec.version = Net::SSH::Gateway::VERSION spec.authors = ["Jamis Buck", "Delano Mandelbaum", "Mikl\u{f3}s Fazekas"] spec.email = ["net-ssh@solutious.com"] if ENV['NET_SSH_BUILDGEM_SIGNED'] spec.cert_chain = ["net-ssh-public_cert.pem"] spec.signing_key = "/mnt/gem/net-ssh-private_key.pem" end spec.summary = %q{A simple library to assist in establishing tunneled Net::SSH connections} spec.description = %q{A simple library to assist in establishing tunneled Net::SSH connections} spec.homepage = "https://github.com/net-ssh/net-ssh-gateway" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.10" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "minitest", "~> 5.8.4" spec.add_development_dependency "mocha", ">= 1.2.1" spec.add_runtime_dependency "net-ssh", ">= 4.0.0" end net-ssh-gateway-2.0.0/CHANGES.txt0000644000004100000410000000151413110347012016363 0ustar www-datawww-data === 2.0.0 / 26 Jan 2017 * Update net-ssh dependency to 4.0.0 which requires Ruby version >= 2.0 [delano] === 1.3.0 / 26 Jan 2017 * Fix for loop_wait option on initialization [mfazekas, tpitale] * Use bundler and remove remove jeweler [tpitale] * Use minitest instead of test/unit [tpitale] * Added Travis CI config [tpitale] === 1.2.0 / 06 Feb 2013 * Added public cert. All gem releases are now signed. See INSTALL in readme. === 1.1.0 / 30 Apr 2011 * Fix for sporadicly stalled SSH connections in Ruby 1.9 [Mat Trudel] * Decrease wait time within Net::SSH session loop [Grant Hutchins, Michael Schubert] === 1.0.1 / 1 Feb 2009 * Allow local port to be specified [Will Klancnik] === 1.0.0 / 1 May 2008 * (no changes since the preview release) === 1.0 Preview Release 1 (0.99.0) / 10 Apr 2008 * First release of Net::SSH::Gateway net-ssh-gateway-2.0.0/.ruby-version0000644000004100000410000000000613110347012017212 0ustar www-datawww-data2.2.0 net-ssh-gateway-2.0.0/data.tar.gz.sig0000444000004100000410000000040013110347012017362 0ustar www-datawww-datas(y gw\)gO/Ql²xR5"PjV"^BQ_9c͕ 3 9&7NpOFOd=>^AY„Z?բʒu!;[p xOnJ< 'hWs|yѽyu]P2ZmN gASTx~X$ϭ2.oQzA[[%;/suihG`H" Gnet-ssh-gateway-2.0.0/LICENSE.txt0000644000004100000410000000204513110347012016375 0ustar www-datawww-dataCopyright © 2008 Jamis Buck Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. net-ssh-gateway-2.0.0/.travis.yml0000644000004100000410000000011413110347012016656 0ustar www-datawww-datalanguage: ruby rvm: - 2.2.2 before_install: gem install bundler -v 1.10.6 net-ssh-gateway-2.0.0/lib/0000755000004100000410000000000013110347012015317 5ustar www-datawww-datanet-ssh-gateway-2.0.0/lib/net/0000755000004100000410000000000013110347012016105 5ustar www-datawww-datanet-ssh-gateway-2.0.0/lib/net/ssh/0000755000004100000410000000000013110347012016702 5ustar www-datawww-datanet-ssh-gateway-2.0.0/lib/net/ssh/gateway/0000755000004100000410000000000013110347012020343 5ustar www-datawww-datanet-ssh-gateway-2.0.0/lib/net/ssh/gateway/version.rb0000644000004100000410000000012413110347012022352 0ustar www-datawww-datamodule Net module SSH class Gateway VERSION = "2.0.0" end end end net-ssh-gateway-2.0.0/lib/net/ssh/gateway.rb0000644000004100000410000001401413110347012020670 0ustar www-datawww-datarequire 'thread' require 'net/ssh' require 'net/ssh/version' # A Gateway is an object that allows you to tunnel network connections through # a publicly visible host to a host hidden behind it. This is particularly # useful when dealing with hosts behind a firewall. One host will generally # be visible (and accessible) outside the firewall, while the others will all # be behind the firewall, and the only way to access those restricted hosts # is by first logging into the publicly visible host, and from thence logging # into the restricted ones. # # This class makes it easy to programmatically connect to these restricted # hosts via SSH. You can either simply forward a port from the local host to # the remote host, or you can open a new Net::SSH connection to the remote # host via a forwarded port. # # require 'net/ssh/gateway' # # gateway = Net::SSH::Gateway.new('host.name', 'user') # # gateway.open('hidden.host', 80) do |port| # Net::HTTP.get_print '127.0.0.1', '/path', port # end # # gateway.ssh('hidden.host', 'user') do |ssh| # puts ssh.exec!("hostname") # end # # gateway.shutdown! # # Port numbers are allocated automatically, beginning at MAX_PORT and # decrementing on each request for a new port until MIN_PORT is reached. If # a port is already in use, this is detected and a different port will be # assigned. class Net::SSH::Gateway # The maximum port number that the gateway will attempt to use to forward # connections from. MAX_PORT = 65535 # The minimum port number that the gateway will attempt to use to forward # connections from. MIN_PORT = 1024 # Instantiate a new Gateway object, using the given remote host as the # tunnel. The arguments here are identical to those for Net::SSH.start, and # are passed as given to that method to start up the gateway connection. # # gateway = Net::SSH::Gateway.new('host', 'user', :password => "password") # # As of 1.1 there is an additional option to specify the wait time for # the gateway thread. The default is 0.001 seconds and can be changed # with the :loop_wait option. # def initialize(host, user, options={}) @loop_wait = options.delete(:loop_wait) || 0.001 @session = Net::SSH.start(host, user, options) @session_mutex = Mutex.new @port_mutex = Mutex.new @next_port = MAX_PORT initiate_event_loop! end # Returns +true+ if the gateway is currently open and accepting connections. # This will be the case unless #shutdown! has been invoked. def active? @active end # Shuts down the gateway by closing all forwarded ports and then closing # the gateway's SSH session. def shutdown! return unless active? @session_mutex.synchronize do # cancel all active forward channels @session.forward.active_locals.each do |lport, host, port| @session.forward.cancel_local(lport) end end @active = false @thread.join @session.close end # Opens a new port on the local host and forwards it to the given host/port # via the gateway host. If a block is given, the newly allocated port # number will be yielded to the block, and the port automatically closed # (see #close) when the block finishes. Otherwise, the port number will be # returned, and the caller is responsible for closing the port (#close). # # gateway.open('host', 80) do |port| # # ... # end # # port = gateway.open('host', 80) # # ... # gateway.close(port) # # If +local_port+ is not specified, the next available port will be used. def open(host, port, local_port=nil) ensure_open! actual_local_port = local_port || next_port @session_mutex.synchronize do @session.forward.local(actual_local_port, host, port) end if block_given? begin yield actual_local_port ensure close(actual_local_port) end else return actual_local_port end rescue Errno::EADDRINUSE raise if local_port # if a local port was explicitly requested, bubble the error up retry end # Cancels port-forwarding over an open port that was previously opened via # #open. def close(port) ensure_open! @session_mutex.synchronize do @session.forward.cancel_local(port) end end # Forwards a new connection to the given +host+ and opens a new Net::SSH # connection to that host over the forwarded port. If a block is given, # the new SSH connection will be yielded to the block, and autoclosed # when the block terminates. The forwarded port will be autoclosed as well. # If no block was given, the new SSH connection will be returned, and it # is up to the caller to terminate both the connection and the forwarded # port when done. # # gateway.ssh('host', 'user') do |ssh| # # ... # end # # ssh = gateway.ssh('host', 'user') # # ... # ssh.close # gateway.close(ssh.transport.port) def ssh(host, user, options={}, &block) local_port = open(host, options[:port] || 22) begin Net::SSH.start("127.0.0.1", user, options.merge(:port => local_port), &block) ensure close(local_port) if block || $! end end private # Raises a RuntimeError if the gateway is not active. This is used as a # sanity check to make sure a client doesn't try to call any methods on # a closed gateway. def ensure_open! raise "attempt to use a closed gateway" unless active? end # Fires up the gateway session's event loop within a thread, so that it # can run in the background. The loop will run for as long as the gateway # remains active. def initiate_event_loop! @active = true @thread = Thread.new do while @active @session_mutex.synchronize do @session.process(@loop_wait) end Thread.pass end end end # Grabs the next available port number and returns it. def next_port @port_mutex.synchronize do port = @next_port @next_port -= 1 @next_port = MAX_PORT if @next_port < MIN_PORT port end end end net-ssh-gateway-2.0.0/.gitignore0000644000004100000410000000014713110347012016543 0ustar www-datawww-data/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.swp .DS_Store net-ssh-gateway-2.0.0/checksums.yaml.gz.sig0000444000004100000410000000040013110347012020612 0ustar www-datawww-datalڶtxiު&[jSu%VnW|,n ͯ"n|"Y⒲XAaWG'DбQ@?!XiZVե{l+tpOq֮ohp|HJG .ʀ޾D/]8ЍL3O]TkZTLsKn >×QRqyq ͍ifnuQ qHgaM0X#._偛XZbۙWfgxD ؃_WudJ AfP׊&T*fY-er}MͶyU ~'t}<7<Gğ۩Znet-ssh-gateway-2.0.0/README.md0000644000004100000410000000703313110347012016033 0ustar www-datawww-data# Net::SSH::Gateway Please note: this project is in maintenance mode. It is not under active development but pull requests are very much welcome. Just be sure to include tests! * Docs: http://net-ssh.github.com/net-ssh-gateway * Issues: https://github.com/net-ssh/net-ssh-gateway/issues * Codes: https://github.com/net-ssh/net-ssh-gateway * Email: net-ssh@solutious.com As of v1.1.1, all gem releases are signed. See INSTALL. ## DESCRIPTION: Net::SSH::Gateway is a library for programmatically tunnelling connections to servers via a single "gateway" host. It is useful for establishing Net::SSH connections to servers behind firewalls, but can also be used to forward ports and establish connections of other types, like HTTP, to servers with restricted access. ## FEATURES: * Easily manage forwarded ports * Establish Net::SSH connections through firewalls ## SYNOPSIS: In a nutshell: require 'net/ssh/gateway' gateway = Net::SSH::Gateway.new('host', 'user') gateway.ssh("host.private", "user") do |ssh| puts ssh.exec!("hostname") end gateway.open("host.private", 80) do |port| Net::HTTP.get_print("127.0.0.1", "/path", port) end gateway.shutdown! # As of 1.1.0, you can also specify the wait time for the # gateway thread with the :loop_wait option. gateway = Net::SSH::Gateway.new('host', 'user', :loop_wait => 0.001) See Net::SSH::Gateway for more documentation. ## REQUIREMENTS: * net-ssh (version 2) If you want to run the tests or use any of the Rake tasks, you'll need: * Echoe (for the Rakefile) * Mocha (for the tests) ## INSTALL: $ gem install net-ssh-gateway However, in order to be sure the code you're installing hasn't been tampered with, it's recommended that you verify the [signature](http://guides.rubygems.org/security/). To do this, you need to add the project's public key as a trusted certificate (you only need to do this once): # Add the public key as a trusted certificate # (You only need to do this once) $ curl -O https://raw.githubusercontent.com/net-ssh/net-ssh-gateway/master/net-ssh-public_cert.pem $ gem cert --add net-ssh-public_cert.pem Then, when install the gem, do so with high security: $ gem install net-ssh-gateway -P HighSecurity If you don't add the public key, you'll see an error like "Couldn't verify data signature". ## Ruby 1.9 As of release 2.0.0, net-ssh-gateway supports only Ruby >= 2.0.0. The last release that supports Ruby 1.9 is 1.3.0. ## LICENSE: (The MIT License) Copyright (c) 2008 Jamis Buck Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.