mtik 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,9 @@
1
+ 2010-03-11 (11 MAR 2010) VERSION 3.0.3 Aaron D. Gifford (http://www.aarongifford.com)
2
+ * Bug fix to lib/mtik.rb command() method so when executing multiple commands
3
+ response array order matches command array order.
4
+ * Cosmetic change for hex encoding with a little simplification, and one very small
5
+ readability change in lib/mtik/connection.rb
6
+
1
7
  2010-02-05 (05 FEB 2010) VERSION 3.0.2 Aaron D. Gifford (http://www.aarongifford.com)
2
8
  * Typo fixes to example tikfetch.rb
3
9
  * Multi-command functionality added to interactive client and to tikcommand.rb example
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ gemspec = Gem::Specification.new do |spec|
5
+ spec.name = 'mtik'
6
+ spec.version = File.open('VERSION.txt','r').to_a.join.strip
7
+ spec.date = File.mtime('VERSION.txt')
8
+ spec.author = 'Aaron D. Gifford'
9
+ spec.email = 'email_not_accepted@aarongifford.com'
10
+ spec.homepage = 'http://www.aarongifford.com/computers/mtik/'
11
+ spec.summary = 'MTik implements the MikroTik RouterOS API for use in Ruby.'
12
+ spec.description = 'MTik implements the MikroTik RouterOS API for use in Ruby.'
13
+ spec.has_rdoc = true ## Only partially true currently
14
+ spec.rubyforge_project = 'mtik'
15
+ spec.extra_rdoc_files = [ 'README.txt' ]
16
+ spec.require_paths = [ 'lib' ]
17
+ spec.files = [
18
+ 'CHANGELOG.txt',
19
+ 'LICENSE.txt',
20
+ 'README.txt',
21
+ 'VERSION.txt',
22
+ 'Rakefile',
23
+ 'examples/tikcli.rb',
24
+ 'examples/tikcommand.rb',
25
+ 'examples/tikfetch.rb',
26
+ 'examples/tikjson.rb',
27
+ 'lib/mtik.rb',
28
+ 'lib/mtik/connection.rb',
29
+ 'lib/mtik/error.rb',
30
+ 'lib/mtik/fatalerror.rb',
31
+ 'lib/mtik/reply.rb',
32
+ 'lib/mtik/request.rb',
33
+ 'lib/mtik/timeouterror.rb'
34
+ ]
35
+ end
36
+
37
+ Rake::GemPackageTask.new(gemspec) do |pkg|
38
+ pkg.need_zip = true
39
+ pkg.need_tar = true
40
+ end
41
+
42
+ task :default => [ 'pkg/mtik-' + File.open('VERSION.txt','r').to_a.join.strip + '.gem' ]
43
+
data/VERSION.txt CHANGED
@@ -1 +1 @@
1
- 3.0.2
1
+ 3.0.3
data/lib/mtik.rb CHANGED
@@ -211,7 +211,8 @@ module MTik
211
211
  cmd = [ cmd ]
212
212
  end
213
213
 
214
- cmd.each do |c|
214
+ cmd.each_index do |i|
215
+ c = cmd[i]
215
216
  replycount = 1
216
217
  tk.send_request(false, c[0], c[1,c.length-1]) do |req, sentence|
217
218
  replycount += 1
@@ -229,7 +230,7 @@ module MTik
229
230
  req.cancel
230
231
  end
231
232
  if sentence.key?('!done')
232
- replies.push(req.reply)
233
+ replies[i] = req.reply
233
234
  end
234
235
  end
235
236
  end
@@ -75,13 +75,14 @@ class MTik::Connection
75
75
  end
76
76
  attr_reader :requests, :host, :port, :user, :pass, :conn_timeout, :cmd_timeout
77
77
 
78
- ## Utility to pack a binary string as an ASCII hex string
79
- ## (Ruby really needs pack method for the String class--like
80
- ## "deadbeef".pack("H*")--then this would be unnecessary.)
81
- def hexpack(str)
78
+ ## Internal utility function:
79
+ ## Sugar-coat ["0deadf0015"].pack('H*') so one can just do
80
+ ## "0deadf0015".hex2bin instead. Prepend a '0' if the hex
81
+ ## string doesn't have an even number of digits.
82
+ def hex2bin(str)
82
83
  return str.length % 2 == 0 ?
83
- [str].pack('H'+str.length.to_s) :
84
- [str[0,1]].pack('h') + [str[1,str.length-1]].pack('H'+(str.length-1).to_s)
84
+ [str].pack('H*') :
85
+ ['0'+str].pack('H*')
85
86
  end
86
87
 
87
88
  ## Connect and login to the device using the API
@@ -99,7 +100,7 @@ class MTik::Connection
99
100
  end
100
101
 
101
102
  ## Grab the challenge from first (only) sentence in the reply:
102
- challenge = hexpack(reply[0]['ret'])
103
+ challenge = hex2bin(reply[0]['ret'])
103
104
 
104
105
  ## Generate reply MD5 hash and convert binary hash to hex string:
105
106
  response = Digest::MD5.hexdigest(0.chr + @pass + challenge)
@@ -171,7 +172,8 @@ class MTik::Connection
171
172
  return sentence
172
173
  else
173
174
  ## Add word to sentence
174
- if m = /^=?([^=]+)=(.*)$/.match(word)
175
+ m = /^=?([^=]+)=(.*)$/.match(word)
176
+ unless m.nil?
175
177
  sentence[m[1]] = m[2]
176
178
  else
177
179
  sentence[word] = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtik
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron D. Gifford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-05 00:00:00 -07:00
12
+ date: 2010-03-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,6 +26,7 @@ files:
26
26
  - LICENSE.txt
27
27
  - README.txt
28
28
  - VERSION.txt
29
+ - Rakefile
29
30
  - examples/tikcli.rb
30
31
  - examples/tikcommand.rb
31
32
  - examples/tikfetch.rb
@@ -39,6 +40,8 @@ files:
39
40
  - lib/mtik/timeouterror.rb
40
41
  has_rdoc: true
41
42
  homepage: http://www.aarongifford.com/computers/mtik/
43
+ licenses: []
44
+
42
45
  post_install_message:
43
46
  rdoc_options: []
44
47
 
@@ -59,9 +62,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
62
  requirements: []
60
63
 
61
64
  rubyforge_project: mtik
62
- rubygems_version: 1.3.1
65
+ rubygems_version: 1.3.5
63
66
  signing_key:
64
- specification_version: 2
67
+ specification_version: 3
65
68
  summary: MTik implements the MikroTik RouterOS API for use in Ruby.
66
69
  test_files: []
67
70