As you know, the developers of Mikrotik finally took up the “scripts” section and supplemented the system with a number of new commands, such as, for example, : timestamp, : rndnum. Recent versions have received :convert, :jobname, tosec, /terminal/ask. But I did not find data on these commands in the official manual. Please tell me where I can read about them.
“” is your friend, and some deduction…
The only way ?
By now you should know how MikroTik staff works…
I can’t understand how the :convert command works, what features and parameters it has ?
It’s still in beta, so they don’t doc it. In fact it change from one beta to the next. And…If stuff isn’t obvious from , that’s good feedback on a beta. Since after the equal “=” char in transform=, from=, to= — you can see the choices.
The transform= make a lot of sense. The only tricky thing is to=/from= being “raw” generally means “string”. Some examples are the release thread:
http://forum.mikrotik.com/t/v7-12beta-testing-is-released/168851/1 and http://forum.mikrotik.com/t/v7-12beta-testing-is-released/168851/1 … e.g.
:convert transform=
ed25519-private-to-ed25519-public
reverse
ed25519-private-to-x25519-private
rot13
ed25519-public-to-x25519-public
sha512
md5
x25519-private-to-x25519-public
none
:convert to=
base32 base64 hex raw url
:convert from=
base32 base64 hex raw url
Now IMO, they should hold a release to “stable” if the docs for things aren’t done – that’s another topic – but in beta no docs makes sense.
Forgive me for being stupid, but could you explain why the :convert command is needed at all? The transform parameters are reminiscent of encryption options…
Yeah the specific transform= options offered are lacking – like there is no “trim” to remove whitespace, nor transform=“sha256”, likely others.
But I think the scheme they’re using is right. The transform= applies in-between any to= or from= – but transform=none is valid and the default. So you may not need a transform= in a lot of case. The default to= and from= is “raw”, which a RouterOS string. Since RouterOS “string” can contain raw bytes like “\01\02\AA\AA”, it’s called “raw” – but still a :typeof == string.
Like base64 comes up in MIME encoding, so that work without a transform= since just encoding is needed:
:put [:convert "abcd" to=base64]
# YWJjZA==
:put [:convert from=base64 "YWJjZA==" ]
# abcd
But can be combine however you’d like…
:put [:convert from=base64 "YWJjZA==" transform=reverse]
# dcba
:put [:convert from=base64 "YWJjZA==" transform=reverse to=hex]
# 64636261
and 64 is ASCII code for “d” in hex/base16, 63 = “c”, etc.
Yeah interesting. It will probably solve many problems with various recodings and shorten scripts. Thanks a lot for the explanations.
Yeah, long way to covering all of @rextended’s transformer scripts. But being built-in would be better.
And, [:jobname] … isn’t helpful there…
That stumped me at first. The CLI terminal itself apparently doesn’t have a “jobname”, so looked like it does nothing.
:put "jobname typeof: $[:typeof [:jobname]] len: $[:len [:jobname]]"
# jobname typeof: str len: 0
But shows at /:
:jobname – return current script name
So a /system/script can use :jobname to get the script’s name:
/system script add name=log-jobname source=\
"/log info \"\$[:jobname]\""
and when run, “log-jobname” shows up in /log/print
Oh… finally…
While one might assume the “n” in [:tonsec] means number – since it converts a time type to a num type.
But it really a “tonanosecs”…
:put [:tonsec 1s]
1000000000
:put [:typeof [:tonsec 1s]]
num
:put [:tonsec [:timestamp]]
1693512717100098007
To get # of seconds from a time type…
:put ([:tonsec 1s]/1000000000)
# 1
For completeness, /terminal/ask replaces using a [:return] or loop on [/terminal/inkey], to collect a string from the commands line
:global userinput [/terminal/ask preinput="preinput>" prompt="Some text that in prompt=" ]
# Some text that in prompt=
# preinput>test
:put $userinput
# test
preinput= and prompt= seem backwards, but that’s how it works… preinput is what appear just before the user input cursor & prompt is what shows above it.
Thank you very much. Let’s put in this topic everything that concerns the new Ros teams. It will be easy to search.
Is it possible to encode some data with a key using :convert, and then decode it only if this key is known?
By the way, some descriptions of the new commands are present here:
https://help.mikrotik.com/docs/display/ROS/Scripting
I guess rot13 is not good enough “encryption” …
But not at present. The transform='s in :convert are are either string operations or one-way hashes. The “ed25519-” are to deal with converting/extracting keys for EC-based SSH, but not the encryption.
Kinda my thought. Although, might want to change the title to include the 7.12 version in your title. e.g. “New commands in v7.12”
There was also this in the v7.12 release notes, I’m not sure what was improved… Maybe someone else know this one?
*) console - improved multi-argument property parsing into array;
No, I think it’s better to post here for now all the new commands of the entire Router OS 7.