It's a package manager for RouterOS script. You can use rspm to install and share script packages.
It also provide many useful script packages for RouterOS, which support rspm itself and fulfill the missing string operation, datetime operation and so on.
If you like it, please star and watch the project on github.
If you have some really good idea, you can open an issue and let me know.
Quick Example
String Operations
Code: Select all
# split
:put [$Split "a,b,c,d" ","];
# result: a;b;c;d
# rsplit
:put [$RSplit "a,b,c,d" "," 1];
# result: a,b,c;d
# join
:local a {"a";"b";"c";"d";"e"};
:put [$Join "/" $a];
# result: a/b/c/d/e
# strip
:put [$Strip ("hello world") "hed"];
# result: llo worl
Datetime Operations
Code: Select all
# get current datetime
:put [$GetCurrentDatetime ];
# result: 2021;8;26;3;4;32
# convert system clock to datetime
:put [$ToDatetime [/system clock print as-value ]];
# result: 2021;8;26;3;4;32
# from array
:local sdt {"date"="aug/26/2021"; "time"=0:0:0};
:put [$ToDatetime $sdt];
# result: 2021;8;26;0;0;0
# datetime shift by timedelta
:local dt {2021;2;28;0;0;0};
# timedelta: years, months, days, hours, minutes and seconds
:local td {days=1095;minutes=1500};
:put [$ShiftDatetime $dt $td];
# result: 2024;2;29;1;0;0
# datetime shift by time
:local dt {2021;2;28;0;0;0};
# time
:local t -364d0:1000:00;
:put [$ShiftDatetime $dt $t];
# result: 2020;2;29;7;20;0
JSON Operations
Code: Select all
# JSON loads
:local s "{\"text\": \"hello world!\"}";
:local array [[$GetFunc "tool.json.loads"] Str=$s];
$Print $array;
# JSON dumps
:local a {
"a"={
"aa"=true;
"ab"=false;
"ac"=$Nil;
"b"={1;2;3;4;{"ccc"="dwafagcsad";}};
};
"s"="asdvasd";
"ip"=1.2.3.4;
"ip-range"=1.0.0.0/8;
"ipv6"=ffff::0000;
"time"=12:00:59;
}
# no indent
:put [[$GetFunc "tool.json.dumps"] Obj=$a];
# use indent
:put [[$GetFunc "tool.json.dumps"] Obj=$a Indent=4];
Script Sharing
source code here: https://github.com/Detavern/rspm-pkg-hello-world
You can follow the structure and make your own package
Code: Select all
:local metaInfo {
"name"="rspm.hello-world";
"author"="rspm";
"version"="1.0.0";
"description"="rspm package example: hello-world";
"url"="https://raw.githubusercontent.com/Detavern/rspm-pkg-hello-world/master/hello-world.rsc";
};
# $helloWorld
# kwargs: Name=<str> substitution of string "world"
:local helloWorld do={
:global IsNothing;
:if ([$IsNothing $Name]) do={
:put "Hello world!";
} else {
:put ("Hello $Name!");
}
}
:local package {
"metaInfo"=$metaInfo;
"helloWorld"=$helloWorld;
}
:return $package;
install and invoke it on routeros
Code: Select all
# install
[[$GetFunc "rspm.install"] URL="https://raw.githubusercontent.com/Detavern/rspm-pkg-hello-world/master/hello-world.rsc"];
# invoke
[[$GetFunc "rspm.hello-world.helloWorld"]];
[[$GetFunc "rspm.hello-world.helloWorld"] Name="Alice"];