mtik 4.0.2 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.txt +52 -13
- data/LICENSE.txt +3 -3
- data/README.txt +19 -19
- data/Rakefile +1 -32
- data/VERSION.txt +1 -1
- data/bin/tikcli +46 -6
- data/bin/tikcommand +50 -12
- data/bin/tikfetch +50 -13
- data/bin/tikjson +119 -0
- data/lib/mtik.rb +40 -24
- data/lib/mtik/connection.rb +159 -55
- data/lib/mtik/error.rb +2 -2
- data/lib/mtik/fatalerror.rb +2 -2
- data/lib/mtik/reply.rb +2 -2
- data/lib/mtik/request.rb +2 -2
- data/lib/mtik/timeouterror.rb +2 -2
- metadata +13 -16
- data/examples/tikjson.rb +0 -70
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69ac4aa4e71fb42516c3f6251de37e64a1041ad5f47f6c95548e601e451f8475
|
4
|
+
data.tar.gz: 3003d97eefc4abe69bf3e0e708e47426cd88ca1ac70c7130ccf8336c14ede4c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ecee89ebbb4ad1f19ed5ddee719883ad0f7612157650487019dbd607580dfbab274c29c07567016b71a1695ef493c6e24358e13d2ccffb89a16adb3855de54c
|
7
|
+
data.tar.gz: f59ffc39d06615562f676499ed1a672be907e95e9d55589c472081c78ccf0670ba024821d4625782dcb2bf7bf1f1d20cead2303e4095d459ed6aeca98a755229
|
data/CHANGELOG.txt
CHANGED
@@ -1,15 +1,54 @@
|
|
1
|
-
|
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
|
+
|
13
|
+
2020-08-23 (23 AUG 2020) VERSION 4.1.0
|
14
|
+
* Minor version bump due to changing argument passing for the call to
|
15
|
+
MTik.interactive_client()
|
16
|
+
* Updated tikcli, tikcommand, and tikfetch commands to add options for
|
17
|
+
enabling SSL and/or to use unencrypted plaintext logins (newer API
|
18
|
+
login style). Also one can set environment variables MTIK_SSL to
|
19
|
+
specify SSL use, or MTIK_UNENCRYPTED_PLAINTEXT to enable unencrypted
|
20
|
+
plaintext logins if SSL is NOT used for compatibility with cleartext
|
21
|
+
API usage on RouterOS versions 6.43+
|
22
|
+
* THANKS to Zdenek Crha (zdenek-crha on github) for pointing out that
|
23
|
+
the binary commands were lacking proper argument passing to allow
|
24
|
+
for SSL and/or unencrypted plaintext options, and for suggesting the
|
25
|
+
use of environment variables as an alterative to CLI options for
|
26
|
+
enabling such.
|
27
|
+
|
28
|
+
2020-08-22 (22 AUG 2020) VERSION 4.0.5
|
29
|
+
* This is a cosmetic version bump for the purpose of updating the gem for wider
|
30
|
+
availability via rubygems in addition to directly from github prior to some
|
31
|
+
coming feature updates and fixes for newer versions of RouterOS
|
32
|
+
|
33
|
+
2019-07-26 (26 JUL 2020) VERSION 4.0.4 Adam Kubica (github user xcr)
|
34
|
+
* Adam bumped the version number and separated out a gemspec file
|
35
|
+
* Jiacheng (github user krhougs) had submitted a similar update as Adam
|
36
|
+
|
37
|
+
2014-02-14 (14 FEB 2014) VERSION 4.0.3 Aaron D. Gifford (https://aarongifford.com)
|
38
|
+
* Update to fetch() utility, along with some very minor some cosmetic changes
|
39
|
+
|
40
|
+
2013-06-06 (06 JUN 2013) VERSION 4.0.2 Aaron D. Gifford (https://aarongifford.com)
|
2
41
|
Bart Braem (http://www.lalunerouge.net/)
|
3
42
|
* Merged Bart Braem's implementation of timeouts and bumped up the version. Thanks, Bart!
|
4
43
|
* Updated Rakefile to remove a bit of obsolescence
|
5
44
|
|
6
|
-
2012-02-09 (09 FEB 2012) VERSION 4.0.1 Aaron D. Gifford (
|
45
|
+
2012-02-09 (09 FEB 2012) VERSION 4.0.1 Aaron D. Gifford (https://aarongifford.com)
|
7
46
|
* Added os_version to connections. Upon successful connect and login, the RouterOS
|
8
47
|
version is fetched and stored. This will allow future updates to better support
|
9
48
|
some commands that differ (like fetch) depending on which RouterOS version is
|
10
49
|
installed on the device.
|
11
50
|
|
12
|
-
2011-03-25 (25 MAR 2011) VERSION 4.0.0 Aaron D. Gifford (
|
51
|
+
2011-03-25 (25 MAR 2011) VERSION 4.0.0 Aaron D. Gifford (https://aarongifford.com)
|
13
52
|
* Per user suggestion, added a new optional cancel parameter to the MTik#command()
|
14
53
|
method that will auto-cancel the supplied command after receiving the specified
|
15
54
|
number of '!re' reply sentences. This is usful for executing a command that otherwise
|
@@ -25,7 +64,7 @@
|
|
25
64
|
eliminated a few redundant key?() calls, and fixed a replycounter initialization
|
26
65
|
typo (had set it to 1 instead of 0).
|
27
66
|
|
28
|
-
2011-01-11 (11 JAN 2011) VERSION 3.1.2 Aaron D. Gifford (
|
67
|
+
2011-01-11 (11 JAN 2011) VERSION 3.1.2 Aaron D. Gifford (https://aarongifford.com)
|
29
68
|
* Added source file encoding comments and updated the copyright notices
|
30
69
|
* Fixed a tiny bug in lib/mtik/connection.rb
|
31
70
|
* Changed MTik::Request@state member in lib/mtik/request.rb to Symbol instead of String
|
@@ -34,12 +73,12 @@
|
|
34
73
|
* Renamed a few variables that, with warnings enabled, Ruby complained were overlapping
|
35
74
|
or hiding outer variables of the same name to avoid the warning.
|
36
75
|
|
37
|
-
2010-12-30 (30 DEC 2011) VERSION 3.1.1 Aaron D. Gifford (
|
76
|
+
2010-12-30 (30 DEC 2011) VERSION 3.1.1 Aaron D. Gifford (https://aarongifford.com)
|
38
77
|
* Changed the tikfetch.rb utility so it no longer requires a destination filename
|
39
78
|
by default--it will use the supplied URL's final path element as a filename. Also
|
40
79
|
updated the stats output a bit.
|
41
80
|
|
42
|
-
2010-04-24 (24 APR 2010) VERSION 3.1.0 Aaron D. Gifford (
|
81
|
+
2010-04-24 (24 APR 2010) VERSION 3.1.0 Aaron D. Gifford (https://aarongifford.com)
|
43
82
|
* Added find_sentences() method to MTik::Reply -- just sugar to Array.select()
|
44
83
|
* Changed MTik::Connection.fetch() method to add an optional timeout parameter
|
45
84
|
which should not affect the API and should be backward compatible. By default,
|
@@ -53,28 +92,28 @@
|
|
53
92
|
command if needed. Due to this change, I decided to bump the version to 3.1.0.
|
54
93
|
* Fixed RDoc formatting in several files, and added an RDocTask to the Rakefile
|
55
94
|
|
56
|
-
2010-04-23 (23 APR 2010) VERSION 3.0.5 Aaron D. Gifford (
|
57
|
-
* Double bug-fix (typo fix and logic fix) to request.rb thanks to Allan Eising and
|
95
|
+
2010-04-23 (23 APR 2010) VERSION 3.0.5 Aaron D. Gifford (https://aarongifford.com)
|
96
|
+
* Double bug-fix (typo fix and logic fix) to request.rb thanks to Allan Eising and
|
58
97
|
Søren Daugaard. Thank you both for the patch!
|
59
98
|
* Added a brief sanity-check in request.rb to help spotlight logic errors.
|
60
99
|
|
61
|
-
2010-04-09 (09 APR 2010) VERSION 3.0.4 Aaron D. Gifford (
|
100
|
+
2010-04-09 (09 APR 2010) VERSION 3.0.4 Aaron D. Gifford (https://aarongifford.com)
|
62
101
|
* Bug fix to lib/mtik.rb thanks to Allan Eising to the command validation regular
|
63
102
|
expression to permit the '-' character in a command. Thanks!
|
64
103
|
|
65
|
-
2010-03-11 (11 MAR 2010) VERSION 3.0.3 Aaron D. Gifford (
|
104
|
+
2010-03-11 (11 MAR 2010) VERSION 3.0.3 Aaron D. Gifford (https://aarongifford.com)
|
66
105
|
* Bug fix to lib/mtik.rb command() method so when executing multiple commands
|
67
106
|
response array order matches command array order.
|
68
107
|
* Cosmetic change for hex encoding with a little simplification, and one very small
|
69
108
|
readability change in lib/mtik/connection.rb
|
70
109
|
|
71
|
-
2010-02-05 (05 FEB 2010) VERSION 3.0.2 Aaron D. Gifford (
|
110
|
+
2010-02-05 (05 FEB 2010) VERSION 3.0.2 Aaron D. Gifford (https://aarongifford.com)
|
72
111
|
* Typo fixes to example tikfetch.rb
|
73
112
|
* Multi-command functionality added to interactive client and to tikcommand.rb example
|
74
113
|
* Removed kludge path stuff for author's broken FreeBSD Ruby 1.9.1 gem system
|
75
114
|
* Removed lame JSON-ifier from example and switched to require 'json' instead
|
76
115
|
|
77
|
-
2010-01-19 (19 JAN 2010) VERSION 3.0.1 Aaron D. Gifford (
|
116
|
+
2010-01-19 (19 JAN 2010) VERSION 3.0.1 Aaron D. Gifford (https://aarongifford.com/)
|
78
117
|
* Added support for '/tool/fetch' 'requesting' state
|
79
118
|
* Added auto-cancel of finished '/tool/fetch' command in MTik#command()
|
80
119
|
* Added MTik::Request#cancel() method
|
@@ -87,7 +126,7 @@
|
|
87
126
|
messed-up FreeBSD Ruby 1.9 installation
|
88
127
|
* Renamed examples with a 'tik' prefix
|
89
128
|
|
90
|
-
2010-01-15 (15 JAN 2010) VERSION 3.0.0 Aaron D. Gifford (
|
129
|
+
2010-01-15 (15 JAN 2010) VERSION 3.0.0 Aaron D. Gifford (https://aarongifford.com/)
|
91
130
|
* Bumped the version to 3.0.0 due to modularization and gemification changes
|
92
131
|
that break any software using the older Ruby API classes.
|
93
132
|
* Split out (as separate files) and added a few more examples:
|
data/LICENSE.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
########################################################################
|
2
2
|
#--
|
3
3
|
#
|
4
|
-
# GEM:
|
4
|
+
# GEM: MTik -- A Ruby gem implementing the MikroTik RouterOS API
|
5
5
|
#
|
6
6
|
#++
|
7
|
-
# Author:: Aaron D. Gifford -
|
8
|
-
# Copyright:: Copyright (c) 2009-
|
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
|
9
|
+
Included in the bin subdirectory are four example ruby scripts
|
10
10
|
that use the Ruby API implementation:
|
11
11
|
|
12
|
-
tikcli
|
13
|
-
tikcommand
|
14
|
-
|
15
|
-
tikfetch
|
16
|
-
|
17
|
-
tikjson
|
18
|
-
|
19
|
-
|
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
|
-
*
|
26
|
+
* https://aarongifford.com/computers/mtik/
|
27
27
|
|
28
28
|
Ruby RDoc documentation can be found online at
|
29
29
|
|
30
|
-
*
|
30
|
+
* https://aarongifford.com/computers/mtik/doc/
|
31
31
|
|
32
32
|
Additional documentation is available at
|
33
33
|
|
34
|
-
*
|
35
|
-
*
|
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
|
-
*
|
39
|
+
* https://www.github.com/astounding/mtik/
|
40
40
|
|
41
|
-
For documentation on the MikroTik RouterOS
|
41
|
+
For documentation on the MikroTik RouterOS API, see
|
42
42
|
|
43
|
-
*
|
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.
|
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
|
-
*
|
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
|
-
*
|
68
|
+
* https://aarongifford.com/leaveanote.html
|
69
69
|
|
70
70
|
Thank you!
|
71
71
|
|
data/Rakefile
CHANGED
@@ -2,38 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rubygems/package_task'
|
3
3
|
require 'rdoc/task'
|
4
4
|
|
5
|
-
gemspec = Gem::Specification.
|
6
|
-
spec.name = 'mtik'
|
7
|
-
spec.version = File.open('VERSION.txt','r').to_a.join.strip
|
8
|
-
spec.date = File.mtime('VERSION.txt')
|
9
|
-
spec.author = 'Aaron D. Gifford'
|
10
|
-
spec.email = 'email_not_accepted@aarongifford.com'
|
11
|
-
spec.homepage = 'http://www.aarongifford.com/computers/mtik/'
|
12
|
-
spec.summary = 'MTik implements the MikroTik RouterOS API for use in Ruby.'
|
13
|
-
spec.description = 'MTik implements the MikroTik RouterOS API for use in Ruby.'
|
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/tikjson.rb',
|
24
|
-
'bin/tikcli',
|
25
|
-
'bin/tikcommand',
|
26
|
-
'bin/tikfetch',
|
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
|
-
spec.executables = [ 'tikcli', 'tikcommand', 'tikfetch' ]
|
36
|
-
end
|
5
|
+
gemspec = Gem::Specification.load('mtik.gemspec')
|
37
6
|
|
38
7
|
Gem::PackageTask.new(gemspec) do |pkg|
|
39
8
|
pkg.need_zip = true
|
data/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.
|
1
|
+
4.1.1
|
data/bin/tikcli
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
########################################################################
|
3
3
|
#--
|
4
4
|
#
|
5
|
-
# FILE:
|
5
|
+
# FILE: tikcli -- Example of using the Ruby MikroTik API in Ruby
|
6
6
|
#
|
7
7
|
#++
|
8
|
-
# Author:: Aaron D. Gifford -
|
9
|
-
# Copyright:: Copyright (c) 2009-
|
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,10 +42,50 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
|
|
42
42
|
require 'rubygems'
|
43
43
|
require 'mtik'
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
def usage(msg='')
|
47
|
+
STDERR.print(
|
48
|
+
(msg.size > 0 ? msg + "\n\n" : '') +
|
49
|
+
"Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] <host> <user> <pass>\n" +
|
50
|
+
" --ssl OR -s - Use SSL for the API connection.\n" +
|
51
|
+
" --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
|
52
|
+
" using SSL.\n"
|
53
|
+
)
|
47
54
|
exit(-1)
|
48
55
|
end
|
49
56
|
|
50
|
-
|
57
|
+
use_ssl = unencrypted_plaintext = false
|
58
|
+
while !ARGV[0].nil? && ARGV[0][0] == '-'
|
59
|
+
arg = ARGV.shift
|
60
|
+
case arg
|
61
|
+
when '--ssl', '-s'
|
62
|
+
usage("Please do not repeat the --ssl (or -s) parameter") if use_ssl
|
63
|
+
use_ssl = true
|
64
|
+
when '--unencrypted_plaintext', '-u'
|
65
|
+
usage("Please do not repeat the --unencrypted_plaintext (or -u) parameter") if unencrypted_plaintext
|
66
|
+
unencrypted_plaintext = true
|
67
|
+
else
|
68
|
+
usage("Unknown argument #{arg.inspect}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
usage("Too many arguments.") if ARGV.size > 3
|
72
|
+
usage("Insufficient arguments.") if ARGV.size < 3
|
73
|
+
|
74
|
+
## Permit setting use_ssl and unencrypted_plaintext via environment variables:
|
75
|
+
use_ssl = true if ENV['MTIK_SSL']
|
76
|
+
unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
|
77
|
+
|
78
|
+
## NOTE: We IGNORE environment variable MTIK_VERBOSE mode as this script
|
79
|
+
## ALWAYS uses verbose mode.
|
80
|
+
|
81
|
+
args = {
|
82
|
+
:host => ARGV[0],
|
83
|
+
:user => ARGV[1],
|
84
|
+
:pass => ARGV[2],
|
85
|
+
:ssl => use_ssl,
|
86
|
+
:unencrypted_plaintext => unencrypted_plaintext
|
87
|
+
}
|
88
|
+
p args
|
89
|
+
|
90
|
+
MTik::interactive_client(args)
|
51
91
|
|
data/bin/tikcommand
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
########################################################################
|
3
3
|
#--
|
4
4
|
#
|
5
|
-
# FILE:
|
5
|
+
# FILE: tikcommand -- Example of using the Ruby MikroTik API in Ruby
|
6
6
|
#
|
7
7
|
#++
|
8
|
-
# Author:: Aaron D. Gifford -
|
9
|
-
# Copyright:: Copyright (c) 2009-
|
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,12 +42,46 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
|
|
42
42
|
require 'rubygems'
|
43
43
|
require 'mtik'
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
def usage(msg='')
|
47
|
+
STDERR.print(
|
48
|
+
(msg.size > 0 ? msg + "\n\n" : '') +
|
49
|
+
"Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] [-v|--verbose] <host> <user> <pass> <command> [<args>...] [<command> [<args> ...]]\n" +
|
50
|
+
" --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
|
51
|
+
" using SSL.\n" +
|
52
|
+
" --ssl OR -s - Use SSL for the API connection.\n" +
|
53
|
+
" --verbose OR -v - Enable verbose output via STDERR.\n"
|
54
|
+
)
|
47
55
|
exit(-1)
|
48
56
|
end
|
49
57
|
|
50
|
-
|
58
|
+
|
59
|
+
use_ssl = unencrypted_plaintext = verbose = false
|
60
|
+
while !ARGV[0].nil? && ARGV[0][0] == '-'
|
61
|
+
arg = ARGV.shift
|
62
|
+
case arg
|
63
|
+
when '--ssl', '-s'
|
64
|
+
usage("Please do not repeat the --ssl (or -s) parameter") if use_ssl
|
65
|
+
use_ssl = true
|
66
|
+
when '--unencrypted_plaintext', '-u'
|
67
|
+
usage("Please do not repeat the --unencrypted_plaintext (or -u) parameter") if unencrypted_plaintext
|
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
|
72
|
+
else
|
73
|
+
usage("Unknown argument #{arg.inspect}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
usage("Too few arguments.") if ARGV.size < 4
|
77
|
+
usage("First command must start with a slash '/' character. #{ARGV[3].inspect}") if ARGV[3].nil? || ARGV[3][0] != '/'
|
78
|
+
|
79
|
+
## Permit setting use_ssl and unencrypted_plaintext via environment variables:
|
80
|
+
use_ssl = true if ENV['MTIK_SSL']
|
81
|
+
unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
|
82
|
+
verbose = true if ENV['MTIK_VERBOSE']
|
83
|
+
|
84
|
+
MTik::verbose = verbose
|
51
85
|
|
52
86
|
## Detect multiple command sequences and build an array of arrays
|
53
87
|
## where each outer array element is a command plus arguments:
|
@@ -62,10 +96,14 @@ while i < ARGV.length
|
|
62
96
|
i += 1
|
63
97
|
end
|
64
98
|
|
65
|
-
|
66
|
-
:host=>ARGV[0],
|
67
|
-
:user=>ARGV[1],
|
68
|
-
:pass=>ARGV[2],
|
69
|
-
:command=>command
|
70
|
-
|
99
|
+
args = {
|
100
|
+
:host => ARGV[0],
|
101
|
+
:user => ARGV[1],
|
102
|
+
:pass => ARGV[2],
|
103
|
+
:command => command,
|
104
|
+
:ssl => use_ssl,
|
105
|
+
:unencrypted_plaintext => unencrypted_plaintext
|
106
|
+
}
|
107
|
+
|
108
|
+
p MTik::command(args)
|
71
109
|
|
data/bin/tikfetch
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
########################################################################
|
3
3
|
#--
|
4
4
|
#
|
5
|
-
# FILE:
|
5
|
+
# FILE: tikfetch -- Example of using the Ruby MikroTik API in Ruby
|
6
6
|
#
|
7
7
|
#++
|
8
|
-
# Author:: Aaron D. Gifford -
|
9
|
-
# Copyright:: Copyright (c) 2009-
|
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,56 @@ $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
|
-
|
50
|
-
print
|
51
|
-
|
46
|
+
def usage(msg='')
|
47
|
+
STDERR.print(
|
48
|
+
(msg.size > 0 ? msg + "\n\n" : '') +
|
49
|
+
"Usage: #{$0} [-s|--ssl] [-u|--unencrypted_plaintext] [-v|--verbose] <device> <user> <pass> <url> [<localfilename> [<url> [<localfilename> ... ]]]\n" +
|
50
|
+
" --unencrypted_plaintext OR -u - Use the 6.43+ login API even if NOT\n" +
|
51
|
+
" using SSL.\n" +
|
52
|
+
" --ssl OR -s - Use SSL for the API connection.\n" +
|
53
|
+
" --verbose OR -v - Enable verbose output via STDOUT.\n"
|
54
|
+
)
|
55
|
+
exit(-1)
|
56
|
+
end
|
57
|
+
|
58
|
+
use_ssl = unencrypted_plaintext = verbose = false
|
59
|
+
while !ARGV[0].nil? && ARGV[0][0] == '-'
|
60
|
+
arg = ARGV.shift
|
61
|
+
case arg
|
62
|
+
when '--ssl', '-s'
|
63
|
+
usage("Please do not repeat the --ssl (or -s) parameter") if use_ssl
|
64
|
+
use_ssl = true
|
65
|
+
when '--unencrypted_plaintext', '-u'
|
66
|
+
usage("Please do not repeat the --unencrypted_plaintext (or -u) parameter") if unencrypted_plaintext
|
67
|
+
unencrypted_plaintext = true
|
68
|
+
when '--verbose', '-v'
|
69
|
+
usage("Please do not repeat the --verbose (or -v) parameter") if verbose
|
70
|
+
verbose = true
|
71
|
+
else
|
72
|
+
usage("Unknown argument #{arg.inspect}")
|
73
|
+
end
|
52
74
|
end
|
75
|
+
usage("Too few arguments.") if ARGV.size < 4
|
76
|
+
|
77
|
+
## Permit setting use_ssl and unencrypted_plaintext via environment variables:
|
78
|
+
use_ssl = true if ENV['MTIK_SSL']
|
79
|
+
unencrypted_plaintext = true if ENV['MTIK_UNENCRYPTED_PLAINTEXT']
|
80
|
+
verbose = true if ENV['MTIK_VERBOSE']
|
81
|
+
|
82
|
+
MTik::verbose = verbose
|
83
|
+
|
84
|
+
args = {
|
85
|
+
:host => ARGV.shift,
|
86
|
+
:user => ARGV.shift,
|
87
|
+
:pass => ARGV.shift,
|
88
|
+
:ssl => use_ssl,
|
89
|
+
:unencrypted_plaintext => unencrypted_plaintext
|
90
|
+
}
|
91
|
+
|
53
92
|
|
54
|
-
host = ARGV.shift
|
55
|
-
user = ARGV.shift
|
56
|
-
pass = ARGV.shift
|
57
93
|
begin
|
58
|
-
mt = MTik::Connection.new(
|
94
|
+
mt = MTik::Connection.new(args)
|
59
95
|
rescue Errno::ETIMEDOUT, Errno::ENETUNREACH, Errno::EHOSTUNREACH, MTik::Error => e
|
60
96
|
print ">>> ERROR CONNECTING: #{e}\n"
|
61
97
|
exit
|
@@ -129,6 +165,7 @@ print "SIZE CREATED FILENAME\n"
|
|
129
165
|
print "====================================================================\n"
|
130
166
|
mt.get_reply_each('/file/getall') do |req, s|
|
131
167
|
unless s.key?('!done')
|
168
|
+
s['size'] = 'directory' if s['type'] == 'directory'
|
132
169
|
print "#{(s['size']+' ')[0,10]} #{s['creation-time']} #{s['name']}\n"
|
133
170
|
end
|
134
171
|
end
|