Module: Pipe2me::Tunnel

Extended by:
Tunnel
Includes:
Sys, Commands, OpenSSL, SSH
Included in:
Tunnel
Defined in:
lib/pipe2me/tunnel.rb,
lib/pipe2me/tunnel.rb

Defined Under Namespace

Modules: Commands, OpenSSL, SSH

Constant Summary collapse

SSL_KEY =

file names

"pipe2me.openssl.priv"
SSL_CERT =
"pipe2me.openssl.cert"
SSL_CACERT =
"pipe2me.cacert"
SSH_PUBKEY =
"pipe2me.id_rsa.pub"
SSH_PRIVKEY =
"pipe2me.id_rsa"
SSH_CONFIG =
"pipe2me.ssh_config"
ShellFormat =
Pipe2me::ShellFormat

Constants included from Commands

Commands::T

Constants included from SSH

SSH::HTTP

Constants included from OpenSSL

OpenSSL::HTTP

Instance Method Summary collapse

Methods included from Commands

#command, #tunnel_uri, #tunnels

Methods included from SSH

#ssh_keygen

Methods included from OpenSSL

#openssl_conf, #ssl_certsign, #ssl_keygen

Methods included from Sys

#sh, #sh!, #sys, #sys!

Instance Method Details

#checkObject



88
89
90
91
# File 'lib/pipe2me/tunnel.rb', line 88

def check
  r = HTTP.get! "#{url}/check"
  puts r
end

#clearObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pipe2me/tunnel.rb', line 16

def clear
  [ 
    SSL_KEY, SSL_CERT, SSL_CACERT, SSH_PUBKEY, SSH_PRIVKEY, SSH_CONFIG,
    "pipe2me.info.inc", "pipe2me.local.inc",
    "pipe2me.openssl.priv.csr", "pipe2me.openssl.rnd",
    "pipe2me.known_hosts"
  ].each do |base|
      next unless File.exist?(base)
      UI.info "Deleting #{base}" 
      FileUtils.rm base
  end
end

#setup(options) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pipe2me/tunnel.rb', line 44

def setup(options)
  if File.exists?("pipe2me.info.inc")
    raise "Found existing pipe2me configuration in #{Dir.getwd}"
  end

  # [todo] escape auth option
  response = HTTP.post! "#{Pipe2me.server}/tunnels/#{options[:token]}",
    "protocols" => options[:protocols]

  server_info = ShellFormat.parse(response)

  raise(ArgumentError, "Missing :fqdn information") unless server_info[:fqdn]

  ShellFormat.write "pipe2me.info.inc", server_info
  ShellFormat.write "pipe2me.local.inc",
                      :server => Pipe2me.server,
                      :ports => options[:ports]

  server_info
end

#updateObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pipe2me/tunnel.rb', line 93

def update
  unless File.exists?(SSH_PRIVKEY)
    ssh_keygen
  end
  unless File.exists?(SSL_KEY)
    ssl_keygen
  end
  unless File.exists?(SSL_CERT)
    ssl_certsign
  end
  unless File.exists?(SSH_CONFIG)
    FileUtils.cp "#{File.dirname(__FILE__)}/tunnel/ssh_config", SSH_CONFIG
  end
end

#verifyObject



83
84
85
86
# File 'lib/pipe2me/tunnel.rb', line 83

def verify
  HTTP.get! "#{url}/verify"
  puts config.fqdn
end