mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
49 lines
1.5 KiB
Text
49 lines
1.5 KiB
Text
#!rsc
|
|
# RouterOS script: sms-forward
|
|
# Copyright (c) 2013-2019 Christian Hesse <mail@eworm.de>
|
|
#
|
|
# forward SMS to e-mail
|
|
|
|
:global Identity;
|
|
|
|
:global SendNotification;
|
|
|
|
# check mail server
|
|
:if ([ / tool netwatch get [ find where comment=[ / tool e-mail get address ] ] status ] != "up") do={
|
|
:log warning "Mail server is not up.";
|
|
:error "Warning: See log for details.";
|
|
}
|
|
|
|
:local Allowed [ / tool sms get allowed-number ];
|
|
:local Secret [ / tool sms get secret ];
|
|
|
|
# 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 Message [ / tool sms inbox get $Sms message ];
|
|
:local TimeStamp [ / tool sms inbox get $Sms timestamp ];
|
|
:local Type [ / tool sms inbox get $Sms type ];
|
|
|
|
:if ($Phone = $Allowed && $Message~("^:cmd " . $Secret . " script ")) do={
|
|
:log debug "Removing SMS, which started a script.";
|
|
/ tool sms inbox remove $Sms;
|
|
} else={
|
|
:set Messages ($Messages . "\n\nOn " . $TimeStamp . \
|
|
" type " . $Type . ":\n" . $Message);
|
|
:set Delete ($Delete, $Sms);
|
|
}
|
|
}
|
|
|
|
:if ([ :len $Messages ] > 0) do={
|
|
$SendNotification ("SMS Forwarding") \
|
|
("These message(s) were received by " . $Identity . \
|
|
" from " . $Phone . ":" . $Messages);
|
|
:foreach Sms in=$Delete do={
|
|
/ tool sms inbox remove $Sms;
|
|
}
|
|
}
|
|
}
|