aboutsummaryrefslogtreecommitdiffstats
path: root/email-daily-psk
blob: af991cae75d2e10c697ba8c5618746cf7a878117 (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
39
40
41
42
43
44
45
46
47
# RouterOS script: email-daily-psk
# Copyright (c) 2013-2018 Christian Hesse <mail@eworm.de>
#
# email daily PSK (pre shared key)

:global "identity";
:global "email-general-to";
:global "email-general-cc";
:global "daily-psk-match-comment";

:local "seen-ssids" { "" };

:foreach acclist in=[ / interface wireless access-list find where comment~$"daily-psk-match-comment" ] do={
  :local interface [ / interface wireless access-list get $acclist interface ];
  :local ssid [ / interface wireless get $interface ssid ];
  :local psk [ / interface wireless access-list get $acclist private-pre-shared-key ];

  :local seen 0;
  :foreach "seen-ssid" in=$"seen-ssids" do={
    :if ($"seen-ssid" = $ssid) do={
      :set seen 1;
    }
  }

  :if ($seen = 0) do={
    :set $"seen-ssids" { $"seen-ssids"; $ssid };

    :local host "www.eworm.de"
    :local srcpath ("/cgi-bin/cqrlogo-wifi.cgi" . \
      "?scale=8" . \
      "&level=1" . \
      "&ssid=" . $ssid . \
      "&pass=" . $psk);

    / tool fetch mode=https check-certificate=yes-without-crl address=$host host=$host \
      src-path=$srcpath dst-path=qrcode-daily.png;

    / tool e-mail send to=$"email-general-to" cc=$"email-general-cc" \
      subject=("[" . $identity . "] daily PSK " . $ssid) \
      body=("This is the daily PSK on " . $identity . ":\n\n" . \
        "SSID: " . $ssid . "\n" . \
        "PSK:  " . $psk . "\n" . \
        "Date: " . [ / system clock get date ] . "\n\n" . \
        "https://" . $host . $srcpath) \
      file=qrcode-daily.png;
  }
}