mtik 4.1.0 → 4.1.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
  SHA256:
3
- metadata.gz: 5ce416fc9ce5a6d6768f40c11b68fc983fcf75ba69e10e3bc660a0b405fc1bcc
4
- data.tar.gz: 910a34bcb91770ea3f5607fd91297fa1d518f0020e35e27e810deb4eb797cd71
3
+ metadata.gz: 69ac4aa4e71fb42516c3f6251de37e64a1041ad5f47f6c95548e601e451f8475
4
+ data.tar.gz: 3003d97eefc4abe69bf3e0e708e47426cd88ca1ac70c7130ccf8336c14ede4c9
5
5
  SHA512:
6
- metadata.gz: 86879188b9b9af32b1d61f61d3c539a3f8482ef1da078f4a347ea548e1480e0c5b6502d73784a7acda610a17d4b6be141dae93a20b07c1c85959aec538834be5
7
- data.tar.gz: 6778bcf64f479677ccdaec744a8356b936527471870e21aa6878749ceb22d79d43452415113a2e15de4d4be0bbc133d7a32b1d0c7d70807cf7066eb94acab91e
6
+ metadata.gz: 1ecee89ebbb4ad1f19ed5ddee719883ad0f7612157650487019dbd607580dfbab274c29c07567016b71a1695ef493c6e24358e13d2ccffb89a16adb3855de54c
7
+ data.tar.gz: f59ffc39d06615562f676499ed1a672be907e95e9d55589c472081c78ccf0670ba024821d4625782dcb2bf7bf1f1d20cead2303e4095d459ed6aeca98a755229
@@ -1,3 +1,15 @@
1
+ 2020-08-24 (24 AUG 2020) VERSION 4.1.1
2
+ * Version bump to update copyright notices and author's URL
3
+ * Moved the tikjson script to the bin subdirectory and updated
4
+ it to include CLI options like tikcommand and added a
5
+ --pretty CLI option.
6
+ * Updated README to use HTTPS URLs where releant AND fixed the
7
+ examples section to correctly note that example scripts now
8
+ reside in the bin subdirectory.
9
+ * Tweaked varous bin subdirectory scripts to add a --verbose
10
+ CLI option (except for tikcli) and matching MTIK_VERBOSE
11
+ environment variable.
12
+
1
13
  2020-08-23 (23 AUG 2020) VERSION 4.1.0
2
14
  * Minor version bump due to changing argument passing for the call to
3
15
  MTik.interactive_client()
@@ -22,21 +34,21 @@
22
34
  * Adam bumped the version number and separated out a gemspec file
23
35
  * Jiacheng (github user krhougs) had submitted a similar update as Adam
24
36
 
25
- 2014-02-14 (14 FEB 2014) VERSION 4.0.3 Aaron D. Gifford (http://www.aarongifford.com)
37
+ 2014-02-14 (14 FEB 2014) VERSION 4.0.3 Aaron D. Gifford (https://aarongifford.com)
26
38
  * Update to fetch() utility, along with some very minor some cosmetic changes
27
39
 
28
- 2013-06-06 (06 JUN 2013) VERSION 4.0.2 Aaron D. Gifford (http://www.aarongifford.com)
40
+ 2013-06-06 (06 JUN 2013) VERSION 4.0.2 Aaron D. Gifford (https://aarongifford.com)
29
41
  Bart Braem (http://www.lalunerouge.net/)
30
42
  * Merged Bart Braem's implementation of timeouts and bumped up the version. Thanks, Bart!
31
43
  * Updated Rakefile to remove a bit of obsolescence
32
44
 
33
- 2012-02-09 (09 FEB 2012) VERSION 4.0.1 Aaron D. Gifford (http://www.aarongifford.com)
45
+ 2012-02-09 (09 FEB 2012) VERSION 4.0.1 Aaron D. Gifford (https://aarongifford.com)
34
46
  * Added os_version to connections. Upon successful connect and login, the RouterOS
35
47
  version is fetched and stored. This will allow future updates to better support
36
48
  some commands that differ (like fetch) depending on which RouterOS version is
37
49
  installed on the device.
38
50
 
39
- 2011-03-25 (25 MAR 2011) VERSION 4.0.0 Aaron D. Gifford (http://www.aarongifford.com)
51
+ 2011-03-25 (25 MAR 2011) VERSION 4.0.0 Aaron D. Gifford (https://aarongifford.com)
40
52
  * Per user suggestion, added a new optional cancel parameter to the MTik#command()
41
53
  method that will auto-cancel the supplied command after receiving the specified
42
54
  number of '!re' reply sentences. This is usful for executing a command that otherwise
@@ -52,7 +64,7 @@
52
64
  eliminated a few redundant key?() calls, and fixed a replycounter initialization
53
65
  typo (had set it to 1 instead of 0).
54
66
 
55
- 2011-01-11 (11 JAN 2011) VERSION 3.1.2 Aaron D. Gifford (http://www.aarongifford.com)
67
+ 2011-01-11 (11 JAN 2011) VERSION 3.1.2 Aaron D. Gifford (https://aarongifford.com)
56
68
  * Added source file encoding comments and updated the copyright notices
57
69
  * Fixed a tiny bug in lib/mtik/connection.rb
58
70
  * Changed MTik::Request@state member in lib/mtik/request.rb to Symbol instead of String
@@ -61,12 +73,12 @@
61
73
  * Renamed a few variables that, with warnings enabled, Ruby complained were overlapping
62
74
  or hiding outer variables of the same name to avoid the warning.
63
75
 
64
- 2010-12-30 (30 DEC 2011) VERSION 3.1.1 Aaron D. Gifford (http://www.aarongifford.com)
76
+ 2010-12-30 (30 DEC 2011) VERSION 3.1.1 Aaron D. Gifford (https://aarongifford.com)
65
77
  * Changed the tikfetch.rb utility so it no longer requires a destination filename
66
78
  by default--it will use the supplied URL's final path element as a filename. Also
67
79
  updated the stats output a bit.
68
80
 
69
- 2010-04-24 (24 APR 2010) VERSION 3.1.0 Aaron D. Gifford (http://www.aarongifford.com)
81
+ 2010-04-24 (24 APR 2010) VERSION 3.1.0 Aaron D. Gifford (https://aarongifford.com)
70
82
  * Added find_sentences() method to MTik::Reply -- just sugar to Array.select()
71
83
  * Changed MTik::Connection.fetch() method to add an optional timeout parameter
72
84
  which should not affect the API and should be backward compatible. By default,
@@ -80,28 +92,28 @@
80
92
  command if needed. Due to this change, I decided to bump the version to 3.1.0.
81
93
  * Fixed RDoc formatting in several files, and added an RDocTask to the Rakefile
82
94
 
83
- 2010-04-23 (23 APR 2010) VERSION 3.0.5 Aaron D. Gifford (http://www.aarongifford.com)
95
+ 2010-04-23 (23 APR 2010) VERSION 3.0.5 Aaron D. Gifford (https://aarongifford.com)
84
96
  * Double bug-fix (typo fix and logic fix) to request.rb thanks to Allan Eising and
85
97
  Søren Daugaard. Thank you both for the patch!
86
98
  * Added a brief sanity-check in request.rb to help spotlight logic errors.
87
99
 
88
- 2010-04-09 (09 APR 2010) VERSION 3.0.4 Aaron D. Gifford (http://www.aarongifford.com)
100
+ 2010-04-09 (09 APR 2010) VERSION 3.0.4 Aaron D. Gifford (https://aarongifford.com)
89
101
  * Bug fix to lib/mtik.rb thanks to Allan Eising to the command validation regular
90
102
  expression to permit the '-' character in a command. Thanks!
91
103
 
92
- 2010-03-11 (11 MAR 2010) VERSION 3.0.3 Aaron D. Gifford (http://www.aarongifford.com)
104
+ 2010-03-11 (11 MAR 2010) VERSION 3.0.3 Aaron D. Gifford (https://aarongifford.com)
93
105
  * Bug fix to lib/mtik.rb command() method so when executing multiple commands
94
106
  response array order matches command array order.
95
107
  * Cosmetic change for hex encoding with a little simplification, and one very small
96
108
  readability change in lib/mtik/connection.rb
97
109
 
98
- 2010-02-05 (05 FEB 2010) VERSION 3.0.2 Aaron D. Gifford (http://www.aarongifford.com)
110
+ 2010-02-05 (05 FEB 2010) VERSION 3.0.2 Aaron D. Gifford (https://aarongifford.com)
99
111
  * Typo fixes to example tikfetch.rb
100
112
  * Multi-command functionality added to interactive client and to tikcommand.rb example
101
113
  * Removed kludge path stuff for author's broken FreeBSD Ruby 1.9.1 gem system
102
114
  * Removed lame JSON-ifier from example and switched to require 'json' instead
103
115
 
104
- 2010-01-19 (19 JAN 2010) VERSION 3.0.1 Aaron D. Gifford (http://www.aarongifford.com/)
116
+ 2010-01-19 (19 JAN 2010) VERSION 3.0.1 Aaron D. Gifford (https://aarongifford.com/)
105
117
  * Added support for '/tool/fetch' 'requesting' state
106
118
  * Added auto-cancel of finished '/tool/fetch' command in MTik#command()
107
119
  * Added MTik::Request#cancel() method
@@ -114,7 +126,7 @@
114
126
  messed-up FreeBSD Ruby 1.9 installation
115
127
  * Renamed examples with a 'tik' prefix
116
128
 
117
- 2010-01-15 (15 JAN 2010) VERSION 3.0.0 Aaron D. Gifford (http://www.aarongifford.com/)
129
+ 2010-01-15 (15 JAN 2010) VERSION 3.0.0 Aaron D. Gifford (https://aarongifford.com/)
118
130
  * Bumped the version to 3.0.0 due to modularization and gemification changes
119
131
  that break any software using the older Ruby API classes.
120
132
  * Split out (as separate files) and added a few more examples:
@@ -1,11 +1,11 @@
1
1
  ########################################################################
2
2
  #--
3
3
  #
4
- # GEM: MTik -- A Ruby gem implementing the MikroTik RouterOS API
4
+ # GEM: MTik -- A Ruby gem implementing the MikroTik RouterOS API
5
5
  #
6
6
  #++
7
- # Author:: Aaron D. Gifford - http://www.aarongifford.com/
8
- # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
7
+ # Author:: Aaron D. Gifford - https://aarongifford.com/
8
+ # Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
9
9
  # License:: BSD license
10
10
  #--
11
11
  # Redistribution and use in source and binary forms, with or without
data/README.txt CHANGED
@@ -6,48 +6,48 @@ devices running RouterOS (with the API enabled) over the network.
6
6
 
7
7
  == Examples
8
8
 
9
- Included in the examples subdirectory are four example ruby scripts
9
+ Included in the bin subdirectory are four example ruby scripts
10
10
  that use the Ruby API implementation:
11
11
 
12
- tikcli.rb:: A command-line-like API interface
13
- tikcommand.rb:: A tool for executing a single API command from
14
- a unix command-line
15
- tikfetch.rb:: A tool for instructing devices to download files
16
- from specified URLs (unix command-line tool)
17
- tikjson.rb:: Like 'command.rb' a tool for executing a single
18
- API command, except the output is formatted in
19
- JSON-style
12
+ tikcli:: A command-line-like API interface
13
+ tikcommand:: A tool for executing a single API command from
14
+ a unix command-line
15
+ tikfetch:: A tool for instructing devices to download files
16
+ from specified URLs (unix command-line tool)
17
+ tikjson:: Like 'tikcommand' a tool for executing a single
18
+ API command, except the output is formatted in
19
+ JSON-style
20
20
 
21
21
 
22
22
  == Download
23
23
 
24
24
  The latest version of MTik can be found at
25
25
 
26
- * http://www.aarongifford.com/computers/mtik/
26
+ * https://aarongifford.com/computers/mtik/
27
27
 
28
28
  Ruby RDoc documentation can be found online at
29
29
 
30
- * http://www.aarongifford.com/computers/mtik/latest/doc/
30
+ * https://aarongifford.com/computers/mtik/doc/
31
31
 
32
32
  Additional documentation is available at
33
33
 
34
- * http://www.aarongifford.com/computers/mtik/
35
- * http://wiki.mikrotik.com/wiki/API_Ruby_class
34
+ * https://aarongifford.com/computers/mtik/
35
+ * https://wiki.mikrotik.com/wiki/API_Ruby_class
36
36
 
37
37
  Source code is available on GitHub:
38
38
 
39
- * http://www.github.com/astounding/mtik/
39
+ * https://www.github.com/astounding/mtik/
40
40
 
41
- For documentation on the MikroTik RouterOS APi, see
41
+ For documentation on the MikroTik RouterOS API, see
42
42
 
43
- * http://wiki.mikrotik.com/wiki/API
43
+ * https://wiki.mikrotik.com/wiki/API
44
44
 
45
45
 
46
46
  == Installation
47
47
 
48
48
  To install MTik is through its GEM file:
49
49
 
50
- % [sudo] gem install mtik-4.0.0.gem
50
+ % [sudo] gem install mtik-4.1.1.gem
51
51
 
52
52
  == License
53
53
 
@@ -59,13 +59,13 @@ under a BSD-style license. (See the LICENSE.txt file.)
59
59
 
60
60
  Bugs/issues may also be reported via GitHub:
61
61
 
62
- * http://www.github.com/astounding/mtik/issues/
62
+ * https://www.github.com/astounding/mtik/issues/
63
63
 
64
64
  ALSO, please send the author a note regarding the issue by clicking on the
65
65
  "Contact Me" link in the left-hand menu of the author's web site.
66
66
  The direct URL is:
67
67
 
68
- * http://www.aarongifford.com/leaveanote.html
68
+ * https://aarongifford.com/leaveanote.html
69
69
 
70
70
  Thank you!
71
71
 
@@ -1 +1 @@
1
- 4.1.0
1
+ 4.1.1
data/bin/tikcli CHANGED
@@ -2,11 +2,11 @@
2
2
  ########################################################################
3
3
  #--
4
4
  #
5
- # FILE: tikcli.rb -- Example of using the Ruby MikroTik API in Ruby
5
+ # FILE: tikcli -- Example of using the Ruby MikroTik API in Ruby
6
6
  #
7
7
  #++
8
- # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
8
+ # Author:: Aaron D. Gifford - https://aarongifford.com/
9
+ # Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -42,13 +42,14 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
42
42
  require 'rubygems'
43
43
  require 'mtik'
44
44
 
45
+
45
46
  def usage(msg='')
46
47
  STDERR.print(
47
48
  (msg.size > 0 ? msg + "\n\n" : '') +
48
- "Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] <host> <user> <pass>\n" +
49
+ "Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] <host> <user> <pass>\n" +
50
+ " --ssl OR -s - Use SSL for the API connection.\n" +
49
51
  " --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
50
- " using SSL.\n" +
51
- " --ssl OR -s - Use SSL for the API connection.\n"
52
+ " using SSL.\n"
52
53
  )
53
54
  exit(-1)
54
55
  end
@@ -74,6 +75,9 @@ usage("Insufficient arguments.") if ARGV.size < 3
74
75
  use_ssl = true if ENV['MTIK_SSL']
75
76
  unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
76
77
 
78
+ ## NOTE: We IGNORE environment variable MTIK_VERBOSE mode as this script
79
+ ## ALWAYS uses verbose mode.
80
+
77
81
  args = {
78
82
  :host => ARGV[0],
79
83
  :user => ARGV[1],
@@ -2,11 +2,11 @@
2
2
  ########################################################################
3
3
  #--
4
4
  #
5
- # FILE: command.rb -- Example of using the Ruby MikroTik API in Ruby
5
+ # FILE: tikcommand -- Example of using the Ruby MikroTik API in Ruby
6
6
  #
7
7
  #++
8
- # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
8
+ # Author:: Aaron D. Gifford - https://aarongifford.com/
9
+ # Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -42,20 +42,21 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
42
42
  require 'rubygems'
43
43
  require 'mtik'
44
44
 
45
+
45
46
  def usage(msg='')
46
47
  STDERR.print(
47
48
  (msg.size > 0 ? msg + "\n\n" : '') +
48
- "Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] <host> <user> <pass> <command> [<args>...] [<command> [<args> ...]]\n" +
49
+ "Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] [-v|--verbose] <host> <user> <pass> <command> [<args>...] [<command> [<args> ...]]\n" +
49
50
  " --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
50
51
  " using SSL.\n" +
51
- " --ssl OR -s - Use SSL for the API connection.\n"
52
+ " --ssl OR -s - Use SSL for the API connection.\n" +
53
+ " --verbose OR -v - Enable verbose output via STDERR.\n"
52
54
  )
53
55
  exit(-1)
54
56
  end
55
57
 
56
- MTik::verbose = true ## Set how verbose you want things
57
58
 
58
- use_ssl = unencrypted_plaintext = false
59
+ use_ssl = unencrypted_plaintext = verbose = false
59
60
  while !ARGV[0].nil? && ARGV[0][0] == '-'
60
61
  arg = ARGV.shift
61
62
  case arg
@@ -65,6 +66,9 @@ while !ARGV[0].nil? && ARGV[0][0] == '-'
65
66
  when '--unencrypted_plaintext', '-u'
66
67
  usage("Please do not repeat the --unencrypted_plaintext (or -u) parameter") if unencrypted_plaintext
67
68
  unencrypted_plaintext = true
69
+ when '--verbose', '-v'
70
+ usage("Please do not repeat the --verbose (or -v) parameter") if use_ssl
71
+ verbose = true
68
72
  else
69
73
  usage("Unknown argument #{arg.inspect}")
70
74
  end
@@ -75,6 +79,9 @@ usage("First command must start with a slash '/' character. #{ARGV[3].inspect}")
75
79
  ## Permit setting use_ssl and unencrypted_plaintext via environment variables:
76
80
  use_ssl = true if ENV['MTIK_SSL']
77
81
  unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
82
+ verbose = true if ENV['MTIK_VERBOSE']
83
+
84
+ MTik::verbose = verbose
78
85
 
79
86
  ## Detect multiple command sequences and build an array of arrays
80
87
  ## where each outer array element is a command plus arguments:
@@ -2,11 +2,11 @@
2
2
  ########################################################################
3
3
  #--
4
4
  #
5
- # FILE: fetch.rb -- Example of using the Ruby MikroTik API in Ruby
5
+ # FILE: tikfetch -- Example of using the Ruby MikroTik API in Ruby
6
6
  #
7
7
  #++
8
- # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
8
+ # Author:: Aaron D. Gifford - https://aarongifford.com/
9
+ # Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -42,22 +42,20 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
42
42
  require 'rubygems'
43
43
  require 'mtik'
44
44
 
45
- ## Uncomment this (set $VERBOSE to true) if you want crazy verbose
46
- ## output of all API interactions:
47
- #MTik::verbose = true
48
45
 
49
46
  def usage(msg='')
50
47
  STDERR.print(
51
48
  (msg.size > 0 ? msg + "\n\n" : '') +
52
- "Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] <device> <user> <pass> <url> [<localfilename> [<url> [<localfilename> ... ]]]\n" +
49
+ "Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] [-v|--verbose] <device> <user> <pass> <url> [<localfilename> [<url> [<localfilename> ... ]]]\n" +
53
50
  " --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
54
51
  " using SSL.\n" +
55
- " --ssl OR -s - Use SSL for the API connection.\n"
52
+ " --ssl OR -s - Use SSL for the API connection.\n" +
53
+ " --verbose OR -v - Enable verbose output via STDOUT.\n"
56
54
  )
57
55
  exit(-1)
58
56
  end
59
57
 
60
- use_ssl = unencrypted_plaintext = false
58
+ use_ssl = unencrypted_plaintext = verbose = false
61
59
  while !ARGV[0].nil? && ARGV[0][0] == '-'
62
60
  arg = ARGV.shift
63
61
  case arg
@@ -67,6 +65,9 @@ while !ARGV[0].nil? && ARGV[0][0] == '-'
67
65
  when '--unencrypted_plaintext', '-u'
68
66
  usage("Please do not repeat the --unencrypted_plaintext (or -u) parameter") if unencrypted_plaintext
69
67
  unencrypted_plaintext = true
68
+ when '--verbose', '-v'
69
+ usage("Please do not repeat the --verbose (or -v) parameter") if verbose
70
+ verbose = true
70
71
  else
71
72
  usage("Unknown argument #{arg.inspect}")
72
73
  end
@@ -76,6 +77,9 @@ usage("Too few arguments.") if ARGV.size < 4
76
77
  ## Permit setting use_ssl and unencrypted_plaintext via environment variables:
77
78
  use_ssl = true if ENV['MTIK_SSL']
78
79
  unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
80
+ verbose = true if ENV['MTIK_VERBOSE']
81
+
82
+ MTik::verbose = verbose
79
83
 
80
84
  args = {
81
85
  :host => ARGV.shift,
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+ ########################################################################
3
+ #--
4
+ #
5
+ # FILE: tikjson -- Example of using the Ruby MikroTik API in Ruby
6
+ # to execute an API command and retrieve results
7
+ # in JSON format
8
+ #
9
+ #++
10
+ # Author:: Aaron D. Gifford - https://aarongifford.com/
11
+ # Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
12
+ # License:: BSD license
13
+ #--
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions
16
+ # are met:
17
+ # 1. Redistributions of source code must retain the above copyright
18
+ # notice, the above list of authors and contributors, this list of
19
+ # conditions and the following disclaimer.
20
+ # 2. Redistributions in binary form must reproduce the above copyright
21
+ # notice, this list of conditions and the following disclaimer in the
22
+ # documentation and/or other materials provided with the distribution.
23
+ # 3. Neither the name of the author(s) or copyright holder(s) nor the
24
+ # names of any contributors may be used to endorse or promote products
25
+ # derived from this software without specific prior written permission.
26
+ #
27
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S), AUTHOR(S) AND
28
+ # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
29
+ # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
30
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
31
+ # IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), AUTHOR(S), OR CONTRIBUTORS BE
32
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33
+ # DCONSEQUENTIAL AMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
38
+ # THE POSSIBILITY OF SUCH DAMAGE.
39
+ ########################################################################
40
+ # encoding: ASCII-8BIT
41
+
42
+ $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
43
+
44
+ require 'rubygems'
45
+ require 'mtik'
46
+ require 'json'
47
+
48
+
49
+ def usage(msg='')
50
+ STDERR.print(
51
+ (msg.size > 0 ? msg + "\n\n" : '') +
52
+ "Usage: #{$0} [-p|--pretty] [-s|--ssl] [-u|--unencrypted_plaintext] [-v|--verbose] <host> <user> <pass> <command> [<args>...] [<command> [<args> ...]]\n" +
53
+ " --pretty OR -p - Output JSON using JSON.pretty_generate()\n" +
54
+ " --ssl OR -s - Use SSL for the API connection.\n" +
55
+ " --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
56
+ " using SSL.\n" +
57
+ " --verbose OR -v - Enable verbose output to STDERR.\n"
58
+ )
59
+ exit(-1)
60
+ end
61
+
62
+ use_ssl = unencrypted_plaintext = pretty = verbose = false
63
+ while !ARGV[0].nil? && ARGV[0][0] == '-'
64
+ arg = ARGV.shift
65
+ case arg
66
+ when '--pretty', '-p'
67
+ usage("Please do not repeat the --pretty (or -p) parameter") if pretty
68
+ pretty = true
69
+ when '--ssl', '-s'
70
+ usage("Please do not repeat the --ssl (or -s) parameter") if use_ssl
71
+ use_ssl = true
72
+ when '--unencrypted_plaintext', '-u'
73
+ usage("Please do not repeat the --unencrypted_plaintext (or -u) parameter") if unencrypted_plaintext
74
+ unencrypted_plaintext = true
75
+ when '--verbose', '-v'
76
+ usage("Please do not repeat the --verbose (or -v) parameter") if verbose
77
+ verbose = true
78
+ else
79
+ usage("Unknown argument #{arg.inspect}")
80
+ end
81
+ end
82
+ usage("Too few arguments.") if ARGV.size < 4
83
+ usage("First command must start with a slash '/' character. #{ARGV[3].inspect}") if ARGV[3].nil? || ARGV[3][0] != '/'
84
+
85
+ ## Permit setting use_ssl and unencrypted_plaintext via environment variables:
86
+ use_ssl = true if ENV['MTIK_SSL']
87
+ unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
88
+ verbose = true if ENV['MTIK_VERBOSE']
89
+
90
+ MTik::verbose = verbose
91
+
92
+ ## Detect multiple command sequences and build an array of arrays
93
+ ## where each outer array element is a command plus arguments:
94
+ command = Array.new
95
+ i = 3
96
+ while i < ARGV.length
97
+ if ARGV[i][0,1] == '/' ## Command detected...
98
+ command << [ ARGV[i] ]
99
+ else
100
+ command[command.length-1] << ARGV[i]
101
+ end
102
+ i += 1
103
+ end
104
+
105
+ args = {
106
+ :host => ARGV[0],
107
+ :user => ARGV[1],
108
+ :pass => ARGV[2],
109
+ :command => command,
110
+ :ssl => use_ssl,
111
+ :unencrypted_plaintext => unencrypted_plaintext
112
+ }
113
+
114
+ if pretty
115
+ puts JSON.pretty_generate(MTik::command(args))
116
+ else
117
+ print MTik::command(args).to_json + "\n"
118
+ end
119
+
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -1,8 +1,8 @@
1
1
  ############################################################################
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
- ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
4
+ ## Author:: Aaron D. Gifford - https://aarongifford.com/
5
+ ## Copyright:: Copyright (c) 2009-2020, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtik
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron D. Gifford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-22 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: MTik implements the MikroTik RouterOS API for use in Ruby.
14
14
  email: email_not_accepted@aarongifford.com
@@ -28,7 +28,7 @@ files:
28
28
  - bin/tikcli
29
29
  - bin/tikcommand
30
30
  - bin/tikfetch
31
- - examples/tikjson.rb
31
+ - bin/tikjson
32
32
  - lib/mtik.rb
33
33
  - lib/mtik/connection.rb
34
34
  - lib/mtik/error.rb
@@ -36,7 +36,7 @@ files:
36
36
  - lib/mtik/reply.rb
37
37
  - lib/mtik/request.rb
38
38
  - lib/mtik/timeouterror.rb
39
- homepage: http://www.aarongifford.com/computers/mtik/
39
+ homepage: https://aarongifford.com/computers/mtik/
40
40
  licenses: []
41
41
  metadata: {}
42
42
  post_install_message:
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env ruby
2
- ########################################################################
3
- #--
4
- #
5
- # FILE: tikjson.rb -- Example of using the Ruby MikroTik API in Ruby
6
- # to execute an API command and retrieve results
7
- # in JSON format
8
- #
9
- #++
10
- # Author:: Aaron D. Gifford - http://www.aarongifford.com/
11
- # Copyright:: Copyright (c) 2009-2014, InfoWest, Inc.
12
- # License:: BSD license
13
- #--
14
- # Redistribution and use in source and binary forms, with or without
15
- # modification, are permitted provided that the following conditions
16
- # are met:
17
- # 1. Redistributions of source code must retain the above copyright
18
- # notice, the above list of authors and contributors, this list of
19
- # conditions and the following disclaimer.
20
- # 2. Redistributions in binary form must reproduce the above copyright
21
- # notice, this list of conditions and the following disclaimer in the
22
- # documentation and/or other materials provided with the distribution.
23
- # 3. Neither the name of the author(s) or copyright holder(s) nor the
24
- # names of any contributors may be used to endorse or promote products
25
- # derived from this software without specific prior written permission.
26
- #
27
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S), AUTHOR(S) AND
28
- # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
29
- # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
30
- # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
31
- # IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), AUTHOR(S), OR CONTRIBUTORS BE
32
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33
- # DCONSEQUENTIAL AMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36
- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
38
- # THE POSSIBILITY OF SUCH DAMAGE.
39
- ########################################################################
40
- # encoding: ASCII-8BIT
41
-
42
- $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
43
-
44
- require 'rubygems'
45
- require 'mtik'
46
- require 'json'
47
-
48
- unless ARGV.length > 3
49
- STDERR.print("Usage: #{$0} <host> <user> <pass> <command> [<args>...] [<command> [<args> ...]]\n")
50
- exit(-1)
51
- end
52
-
53
- ## Detect multiple command sequences and build an array of arrays
54
- ## where each outer array element is a command plus arguments:
55
- command = Array.new
56
- i = 3
57
- while i < ARGV.length
58
- if ARGV[i][0,1] == '/' ## Command detected...
59
- command << [ ARGV[i] ]
60
- else
61
- command[command.length-1] << ARGV[i]
62
- end
63
- i += 1
64
- end
65
-
66
- print MTik::command(
67
- :host=>ARGV[0],
68
- :user=>ARGV[1],
69
- :pass=>ARGV[2],
70
- :command=>command
71
- ).to_json + "\n"
72
-