aboutsummaryrefslogtreecommitdiffstats
path: root/sms-forward
blob: 9850d87edb06740786ce77b23f240926ff858dff (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
38
#!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
: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;
  }
}