2018-08-24 14:16:56 +00:00
|
|
|
#
|
2018-07-05 13:29:26 +00:00
|
|
|
# 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";
|
|
|
|
|
2018-08-24 14:34:06 +00:00
|
|
|
:local seen [ :toarray "" ];
|
2018-07-05 13:29:26 +00:00
|
|
|
|
|
|
|
:foreach acclist in=[ / interface wireless access-list find where comment~$"daily-psk-match-comment" ] do={
|
2018-08-17 07:01:52 +00:00
|
|
|
:local skip 0;
|
|
|
|
:local intname [ / interface wireless access-list get $acclist interface ];
|
2018-07-05 13:29:26 +00:00
|
|
|
:local psk [ / interface wireless access-list get $acclist private-pre-shared-key ];
|
2018-08-17 07:01:52 +00:00
|
|
|
:local interface [ / interface wireless find where name=$intname disabled=no ];
|
|
|
|
:local ssid;
|
|
|
|
|
|
|
|
:if ([ :len $interface ] = 1) do={
|
|
|
|
:set ssid [ / interface wireless get $interface ssid ];
|
|
|
|
} else={
|
|
|
|
:log debug "Missing active interface for access list entry, skipping.";
|
|
|
|
:set skip 1;
|
|
|
|
}
|
2018-07-05 13:29:26 +00:00
|
|
|
|
2018-08-17 07:01:52 +00:00
|
|
|
:foreach "seen-ssid" in=$seen do={
|
|
|
|
:if ($"seen-ssid" = $ssid) do={
|
|
|
|
:log debug ("Already sent a mail for SSID " . $ssid . ", skipping.");
|
|
|
|
:set skip 1;
|
|
|
|
}
|
2018-07-05 13:29:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 07:01:52 +00:00
|
|
|
:if ($skip = 0) do={
|
|
|
|
:set $seen { $seen; $ssid };
|
2018-07-05 13:29:26 +00:00
|
|
|
|
|
|
|
: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;
|
|
|
|
}
|
|
|
|
}
|