routeros-scripts/sms-forward
Christian Hesse 71ad56aacc explicitly name the license
Copyright (C) 2013-2020 Christian Hesse <mail@eworm.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

https://www.gnu.org/licenses/#GPL
https://www.gnu.org/licenses/gpl.html
https://www.gnu.org/licenses/gpl.md
2020-06-19 22:17:42 +02:00

54 lines
1.6 KiB
Text

#!rsc
# RouterOS script: sms-forward
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# forward SMS to e-mail
# https://git.eworm.de/cgit/routeros-scripts/about/doc/sms-forward.md
:global Identity;
:global LogPrintExit;
:global MailServerIsUp;
:global SendNotification;
:if ([ / tool sms get receive-enabled ] = false) do={
$LogPrintExit warning "Receiving of SMS is not enabled." true;
}
# check mail server
:if ($MailServerIsUp = false) do={
$LogPrintExit warning "Mail server is not up." true;
}
:local Settings [ / tool sms get ];
# forward SMS in a loop
:while ([ / tool sms inbox print count-only ] > 0) do={
:local Phone [ / tool sms inbox get ([ find ]->0) phone ];
:local Messages "";
:local Delete [ :toarray "" ];
:foreach Sms in=[ / tool sms inbox find where phone=$Phone ] do={
:local SmsVal [ / tool sms inbox get $Sms ];
:if ($Phone = $Settings->"allowed-number" && \
($SmsVal->"message")~("^:cmd " . $Settings->"secret" . " script ")) do={
$LogPrintExit debug ("Removing SMS, which started a script.") false;
/ tool sms inbox remove $Sms;
} else={
:set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \
" type " . $SmsVal->"type" . ":\n" . $SmsVal->"message");
:set Delete ($Delete, $Sms);
}
}
:if ([ :len $Messages ] > 0) do={
$SendNotification ("SMS Forwarding from " . $Phone) \
("These message(s) were received by " . $Identity . \
" from " . $Phone . ":" . $Messages);
:foreach Sms in=$Delete do={
/ tool sms inbox remove $Sms;
}
}
}