Community discussions

 
User avatar
mrz
MikroTik Support
MikroTik Support
Topic Author
Posts: 5655
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: 2386
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
newbie
Posts: 37
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: 2386
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: 1761
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
newbie
Posts: 37
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 Veteran
Forum Veteran
Posts: 721
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: 4712
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: 34
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: 17
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: 123
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: 6
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: 4712
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: 427
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: 149
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: 5655
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: 149
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: 149
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: 5655
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: 5
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

Who is online

Users browsing this forum: No registered users and 4 guests