mod/notification-matrix: use :deserialize ...

... instead of $ParseJson. This requires RouterOS 7.13.
This commit is contained in:
Christian Hesse 2024-03-28 22:54:23 +01:00
parent 29bcbc4db9
commit bb237dcef3
2 changed files with 5 additions and 5 deletions

View file

@ -4,7 +4,7 @@ Send notifications via Matrix
[![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers) [![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network) [![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network)
[![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers) [![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers)
[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.12-yellow?style=flat)](https://mikrotik.com/download/changelogs/) [![required RouterOS version](https://img.shields.io/badge/RouterOS-7.13-yellow?style=flat)](https://mikrotik.com/download/changelogs/)
[![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts) [![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts)
[![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) [![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)

View file

@ -4,6 +4,8 @@
# Christian Hesse <mail@eworm.de> # Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md # https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
# #
# requires RouterOS, version=7.13
#
# send notifications via Matrix # send notifications via Matrix
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mod/notification-matrix.md # https://git.eworm.de/cgit/routeros-scripts/about/doc/mod/notification-matrix.md
@ -183,9 +185,7 @@
:local User [ :tostr $1 ]; :local User [ :tostr $1 ];
:local Pass [ :tostr $2 ]; :local Pass [ :tostr $2 ];
:global CharacterReplace;
:global LogPrint; :global LogPrint;
:global ParseJson;
:global MatrixAccessToken; :global MatrixAccessToken;
:global MatrixHomeServer; :global MatrixHomeServer;
@ -194,7 +194,7 @@
:do { :do {
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data"); ("https://" . $Domain . "/.well-known/matrix/client") as-value ]->"data");
:set MatrixHomeServer ([ $ParseJson ([ $ParseJson [ $CharacterReplace $Data " " "" ] ]->"m.homeserver") ]->"base_url"); :set MatrixHomeServer ([ :deserialize from=json value=$Data ]->"m.homeserver"->"base_url");
$LogPrint debug $0 ("Home server is: " . $MatrixHomeServer); $LogPrint debug $0 ("Home server is: " . $MatrixHomeServer);
} on-error={ } on-error={
$LogPrint error $0 ("Failed getting home server!"); $LogPrint error $0 ("Failed getting home server!");
@ -209,7 +209,7 @@
:local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \ :local Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
http-method=post http-data=("{\"type\":\"m.login.password\", \"user\":\"" . $User . "\", \"password\":\"" . $Pass . "\"}") \ http-method=post http-data=("{\"type\":\"m.login.password\", \"user\":\"" . $User . "\", \"password\":\"" . $Pass . "\"}") \
("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data"); ("https://" . $MatrixHomeServer . "/_matrix/client/r0/login") as-value ]->"data");
:set MatrixAccessToken ([ $ParseJson $Data ]->"access_token"); :set MatrixAccessToken ([ :deserialize from=json value=$Data ]->"access_token");
$LogPrint debug $0 ("Access token is: " . $MatrixAccessToken); $LogPrint debug $0 ("Access token is: " . $MatrixAccessToken);
} on-error={ } on-error={
$LogPrint error $0 ("Failed logging in (and getting access token)!"); $LogPrint error $0 ("Failed logging in (and getting access token)!");