Community discussions

 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 5696
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Built in function library

Thu Mar 08, 2018 4:56 pm

We are considering to add commonly used functions as built-in.
What functions would you like to see?
For example, MD5hash, random number generator and so on.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2389
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Built in function library

Thu Mar 08, 2018 5:22 pm

From most important to least importing in my opinion:

String replacement. Both by a string needle, and a regex match.

String splitting (into an array of strings). Both by a string needle, and a regex match.

Joining strings in an array into a single string with a specified string between each array member (implicitly convert array values with ":tostr").

Date and time manipulation functions, such as returning the difference between two dates as a "time" value, or adding/subtracting a "time" value to a date (or "num" that is treated as plus seconds), to get a new date at that offset. Also timestamp convertion, i.e. a function to convert a "num" value to a date and time from the unix epoch, and convert a date to a "num" value that is such a timestamp. Being able to output the date and time in a different format would be nice, though it should always default to RouterOS' current format. To that particular end, it would be awesome if there are two new scripting types - date, and datetime, to complement the already existing "time" type, along with type conversion functions. Places within RouterOS that have dates and datetimes should be updated to return typed values instead of strings.

String encoding and decoding functions. Notably, a function to convert a number to a character in a charset (defaulting to ASCII, should support at minimum that and UTF-8), and vice versa. Some other commonly used encoding schemes, such as raw URL encoding/decoding, hex encoding/decoding, hex encoding with a "\" (when generating RouterOS scripts) would also be great.

Array manipulation functions. Such as a function for unique values in an array, getting the key at an index (return "nothing" if there isn't one), sorting an array by key (with an option what to do for keyless members), or by value, in either ascending or descending order, ideally with the option to specify a comparrison function.

In addition to MD5, SHA1, SHA256 and any other OpenSSL supported hashes would be nice, for the purposes of computing hashes to either be posted to a 3rd party or comparing 3rd party checksums. On a related note, encrypting, decrypting and signing data (strings and files) with certificates in the "/certificate" menu (ala PGP) would be awesome.

In addition to a random number between two values, a "random bytes" function (where you just specify the number of bytes you want) would be nice too.
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
User avatar
Joni
Frequent Visitor
Frequent Visitor
Posts: 54
Joined: Fri Mar 20, 2015 2:46 pm
Contact:

Re: Built in function library

Fri Mar 09, 2018 8:52 am

If you want to really jumpstart the Mikrotik scripting community then you should probably review the php most common sought after functions.
Also review scripts made for Mikrotik and the most commonly created functions there.
Personally any and all validation functions (ip, dns, email, url, time, date, etc) would be extremely helpfull for anyone trying to implement anything.
(disclaimer, this has nothing to do with php itself but the most adopted language by beginners, cant argue with history)
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2389
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Built in function library

Mon Mar 12, 2018 5:15 pm

Oh, oh... one more important idea... A function to show the type and value of a variable. When outputting strings or arrays, include lengths, and when outputting strings, surround them with quotes and escape quotes, slashes and unprintable characters inside (so that what's shown could potentially be copy&pasted into a script or parsed). Something analogus to PHP's var_dump(), except that arrays will be shown with both indexes and keys (since RouterOS arrays can have both, whereas PHP can only have either), and perhaps return the string instead of outputting it on screen (allowing users to send it, store it in a file, etc.; not just output it on screen).

This same function, in addition to being useful when debugging scripts, will also enable RouterOS to output reliably parsable data from "print as-value", as opposed to print's other formats, that can all be broken if the user has set a certain value to a free form string field (e.g. comment).
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
User avatar
nz_monkey
Forum Guru
Forum Guru
Posts: 1794
Joined: Mon Jan 14, 2008 1:53 pm
Location: Straya
Contact:

Re: Built in function library

Mon Mar 12, 2018 10:56 pm

I was about to post what I thought was important, then realized boen_robot has written everything I was going to :D

So +1 to everything he said..
http://thebrotherswisp.com/ | Mikrotik MTCNA, MTCRE, MTCINE | Fortinet FTCNA, FCNSP, FCT | Extreme Networks ENA
 
User avatar
Joni
Frequent Visitor
Frequent Visitor
Posts: 54
Joined: Fri Mar 20, 2015 2:46 pm
Contact:

Re: Built in function library

Tue Mar 13, 2018 9:48 am

You could also take into consideration the future possibility of executing scheduled remote scripts from The Dude on remote Device.
(ex collect backups from monitored devices)
 
anav
Forum Guru
Forum Guru
Posts: 1109
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada

Re: Built in function library

Tue Mar 13, 2018 1:41 pm

Easy, a function that creates Ports/Services groups, which then can be used in port forwarding and firewall rules etc........
 
pe1chl
Forum Guru
Forum Guru
Posts: 4864
Joined: Mon Jun 08, 2015 12:09 pm

Re: Built in function library

Tue Mar 13, 2018 2:00 pm

I was about to post what I thought was important, then realized boen_robot has written everything I was going to :D

So +1 to everything he said..
I fully agree with that!
 
ivanfm
newbie
Posts: 37
Joined: Sun May 20, 2012 5:07 pm

Re: Built in function library

Tue Mar 13, 2018 7:01 pm

My suggestions :

ISODateTime - returns date/time in ISO format, great for saving backup files, that can be ordered, currently the ROS date used month as text.

FlashPrefix - receive an filename and return it with /flash/ when the device has an /flash directory to keep saved files

Function to keep only some characters from string (used to create safe filenames)

Replace characters on string , given an string, old character and new character all old characters found in the string are replaced by new character

Modulus of division (better to be an operator instead of function)

function to sort an array, by ascii strings or by numeric values.

hash function returning values in hex.
 
User avatar
omega-00
Forum Guru
Forum Guru
Posts: 1165
Joined: Sat Jun 06, 2009 4:54 am
Location: Brisbane, Australia
Contact:

Re: Built in function library

Wed Mar 14, 2018 2:27 pm

1. The implementation of a switch function as an alternative to if,else.. or at least if,elseif,else.
2. Add back in the LUA support for editing items/utilising datasets above 4k characters long.
3. A random function would be very handy
4. All the things boen said.

A better debugger would also be nice, but now I'm just being picky. :-)
brightwifi.com | mikrotik-routeros.com | MTCNA,MTCWE.MTCTCE | Give karma where due
 
thobias
just joined
Posts: 18
Joined: Thu Nov 30, 2017 8:45 pm

Re: Built in function library

Thu Mar 22, 2018 12:01 pm

Date/time comparison (NOW();) and option to get time in different formats.
Json parsing.
LUA or whatever to be able to parse larger files.
 
User avatar
armandfumal
Member Candidate
Member Candidate
Posts: 124
Joined: Wed Apr 25, 2012 5:50 pm
Location: Huldange,LUX
Contact:

Re: Built in function library

Thu Apr 12, 2018 8:51 am

url_encode();
Armand Fumal
________________________________________________________________
CCR1072-1G-8S+ - CCR1036-8G-2S+EM - CCR1036-12G-4S-EM - RB1100AHx2 - RB2011UAS-RM - OmniTIK Ac- SXT Ac -
 
Chupakabra303
just joined
Posts: 9
Joined: Tue Jun 20, 2017 3:07 pm

Re: Built in function library

Wed Apr 18, 2018 1:55 pm

LUA +1
Internal JSON parser to associative array variable (by type http://www.embest.ru/mikrotik/json-parser-script)
Last edited by Chupakabra303 on Wed Jun 27, 2018 4:50 pm, edited 2 times in total.
 
thantoldo
just joined
Posts: 21
Joined: Tue Apr 10, 2012 10:08 pm

Re: Built in function library

Thu Apr 19, 2018 11:23 am

Can you please raise the fetch variable 65535 character limit (double it or remove it completely), so that the error case "max line length 65535 exceeded!" is resolved?
It happens both with GET and POST.

As routerOS is more and more involved in the big data domain, it is imperative that such limitations are removed.

Also, is there a hardcoded fetch timeout? Can it be exposed as a fetch parameter?
 
shdwmstff
newbie
Posts: 35
Joined: Wed May 30, 2012 12:00 am

Re: Built in function library

Fri Apr 20, 2018 10:57 pm

SNMP-GET
I would like to poll external devices and have based on the results change routes, enable/disable interfaces.
It would be a nice feature.
 
pe1chl
Forum Guru
Forum Guru
Posts: 4864
Joined: Mon Jun 08, 2015 12:09 pm

Re: Built in function library

Sat Apr 21, 2018 1:45 am

SNMP-GET
I would like to poll external devices and have based on the results change routes, enable/disable interfaces.
It would be a nice feature.
I have been thinking about polling SNR/CCQ of radio links and tuning BGP parameters using the results.
First from some external Linux system, when it is workable it would be nice when the router itself could do it.
 
telepro
Frequent Visitor
Frequent Visitor
Posts: 62
Joined: Sun Apr 03, 2011 7:50 pm

Re: Built in function library

Mon May 14, 2018 4:03 am

+1 for SHA1 and SHA256 hash function
better debugging environment
indication of the line number instead of no response when attempting to start a script with an syntax error
output of line number when importing a script encounters a run-time failure
 
User avatar
doneware
Trainer
Trainer
Posts: 436
Joined: Mon Oct 08, 2012 8:39 pm
Location: Hungary

Re: Built in function library

Thu Jul 12, 2018 7:38 pm

JSON encoder
regexp (PCRE) string manipulation
#TR0359
 
Mantrid
just joined
Posts: 1
Joined: Mon Jun 04, 2018 8:53 pm

Re: Built in function library

Fri Jul 27, 2018 3:53 am

function for in RAM memory save\load\parse any big raw data.
"tool fetch", any backup and e.t.c scripts need save data to NAND ... NAND have write limit or small size
Mikrotik need any power functions for manipulate big data in available RAM.
 
User avatar
eworm
Member Candidate
Member Candidate
Posts: 171
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Built in function library

Fri Aug 24, 2018 4:01 pm

Would be nice the see the bitwise operator for IPv6 addresses...
[admin@MikroTik] > :put (192.168.88.10 & 255.255.0.0)
192.168.0.0
[admin@MikroTik] > :put (2003:cf:2f1e:5c00:d250:99ff:fec0:d180 & ffff:ffff:ffff:ff00::)
Script Error: cannot compute bitwise "and" of internal number and internal number
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 5696
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Built in function library

Fri Aug 24, 2018 4:34 pm

bitwise operator works, whats missing is :toipv6
 
User avatar
eworm
Member Candidate
Member Candidate
Posts: 171
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Built in function library

Fri Aug 24, 2018 5:25 pm

bitwise operator works, whats missing is :toipv6
Missing from being implemented or missing in my command?
:put ([:toip6 2003:cf:2f1e:5c00:d250:99ff:fec0:d180 ] & [:toip6 ffff:ffff:ffff:ff00::])
... does not give an error, but does not give output neither.
I mailed support and they told me "to be aware of the issue, perhaps it will be fixed in the upcoming versions" (see Ticket#2018061222006824).
 
User avatar
eworm
Member Candidate
Member Candidate
Posts: 171
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Built in function library

Tue Aug 28, 2018 1:17 pm

bitwise operator works, whats missing is :toipv6
Missing from being implemented or missing in my command?
[admin@MikroTik] > :put ([:toip6 2003:cf:2f1e:5c00:d250:99ff:fec0:d180 ] & [:toip6 ffff:ffff:ffff:ff00::])
... does not give an error, but does not give output neither.
I mailed support and they told me "to be aware of the issue, perhaps it will be fixed in the upcoming versions" (see Ticket#2018061222006824).
mrz, can you give advise?

BTW, this looks borked, no?
:put [:typeof [:toip6 ffff::/64]]
nil
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 5696
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Built in function library

Tue Aug 28, 2018 2:04 pm

Yes it is not implemented.
 
User avatar
rendezz
just joined
Posts: 15
Joined: Mon Sep 17, 2018 11:07 am

Re: Built in function library

Mon Sep 17, 2018 11:09 am

url_encode();
+1 to this, my implementation is limited and awful
Home of the Badjr, the cloud-managed business network router built on Mikrotik http://baselinecloud.com/badjr
 
User avatar
Usermikrotik
just joined
Posts: 3
Joined: Wed Nov 22, 2017 12:03 pm

Re: Built in function library

Thu Sep 27, 2018 12:10 pm

simulate a runtime command and send it to a running command in a script like in these commands

Image
 
howdey57
newbie
Posts: 40
Joined: Wed Dec 31, 2014 2:36 pm

Re: Built in function library

Mon Oct 08, 2018 11:23 am

I'd like to have a debug function that helped with basic syntax. When writing code I spend most of my time getting the basics in place. I write my logic then comment most of it out then uncomment line by line to make sure each line is working. With ros code, if it doesn't work, you get nothing to say where the error is

Also,
- log dates in YYYYMMDD HHMMSS format.
- log dates that work around midnight when not in GMT.
- Ability to add items to end of arrays

Charles
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8140
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Built in function library

Mon Oct 08, 2018 11:35 am

I'd like to have a debug function that helped with basic syntax. When writing code I spend most of my time getting the basics in place. I write my logic then comment most of it out then uncomment line by line to make sure each line is working. With ros code, if it doesn't work, you get nothing to say where the error is
You may paste the script into Terminal after "{" - that will prevent it from running line by line. Then "}" and Enter to execute.
- Ability to add items to end of arrays
Looks like "+" works just fine:
{
	:local a {1;2;3};
	:set a ($a + 5);
	:foreach v in=$a do={
		:put $v
	};
}
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
howdey57
newbie
Posts: 40
Joined: Wed Dec 31, 2014 2:36 pm

Re: Built in function library

Mon Oct 08, 2018 11:48 am

Thanks. I'll try those. Are they mentioned in the wiki?

Any thoughts on the dates?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8140
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Built in function library

Mon Oct 08, 2018 11:51 am

Are they mentioned in the wiki?
Not sure :)
Any thoughts on the dates?
I didn't get what's wrong with dates, sorry
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
eworm
Member Candidate
Member Candidate
Posts: 171
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Built in function library

Mon Oct 08, 2018 11:55 am

- Ability to add items to end of arrays
Looks like "+" works just fine:
No, the documentation says using a comma is the correct way:
:set a ($a, 5);
https://wiki.mikrotik.com/wiki/Manual:S ... _Operators
 
howdey57
newbie
Posts: 40
Joined: Wed Dec 31, 2014 2:36 pm

Re: Built in function library

Mon Oct 08, 2018 5:06 pm

Thanks. Commas it will be!

The date challenge is twofold:
1. Dates in the log file are not consistent. The date is excluded from entries for today and the year is missed out for entries this year. Ideally there would be a switch to set all log date/times to YYYYMMDDHHMMSS format. Machine readable and sortable.
2. If the router is set to anything else apart from GMT (ie there is a time offset), the log entries date/times go mad around midnight (GMT). Look at your log files when time is 00.00 GMT. I can only think it is a bug in ros. I'm on 6.43.2

Charles
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8140
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Built in function library

Mon Oct 08, 2018 5:38 pm

Well, I believe log format has nothing to do with built-in scripting functions...

About 00:00 bug (unfortunately, I don't have a log at 00:00, so I don't know what are you talking about) - have you contacted support@mikrotik.com?
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
howdey57
newbie
Posts: 40
Joined: Wed Dec 31, 2014 2:36 pm

Re: Built in function library

Mon Oct 08, 2018 5:46 pm

Chupaka

You are correct about log entries not directly being about functions but the flip side is that you need lots of other functions to be built to manipulate the inconsistent log date formats.

I'll try support@.

Thanks

Charles
 
plisken
Forum Guru
Forum Guru
Posts: 2312
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Built in function library

Wed Oct 17, 2018 4:47 pm

Secure DNS implementation would be welcome in the future
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8140
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Built in function library

Thu Oct 18, 2018 11:51 am

Secure DNS implementation would be welcome in the future
What scripting functions do you mean?..
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
plisken
Forum Guru
Forum Guru
Posts: 2312
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Built in function library

Thu Oct 18, 2018 12:23 pm

Hallo Chupaka, something like that.
In the same way the SSL turns HTTP web traffic into HTTPS encrypted Web traffic, DNSCrypt turns regular DNS traffic into encrypted DNS traffic that is secure from eavesdropping and man-in-the-middle attacks.

Grt
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8140
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Built in function library

Thu Oct 18, 2018 12:29 pm

You mean, some function like ":resolve", but using DNSCrypt protocol?
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
plisken
Forum Guru
Forum Guru
Posts: 2312
Joined: Sun May 15, 2011 12:24 am
Location: Belgium
Contact:

Re: Built in function library

Thu Oct 18, 2018 12:30 pm

Yes indeed that's what i mean Chupaka.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 5696
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Built in function library

Thu Oct 18, 2018 1:13 pm

Completely unrelated to original topic.
 
pe1chl
Forum Guru
Forum Guru
Posts: 4864
Joined: Mon Jun 08, 2015 12:09 pm

Re: Built in function library

Thu Oct 18, 2018 4:11 pm

Completely unrelated to original topic.
What is the progress on the original topic? Has it been decided if this is going to happen, when, and what functions?

Who is online

Users browsing this forum: No registered users and 14 guests