yakr 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDNmNTlhMzFmZTg5YzFkZWZkODk2ODIwZmFkMTE5MDEwMDA3NDAyZA==
5
- data.tar.gz: !binary |-
6
- MGM1M2VkMmI0YTI0MTc2MmQ2MzY4Y2JjOWIyYzlhMWM4ZTE4Y2RjMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OGY4ZDVlMTYxM2RjY2UzOGZiMzM2ZmVmOWU4OTYxY2I2OTk2N2ViZjNkYzUy
10
- M2Y4MzJkNjE1OWZjNDBmODAxODg3OTczNTg3MmY0ODVhNjNhN2I0MjAyZjUw
11
- ZTJiNjczMDg4YTg4MWQ4YWFlMjdkMjM0OWFmMzk4NDlhNGUxMjY=
12
- data.tar.gz: !binary |-
13
- YzdjOTIwYzhhNjk1MzQ5MDQwMjAxNTQwNzRhZWU2NTUyNjc2NTViOTljODg1
14
- NzI1MWFiNzIwMzkxM2QxYTMyOGU1YmYyYzkwN2IzZjY1NzMzMTA1YmJlOTY5
15
- YWQ1NTE0YjY2OThhYmM5Mjc3ODMyYTI4YmQzZTQzYTcxODBkZTQ=
2
+ SHA1:
3
+ metadata.gz: 655f3af8ad49c2ab4d6410243fffe8a214bbcbb8
4
+ data.tar.gz: e939f4be28c997883fe756ab7985e5f4d68628f7
5
+ SHA512:
6
+ metadata.gz: 5c6f5f43ddebe3c2ca9adc976b3857a9fb1343d81fa41e7fb99da93caabe5a2991fa4dd61cebfd89ded4da65c1b094e55505e085b996d56ca57590382c0a1e41
7
+ data.tar.gz: 97e703de77f0e7ac02777c4c8e4d07d187781dc1a1d32a705c1d7d4d5426b00b695bdc266782916e1a4c36cfa2c96d976bfef83b7c9d5016a0ceed1ba8e90036
data/README.md CHANGED
@@ -44,10 +44,14 @@ The server instance of Yakr can be told to redirect the data it receives to a fi
44
44
  For additional options type `yakr --help`.
45
45
 
46
46
  ##Fun Stuff
47
- To be added soon.
47
+ It's possible to mimic a simple chat interface using a split terminal window (courtesy of the wonderful [iTerm 2](http://http://www.iterm2.com)):
48
+
49
+ ![Split terminal conversation](http://fidgetbox.co.uk/github/split_yakr.png)
50
+
51
+ The top pane shows the output of a local instance of Yakr with a remote client connected. This acts as our incoming chat window. The bottom pane shows another local instance of Yakr connected to the remote system as a client. This acts as our outgoing message window. Crude, but perfectly usable.
48
52
 
49
53
  ##License
50
54
  Yakr is free software, and you are welcome to redistribute it under certain conditions. See the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for more details.
51
55
 
52
56
  ##Comments or suggestions?
53
- Email me at [marc.ransome@fidgetbox.co.uk](marc.ransome@fidgetbox.co.uk) with bug reports, feature requests or general comments and follow [@marcransome](http://www.twitter.com/marcransome) for updates.
57
+ Email me at [marc.ransome@fidgetbox.co.uk](mailto://marc.ransome@fidgetbox.co.uk) with bug reports, feature requests or general comments and follow [@marcransome](http://www.twitter.com/marcransome) for updates.
@@ -27,7 +27,7 @@ require 'timeout'
27
27
 
28
28
  class Yakr
29
29
 
30
- VERSION = "0.2.3"
30
+ VERSION = "0.2.4"
31
31
  REQUIRE_SERVER = 0.1
32
32
  USAGE_BANNER = "Use `#{File.basename($0)} --help` for available options."
33
33
 
@@ -38,8 +38,7 @@ class Yakr
38
38
 
39
39
  # test for zero arguments
40
40
  if ARGV.empty? then
41
- puts USAGE_BANNER
42
- exit 1
41
+ self.exit_with_banner(1)
43
42
  end
44
43
 
45
44
  # start processing command line arguments
@@ -47,68 +46,66 @@ class Yakr
47
46
  options = OptionReader.parse(ARGV)
48
47
  rescue OptionParser::InvalidOption => t
49
48
  puts t
50
- puts USAGE_BANNER
51
- exit
49
+ self.exit_with_banner(1)
52
50
  rescue OptionParser::MissingArgument => m
53
51
  puts m
54
- puts USAGE_BANNER
55
- exit
52
+ self.exit_with_banner(1)
56
53
  end
57
54
 
58
- # ensure host argument is specified if a port is specified
59
- if options.connect_port.any? and !options.connect_host.any?
60
- puts "host connect: no host specified"
61
- puts USAGE_BANNER
62
- exit 1
55
+ # validate mode options
56
+ if (options.connect_host or options.connect_port) and
57
+ (options.listen_port or options.limit_lines) then
58
+ puts "mode options: specify either listen or connect options"
59
+ self.exit_with_banner(1)
60
+ elsif not (options.connect_host or options.listen_port)
61
+ puts "mode options: specify listen or connect options"
62
+ self.exit_with_banner(1)
63
63
  end
64
64
 
65
- if options.connect_host.any? and !options.connect_port.any?
66
- puts "host connect: no port specified"
67
- puts USAGE_BANNER
68
- exit 1
65
+ # validate server options
66
+ if options.connect_port and not options.connect_host
67
+ puts "host connect: no host specified"
68
+ self.exit_with_banner(1)
69
69
  end
70
70
 
71
- # validate host argument
72
- if options.connect_host.any?
73
- # TODO
71
+ if options.connect_host and not options.connect_port
72
+ puts "host connect: no port specified"
73
+ self.exit_with_banner(1)
74
74
  end
75
75
 
76
- # test for invalid host port
77
- if options.connect_port.any?
78
- if !(options.connect_port.first.to_i > 0) and !(options.connect_port.first.to_i < 65535)
79
- puts "invalid port: #{options.connect_port.first.to_s}"
80
- puts USAGE_BANNER
81
- exit 1
76
+ # validate connection port
77
+ if options.connect_port
78
+ if not (options.connect_port.to_i > 0 and options.connect_port.to_i <= 65535)
79
+ puts "invalid port: #{options.connect_port.to_s}"
80
+ self.exit_with_banner(1)
82
81
  end
83
82
  end
84
83
 
85
84
  # validate listen port
86
- if options.connect_port.any?
87
- if options.connect_port.first.to_i > 0 and options.connect_port.first.to_i < 65535
88
- # valid port provided
89
-
90
- else
91
- puts "invalid port: #{options.connect_port.first.to_s}"
92
- puts USAGE_BANNER
93
- exit 1
85
+ if options.listen_port
86
+ if not (options.listen_port.to_i > 0 and options.listen_port.to_i <= 65535)
87
+ puts "invalid port: #{options.listen_port.to_s}"
88
+ self.exit_with_banner(1)
94
89
  end
95
- else
96
- options.connect_port << "4000"
97
90
  end
98
-
99
- # assume connection mode wherever a host has been specified,
100
- # otherwise listen for incoming connections
101
- if options.connect_host.any?
102
- connect(options.connect_host.first, options.connect_port.first.to_i)
91
+
92
+ # validate line limit
93
+ if options.limit_lines and not options.limit_lines.to_i > 0
94
+ puts "invalid max lines: #{options.limit_lines}"
95
+ self.exit_with_banner(1)
96
+ end
97
+
98
+ if options.connect_host
99
+ connect(options.connect_host, options.connect_port.to_i)
103
100
  else
104
- listen(options.listen_port.first.to_i, options.limit_lines.to_i)
101
+ listen(options.listen_port.to_i, options.limit_lines.to_i)
105
102
  end
106
103
  end
107
104
 
108
105
  def self.connect(host, port)
109
106
 
110
107
  begin
111
- timeout(30) do
108
+ timeout(20) do
112
109
 
113
110
  puts "Attempting connection.."
114
111
 
@@ -126,13 +123,11 @@ class Yakr
126
123
  # read from standard input and send
127
124
  # text line by line to server
128
125
  STDIN.each do |str|
129
- #str.chomp!
130
126
  @server.puts "#{str}"
131
127
  end
132
128
  else
133
129
  puts "host connect: unexpected server response"
134
- puts USAGE_BANNER
135
- exit 1
130
+ self.exit_with_banner(1)
136
131
  end
137
132
 
138
133
  rescue Interrupt
@@ -140,35 +135,26 @@ class Yakr
140
135
  exit 1
141
136
  rescue Timeout::Error => ex
142
137
  puts "host connect: timed out"
143
- puts USAGE_BANNER
144
- exit 1
145
- rescue
146
- puts "host connect: unable to connect"
147
- puts USAGE_BANNER
148
- exit 1
138
+ self.exit_with_banner(1)
139
+ rescue => e
140
+ puts "host connect: unable to connect #{e}"
141
+ self.exit_with_banner(1)
149
142
  ensure
150
143
  @server.close unless @server.nil?
151
144
  end
152
145
  end
153
146
 
154
- def self.listen(port, lines_arg)
147
+ def self.listen(port, max_lines)
155
148
  begin
149
+ limit_output = true if max_lines > 0
156
150
  @server = TCPServer.open(port)
157
151
  loop do
158
152
  client = @server.accept
159
153
  client.puts "yakr=>version:#{VERSION}"
160
-
161
- max_lines = lines_arg
162
-
163
- client.each do |str|
164
-
165
- exit 0 if max_lines == 0 and lines_arg > 0
166
-
167
- #str.chomp!
154
+ client.each do |str|
155
+ exit 0 if max_lines <= 0 and limit_output
168
156
  puts "#{str}"
169
-
170
- # decrement line counter
171
- max_lines -= 1
157
+ max_lines -= 1 if limit_output
172
158
  end
173
159
  end
174
160
  rescue Interrupt
@@ -182,4 +168,9 @@ class Yakr
182
168
  @server.close unless @server.nil?
183
169
  end
184
170
  end
171
+
172
+ def self.exit_with_banner(x)
173
+ puts USAGE_BANNER
174
+ exit x
175
+ end
185
176
  end
@@ -24,10 +24,6 @@ class OptionReader
24
24
  def self.parse(args)
25
25
 
26
26
  options = OpenStruct.new
27
- options.connect_host = []
28
- options.connect_port = []
29
- options.listen_port = []
30
- options.limit_lines = 0
31
27
 
32
28
  opts = OptionParser.new do |opts|
33
29
  opts.banner = "Usage: #{File.basename($0)} -c HOST -p PORT | -l PORT [-m NUM]"
@@ -36,25 +32,24 @@ class OptionReader
36
32
  opts.separator "Client mode options:"
37
33
 
38
34
  opts.on("-c", "--connect HOST", "Specify the remote host to connect to") do |host|
39
- options.connect_host << host
35
+ options.connect_host = host
40
36
  end
41
37
 
42
38
  opts.on("-p", "--port PORT", "Port number for outgoing connection") do |port|
43
- options.connect_port << port
39
+ options.connect_port = port
44
40
  end
45
41
 
46
42
  opts.separator ""
47
43
  opts.separator "Server mode options:"
48
44
 
49
45
  opts.on("-l", "--listen PORT", "Port number for incoming connection") do |port|
50
- options.listen_port << port
46
+ options.listen_port = port
51
47
  end
52
48
 
53
49
  opts.on("-m", "--max NUM", "Limit output to NUM lines, then exit") do |lines|
54
50
  options.limit_lines = lines
55
51
  end
56
-
57
-
52
+
58
53
  opts.separator ""
59
54
  opts.separator "Misc options:"
60
55
 
data/test.sh ADDED
@@ -0,0 +1,36 @@
1
+ #!/bin/bash
2
+ #
3
+ # test.sh
4
+ #
5
+ # Copyright (c) 2012, Marc Ransome <marc.ransome@fidgetbox.co.uk>
6
+ #
7
+ # This file is part of Yakr.
8
+ #
9
+ # Yakr is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # Yakr is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with Yakr. If not, see <http://www.gnu.org/licenses/>.
21
+ #
22
+
23
+ version_from_gemspec=$( grep 's.version' yakr.gemspec | cut -c 16-20 )
24
+ gem_file="yakr-$version_from_gemspec.gem"
25
+
26
+ echo "Removing outdated gem files.."
27
+ rm *.gem
28
+
29
+ echo "Uninstalling previous versions.."
30
+ gem uninstall -a -x yakr
31
+
32
+ echo "Building gem.."
33
+ gem build yakr.gemspec
34
+
35
+ echo "Installing gem file.."
36
+ gem install $gem_file
@@ -21,8 +21,8 @@
21
21
 
22
22
  Gem::Specification.new do |s|
23
23
  s.name = 'yakr'
24
- s.version = '0.2.3'
25
- s.date = '2013-02-25'
24
+ s.version = '0.2.4'
25
+ s.date = '2013-04-30'
26
26
  s.summary = 'TCP/IP output tool'
27
27
  s.description = 'Yakr is a minimalist network tool for forwarding command output or arbitrary data to a remote host.'
28
28
  s.authors = ["Marc Ransome"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yakr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Ransome
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-02-25 00:00:00.000000000 Z
11
+ date: 2013-04-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Yakr is a minimalist network tool for forwarding command output or arbitrary
14
14
  data to a remote host.
@@ -23,6 +23,7 @@ files:
23
23
  - bin/yakr
24
24
  - lib/yakr.rb
25
25
  - lib/yakr/optionreader.rb
26
+ - test.sh
26
27
  - yakr.gemspec
27
28
  homepage: http://marcransome.github.com/Yakr
28
29
  licenses:
@@ -34,17 +35,17 @@ require_paths:
34
35
  - lib
35
36
  required_ruby_version: !ruby/object:Gem::Requirement
36
37
  requirements:
37
- - - ! '>='
38
+ - - '>='
38
39
  - !ruby/object:Gem::Version
39
40
  version: '0'
40
41
  required_rubygems_version: !ruby/object:Gem::Requirement
41
42
  requirements:
42
- - - ! '>='
43
+ - - '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
46
  requirements: []
46
47
  rubyforge_project:
47
- rubygems_version: 2.0.0
48
+ rubygems_version: 2.0.3
48
49
  signing_key:
49
50
  specification_version: 4
50
51
  summary: TCP/IP output tool