2018-09-26 22:18:43 +00:00
|
|
|
#!rsc
|
2018-08-06 12:37:28 +00:00
|
|
|
# RouterOS script: sms-forward
|
2018-07-05 13:29:26 +00:00
|
|
|
# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
|
|
|
|
#
|
|
|
|
# forward SMS to e-mail
|
|
|
|
|
|
|
|
:global "identity";
|
|
|
|
|
2018-10-09 13:54:44 +00:00
|
|
|
:global SendNotification;
|
|
|
|
|
2018-07-05 13:29:26 +00:00
|
|
|
# check mail server
|
2018-08-06 12:37:28 +00:00
|
|
|
:if ([ / tool netwatch get [ find where comment=[ / tool e-mail get address ] ] status ] != "up") do={
|
2018-07-05 13:29:26 +00:00
|
|
|
:error "Mail server is not up.";
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:27:01 +00:00
|
|
|
:local allowed [ / tool sms get allowed-number ];
|
|
|
|
:local secret [ / tool sms get secret ];
|
|
|
|
|
2018-07-05 13:29:26 +00:00
|
|
|
# forward SMS in a loop
|
2018-09-23 20:27:01 +00:00
|
|
|
:foreach sms in=[ / tool sms inbox find ] do={
|
2018-07-05 13:29:26 +00:00
|
|
|
:local message [ / tool sms inbox get $sms message ];
|
|
|
|
:local phone [ / tool sms inbox get $sms phone ];
|
|
|
|
:local timestamp [ / tool sms inbox get $sms timestamp ];
|
|
|
|
:local type [ / tool sms inbox get $sms type ];
|
2018-09-23 20:27:01 +00:00
|
|
|
|
|
|
|
:if ($phone = $allowed && message~("^:cmd " . $secret . " script ")) do={
|
|
|
|
:log debug "Ignoring SMS, which starts a script.";
|
|
|
|
} else={
|
2018-11-27 13:08:14 +00:00
|
|
|
$SendNotification ("SMS Forwarding") \
|
2018-10-09 13:54:44 +00:00
|
|
|
("A message was received by " . $identity . ":\n\n" . \
|
2018-09-23 20:27:01 +00:00
|
|
|
"Phone: " . $phone . "\n" . \
|
|
|
|
"Timestamp: " . $timestamp . "\n" . \
|
|
|
|
"Type: " . $type . "\n\n" . \
|
|
|
|
"Message:\n" . $message);
|
|
|
|
/ tool sms inbox remove $sms;
|
|
|
|
}
|
2018-07-05 13:29:26 +00:00
|
|
|
}
|