aboutsummaryrefslogtreecommitdiffstats
path: root/sms-forward
blob: d94f0c3008fd7a8731f50cb9201a6257a3cd9009 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!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={
  :error "Mail server is not up.";
}

:local allowed [ / tool sms get allowed-number ];
:local secret [ / tool sms get secret ];

# forward SMS in a loop
:foreach sms in=[ / tool sms inbox find ] do={
  :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 ];

  :if ($phone = $allowed && message~("^:cmd " . $secret . " script ")) do={
    :log debug "Ignoring SMS, which starts a script.";
  } else={
    $SendNotification ("SMS Forwarding") \
      ("A message was received by " . $identity . ":\n\n" . \
        "Phone:     " . $phone . "\n" . \
        "Timestamp: " . $timestamp . "\n" . \
        "Type:      " . $type . "\n\n" . \
        "Message:\n" .  $message);
    / tool sms inbox remove $sms;
  }
}