mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
daily-psk: merge with email-daily-psk
This commit is contained in:
parent
92bb1d107c
commit
9f4b6fac44
2 changed files with 44 additions and 68 deletions
54
daily-psk
54
daily-psk
|
@ -4,8 +4,15 @@
|
||||||
#
|
#
|
||||||
# update daily PSK (pre shared key)
|
# update daily PSK (pre shared key)
|
||||||
|
|
||||||
|
:global "identity";
|
||||||
|
:global "email-general-to";
|
||||||
|
:global "email-general-cc";
|
||||||
:global "daily-psk-match-comment";
|
:global "daily-psk-match-comment";
|
||||||
|
|
||||||
|
:global SendNotification;
|
||||||
|
|
||||||
|
:local seen [ :toarray "" ];
|
||||||
|
|
||||||
# return pseudo-random string for PSK
|
# return pseudo-random string for PSK
|
||||||
:local GeneratePSK do={
|
:local GeneratePSK do={
|
||||||
:local date $1;
|
:local date $1;
|
||||||
|
@ -61,23 +68,50 @@
|
||||||
:local date [ / system clock get date ];
|
:local date [ / system clock get date ];
|
||||||
:local newpsk [ $GeneratePSK $date ];
|
:local newpsk [ $GeneratePSK $date ];
|
||||||
|
|
||||||
:local sendmail 0;
|
|
||||||
|
|
||||||
:foreach acclist in=[ / interface wireless access-list find where comment~$"daily-psk-match-comment" ] do={
|
: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 intname [ / interface wireless access-list get $acclist interface ];
|
||||||
:local ssid [ / interface wireless get $interface ssid ];
|
:local interface [ / interface wireless find where name=$intname disabled=no ];
|
||||||
|
:local ssid [ / interface wireless get $intname ssid ];
|
||||||
:local oldpsk [ / interface wireless access-list get $acclist private-pre-shared-key ];
|
:local oldpsk [ / interface wireless access-list get $acclist private-pre-shared-key ];
|
||||||
|
:local skip 0;
|
||||||
|
|
||||||
:if ($newpsk != $oldpsk) do={
|
:if ($newpsk != $oldpsk) do={
|
||||||
:log info ("Updating daily PSK for " . $interface . " to " . $newpsk . " (was " . $oldpsk . ")");
|
:log info ("Updating daily PSK for " . $intname . " to " . $newpsk . " (was " . $oldpsk . ")");
|
||||||
/ interface wireless access-list set $acclist private-pre-shared-key=$newpsk;
|
/ interface wireless access-list set $acclist private-pre-shared-key=$newpsk;
|
||||||
|
|
||||||
:set sendmail 1;
|
:if ([ :len $interface ] = 1) do={
|
||||||
|
:foreach "seen-ssid" in=$seen do={
|
||||||
|
:if ($"seen-ssid" = $ssid) do={
|
||||||
|
:log debug ("Already sent a mail for SSID " . $ssid . ", skipping.");
|
||||||
|
:set skip 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:if ($skip = 0) do={
|
||||||
|
:set $seen ( $seen, $ssid );
|
||||||
|
|
||||||
|
:local host "www.eworm.de"
|
||||||
|
:local srcpath ("/cgi-bin/cqrlogo-wifi.cgi" . \
|
||||||
|
"?scale=8" . \
|
||||||
|
"&level=1" . \
|
||||||
|
"&ssid=" . $ssid . \
|
||||||
|
"&pass=" . $newpsk);
|
||||||
|
|
||||||
|
/ tool fetch mode=https check-certificate=yes-without-crl address=$host host=$host \
|
||||||
|
src-path=$srcpath dst-path=qrcode-daily.png;
|
||||||
|
|
||||||
|
$SendNotification ("[" . $identity . "] daily PSK " . $ssid) \
|
||||||
|
("This is the daily PSK on " . $identity . ":\n\n" . \
|
||||||
|
"SSID: " . $ssid . "\n" . \
|
||||||
|
"PSK: " . $newpsk . "\n" . \
|
||||||
|
"Date: " . [ / system clock get date ] . "\n\n" . \
|
||||||
|
"https://" . $host . $srcpath) \
|
||||||
|
"qrcode-daily.png";
|
||||||
|
}
|
||||||
|
} else={
|
||||||
|
:log debug ("Missing active interface " . $intname . " for access list entry.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ($sendmail = 1) do={
|
|
||||||
/ system script run email-daily-psk;
|
|
||||||
}
|
|
||||||
|
|
||||||
/ system scheduler set disabled=yes [ find where name=daily-psk disabled=no ];
|
/ system scheduler set disabled=yes [ find where name=daily-psk disabled=no ];
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
#!rsc
|
|
||||||
# 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";
|
|
||||||
|
|
||||||
:global SendNotification;
|
|
||||||
|
|
||||||
:local seen [ :toarray "" ];
|
|
||||||
|
|
||||||
:foreach acclist in=[ / interface wireless access-list find where comment~$"daily-psk-match-comment" ] do={
|
|
||||||
:local skip 0;
|
|
||||||
:local intname [ / interface wireless access-list get $acclist interface ];
|
|
||||||
:local psk [ / interface wireless access-list get $acclist private-pre-shared-key ];
|
|
||||||
: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;
|
|
||||||
}
|
|
||||||
|
|
||||||
:foreach "seen-ssid" in=$seen do={
|
|
||||||
:if ($"seen-ssid" = $ssid) do={
|
|
||||||
:log debug ("Already sent a mail for SSID " . $ssid . ", skipping.");
|
|
||||||
:set skip 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:if ($skip = 0) do={
|
|
||||||
:set $seen ( $seen, $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;
|
|
||||||
|
|
||||||
$SendNotification ("[" . $identity . "] daily PSK " . $ssid) \
|
|
||||||
("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) \
|
|
||||||
"qrcode-daily.png";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue