pipe2me-client 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f325ba9aa41bbe17611895ce65eff4279fe21fa
4
- data.tar.gz: 330125913e082e80df6e67fde935b41d810b738f
3
+ metadata.gz: da14193618947d8349f1570d2aca3314181b2f27
4
+ data.tar.gz: 374de70c21cfa735fdaf7955d5c7899f2d14fab4
5
5
  SHA512:
6
- metadata.gz: d517e7c6df0d6f76e430d342adfb1931f53fbf585b4b86087a7bee9b9575972180337849813c7d08ca84cdd44e2e17a91ac1a16ab7ba5017022faa7c3467b552
7
- data.tar.gz: 24b3a761dee28119080f12d6aec46a5a05c52a58d5809cf710bb075f1f74eeb89ac93f6bb50d3aedd3e561b17beb47ca52cad82868cfe881f7d4d2b8289abe00
6
+ metadata.gz: c4209b4b7667b38c07ff30e9b7d18916ce6f6ccaaeed2e62262074b379d3b5c1d2aaf32aa3ab557228a44000f9a8cee5845b4c6266d02c4e18f4c0186fab6eac
7
+ data.tar.gz: 1af495821d30bdfd36c5142ca9821710fae53dcc979b18533197d141dd76631015fbb15a36b1dfd2031835f558a683b913ec9d601f63cb7689a5389bb01b6563
data/lib/pipe2me.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Pipe2me
2
+ def self.server; @server; end
3
+ def self.server=(server); @server = server; end
2
4
  end
3
5
 
4
6
  require "simple/ui"
5
7
 
6
8
  require_relative "pipe2me/version"
7
- require_relative "pipe2me/config"
8
9
  require_relative "pipe2me/tunnel"
9
10
 
data/lib/pipe2me/cli.rb CHANGED
@@ -24,7 +24,7 @@ class Pipe2me::CLI < Thor
24
24
  Dir.chdir options[:dir]
25
25
  UI.info "Changed into", options[:dir]
26
26
  end
27
-
27
+
28
28
  if options[:insecure]
29
29
  Pipe2me::HTTP.enable_insecure_mode
30
30
  end
@@ -49,7 +49,7 @@ class Pipe2me::CLI < Thor
49
49
  def setup
50
50
  handle_global_options
51
51
 
52
- Pipe2me::Config.server = options[:server]
52
+ Pipe2me.server = options[:server]
53
53
  server_info = Pipe2me::Tunnel.setup options
54
54
 
55
55
  update
@@ -84,4 +84,27 @@ class Pipe2me::CLI < Thor
84
84
 
85
85
  Pipe2me::Tunnel.check
86
86
  end
87
+
88
+ desc "start", "start tunnels"
89
+ def start
90
+ handle_global_options
91
+
92
+ Pipe2me::Tunnel.tunnels.each do |tunnel|
93
+ UI.info "Setting up", tunnel
94
+ end
95
+
96
+ cmd = Pipe2me::Tunnel.command
97
+ UI.info cmd
98
+ Kernel.exec cmd
99
+ end
100
+
101
+ desc "clear", "clear configuration"
102
+ def clear
103
+ handle_global_options
104
+
105
+ UI.error "This will remove the configuration in #{Dir.getwd}. Continue? (^C to cancel)"
106
+ STDIN.gets
107
+
108
+ Pipe2me::Tunnel.clear
109
+ end
87
110
  end
@@ -10,8 +10,20 @@ module Pipe2me::Tunnel
10
10
 
11
11
  SSH_PUBKEY = "pipe2me.id_rsa.pub"
12
12
  SSH_PRIVKEY = "pipe2me.id_rsa"
13
-
13
+
14
14
  SSH_CONFIG = "pipe2me.ssh_config"
15
+
16
+ def clear
17
+ [
18
+ SSL_KEY, SSL_CERT, SSL_CACERT, SSH_PUBKEY, SSH_PRIVKEY, SSH_CONFIG,
19
+ "pipe2me.info.inc", "pipe2me.local.inc",
20
+ "pipe2me.openssl.priv.csr", "pipe2me.openssl.rnd"
21
+ ].each do |base|
22
+ next unless File.exist?(base)
23
+ UI.info "Deleting #{base}"
24
+ FileUtils.rm base
25
+ end
26
+ end
15
27
  end
16
28
 
17
29
  require_relative "tunnel/openssl"
@@ -34,7 +46,7 @@ module Pipe2me::Tunnel
34
46
  end
35
47
 
36
48
  # [todo] escape auth option
37
- response = HTTP.post! "#{Pipe2me::Config.server}/tunnels/#{options[:token]}",
49
+ response = HTTP.post! "#{Pipe2me.server}/tunnels/#{options[:token]}",
38
50
  "protocols" => options[:protocols]
39
51
 
40
52
  server_info = ShellFormat.parse(response)
@@ -43,7 +55,7 @@ module Pipe2me::Tunnel
43
55
 
44
56
  ShellFormat.write "pipe2me.info.inc", server_info
45
57
  ShellFormat.write "pipe2me.local.inc",
46
- :server => Pipe2me::Config.server,
58
+ :server => Pipe2me.server,
47
59
  :ports => options[:ports]
48
60
 
49
61
  server_info
@@ -3,45 +3,38 @@ module Pipe2me::Tunnel::Commands
3
3
 
4
4
  T = Pipe2me::Tunnel
5
5
 
6
- # returns an array of [ protocol, remote_port, local_port ] entries
7
- def tunnels
8
- @tunnels ||= begin
9
- urls, ports = config.urls, config.ports.to_s.split(",")
6
+ def tunnel_uri
7
+ URI.parse config.tunnel
8
+ end
10
9
 
11
- urls.zip(ports).map do |url, local_port|
12
- uri = URI.parse(url)
13
- [ uri.scheme, uri.port, local_port || uri.port ]
14
- end
10
+ class Spec < Struct.new(:protocol, :host, :remote_port, :local_port)
11
+ def inspect
12
+ "#{protocol}: #{host}:#{remote_port} <= localhost:#{local_port}"
15
13
  end
16
14
  end
17
15
 
18
- # return an arry [ [name, command ], [name, command ], .. ]
19
- def tunnel_command
20
- tunnel_uri = URI.parse config.tunnel
21
-
22
- port_mappings = tunnels.map do |protocol, remote_port, local_port|
23
- [ remote_port, local_port ]
16
+ def tunnels
17
+ urls, ports = config.urls, config.ports.split(",")
18
+ urls.zip(ports).map do |url, local_port|
19
+ uri = URI.parse(url)
20
+ Spec.new uri.scheme, tunnel_uri.host, uri.port, local_port || uri.port
24
21
  end
25
-
26
- cmd = port_tunnel_command(tunnel_uri, port_mappings)
27
- [ "tunnel", cmd ]
28
22
  end
29
23
 
30
- private
31
-
32
- def port_tunnel_command(tunnel_uri, port_mappings)
33
- port_mappings = port_mappings.map do |remote_port, local_port|
34
- "-R 0.0.0.0:#{remote_port}:localhost:#{local_port}"
35
- end.join(" ")
24
+ # return an arry [ [name, command ], [name, command ], .. ]
25
+ def command
26
+ port_mappings = tunnels.map do |tunnel|
27
+ "-R 0.0.0.0:#{tunnel.remote_port}:localhost:#{tunnel.local_port}"
28
+ end
36
29
 
37
30
  cmd = <<-SHELL
38
- env AUTOSSH_GATETIME=0 # comments work here..
31
+ env AUTOSSH_GATETIME=0
39
32
  #{Which::AUTOSSH}
40
33
  -M 0
41
34
  -F #{T::SSH_CONFIG}
42
35
  #{tunnel_uri.user}@#{tunnel_uri.host}
43
36
  -p #{tunnel_uri.port}
44
- #{port_mappings}
37
+ #{port_mappings.join(" ")}
45
38
  -i #{T::SSH_PRIVKEY}
46
39
  -o StrictHostKeyChecking=no
47
40
  -o UserKnownHostsFile=pipe2me.known_hosts
@@ -49,8 +42,7 @@ module Pipe2me::Tunnel::Commands
49
42
  -o ExitOnForwardFailure=yes
50
43
  -N
51
44
  SHELL
52
-
53
- # remove comments and newlines from commands
54
- cmd.gsub(/( *#.*|\s+)/, " ").gsub(/(^ )|( $)/, "")
45
+
46
+ cmd.gsub(/\s+/, " ")
55
47
  end
56
48
  end
@@ -27,8 +27,8 @@ module Pipe2me::Tunnel::OpenSSL
27
27
 
28
28
  File.write SSL_CERT, cert
29
29
 
30
- cacert = HTTP.get! "#{Pipe2me::Config.server}/cacert"
31
- UI.error "Got #{cacert.length} byte from #{Pipe2me::Config.server}/cacert"
30
+ cacert = HTTP.get! "#{Pipe2me.server}/cacert"
31
+ UI.success "Got #{cacert.length} byte from #{Pipe2me.server}/cacert"
32
32
  File.write SSL_CACERT, cacert
33
33
  end
34
34
  end
@@ -1,4 +1,4 @@
1
1
  module Pipe2me
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  BANNER = "pipe2me command line client V#{Pipe2me::VERSION}; (c) The kinko.me team, 2013, 2014."
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipe2me-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: pipe2me command line client V0.3.0; (c) The kinko.me team, 2013, 2014.
55
+ description: pipe2me command line client V0.3.1; (c) The kinko.me team, 2013, 2014.
56
56
  email: contact@kinko.me
57
57
  executables:
58
58
  - pipe2me
@@ -65,7 +65,6 @@ files:
65
65
  - lib/pipe2me.rb
66
66
  - lib/pipe2me/bin/natpmpc
67
67
  - lib/pipe2me/cli.rb
68
- - lib/pipe2me/config.rb
69
68
  - lib/pipe2me/ext/file_ext.rb
70
69
  - lib/pipe2me/ext/http.rb
71
70
  - lib/pipe2me/ext/shell_format.rb
@@ -115,5 +114,5 @@ rubyforge_project:
115
114
  rubygems_version: 2.2.2
116
115
  signing_key:
117
116
  specification_version: 4
118
- summary: pipe2me command line client V0.3.0; (c) The kinko.me team, 2013, 2014.
117
+ summary: pipe2me command line client V0.3.1; (c) The kinko.me team, 2013, 2014.
119
118
  test_files: []
@@ -1,7 +0,0 @@
1
- require "tmpdir"
2
-
3
- module Pipe2me::Config
4
- extend self
5
-
6
- attr :server, true
7
- end