mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
daily-psk: move code into function
This commit is contained in:
parent
e2b87c8634
commit
31da6b8bd5
5 changed files with 320 additions and 295 deletions
|
@ -11,77 +11,82 @@
|
||||||
#
|
#
|
||||||
# !! Do not edit this file, it is generated from template!
|
# !! Do not edit this file, it is generated from template!
|
||||||
|
|
||||||
:local 0 [ :jobname ];
|
|
||||||
:global GlobalFunctionsReady;
|
:global GlobalFunctionsReady;
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
:global DailyPskMatchComment;
|
:local Main do={
|
||||||
:global DailyPskQrCodeUrl;
|
:local ScriptName [ :tostr $1 ];
|
||||||
:global Identity;
|
|
||||||
|
|
||||||
:global FormatLine;
|
:global DailyPskMatchComment;
|
||||||
:global LogPrintExit2;
|
:global DailyPskQrCodeUrl;
|
||||||
:global ScriptLock;
|
:global Identity;
|
||||||
:global SendNotification2;
|
|
||||||
:global SymbolForNotification;
|
|
||||||
:global UrlEncode;
|
|
||||||
:global WaitForFile;
|
|
||||||
:global WaitFullyConnected;
|
|
||||||
|
|
||||||
$ScriptLock $0;
|
:global FormatLine;
|
||||||
$WaitFullyConnected;
|
:global LogPrintExit2;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global UrlEncode;
|
||||||
|
:global WaitForFile;
|
||||||
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
# return pseudo-random string for PSK
|
$ScriptLock $ScriptName;
|
||||||
:local GeneratePSK do={
|
$WaitFullyConnected;
|
||||||
:local Date [ :tostr $1 ];
|
|
||||||
|
|
||||||
:global DailyPskSecrets;
|
# return pseudo-random string for PSK
|
||||||
|
:local GeneratePSK do={
|
||||||
|
:local Date [ :tostr $1 ];
|
||||||
|
|
||||||
:global ParseDate;
|
:global DailyPskSecrets;
|
||||||
|
|
||||||
:set Date [ $ParseDate $Date ];
|
:global ParseDate;
|
||||||
|
|
||||||
:local A ((14 - ($Date->"month")) / 12);
|
:set Date [ $ParseDate $Date ];
|
||||||
:local B (($Date->"year") - $A);
|
|
||||||
:local C (($Date->"month") + 12 * $A - 2);
|
|
||||||
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
|
||||||
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
|
||||||
|
|
||||||
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
:local A ((14 - ($Date->"month")) / 12);
|
||||||
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
:local B (($Date->"year") - $A);
|
||||||
($DailyPskSecrets->2->$WeekDay));
|
:local C (($Date->"month") + 12 * $A - 2);
|
||||||
}
|
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
||||||
|
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
||||||
|
|
||||||
:local Seen ({});
|
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
||||||
:local Date [ /system/clock/get date ];
|
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
||||||
:local NewPsk [ $GeneratePSK $Date ];
|
($DailyPskSecrets->2->$WeekDay));
|
||||||
|
}
|
||||||
|
|
||||||
:foreach AccList in=[ /caps-man/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local Seen ({});
|
||||||
:local SsidRegExp [ /caps-man/access-list/get $AccList ssid-regexp ];
|
:local Date [ /system/clock/get date ];
|
||||||
:local Configuration ([ /caps-man/configuration/find where ssid~$SsidRegExp ]->0);
|
:local NewPsk [ $GeneratePSK $Date ];
|
||||||
:local Ssid [ /caps-man/configuration/get $Configuration ssid ];
|
|
||||||
:local OldPsk [ /caps-man/access-list/get $AccList private-passphrase ];
|
|
||||||
:local Skip 0;
|
|
||||||
|
|
||||||
:if ($NewPsk != $OldPsk) do={
|
:foreach AccList in=[ /caps-man/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
$LogPrintExit2 info $0 ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
:local SsidRegExp [ /caps-man/access-list/get $AccList ssid-regexp ];
|
||||||
/caps-man/access-list/set $AccList private-passphrase=$NewPsk;
|
:local Configuration ([ /caps-man/configuration/find where ssid~$SsidRegExp ]->0);
|
||||||
|
:local Ssid [ /caps-man/configuration/get $Configuration ssid ];
|
||||||
|
:local OldPsk [ /caps-man/access-list/get $AccList private-passphrase ];
|
||||||
|
:local Skip 0;
|
||||||
|
|
||||||
:if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={
|
:if ($NewPsk != $OldPsk) do={
|
||||||
:if ($Seen->$Ssid = 1) do={
|
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
||||||
$LogPrintExit2 debug $0 ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
/caps-man/access-list/set $AccList private-passphrase=$NewPsk;
|
||||||
} else={
|
|
||||||
:local Link ($DailyPskQrCodeUrl . \
|
:if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
:if ($Seen->$Ssid = 1) do={
|
||||||
$SendNotification2 ({ origin=$0; \
|
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
||||||
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
} else={
|
||||||
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
:local Link ($DailyPskQrCodeUrl . \
|
||||||
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
"A client device specific rule must not exist!"); link=$Link });
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
:set ($Seen->$Ssid) 1;
|
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
||||||
|
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
||||||
|
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
||||||
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
|
:set ($Seen->$Ssid) 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Main [ :jobname ];
|
||||||
|
|
|
@ -11,76 +11,81 @@
|
||||||
#
|
#
|
||||||
# !! Do not edit this file, it is generated from template!
|
# !! Do not edit this file, it is generated from template!
|
||||||
|
|
||||||
:local 0 [ :jobname ];
|
|
||||||
:global GlobalFunctionsReady;
|
:global GlobalFunctionsReady;
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
:global DailyPskMatchComment;
|
:local Main do={
|
||||||
:global DailyPskQrCodeUrl;
|
:local ScriptName [ :tostr $1 ];
|
||||||
:global Identity;
|
|
||||||
|
|
||||||
:global FormatLine;
|
:global DailyPskMatchComment;
|
||||||
:global LogPrintExit2;
|
:global DailyPskQrCodeUrl;
|
||||||
:global ScriptLock;
|
:global Identity;
|
||||||
:global SendNotification2;
|
|
||||||
:global SymbolForNotification;
|
|
||||||
:global UrlEncode;
|
|
||||||
:global WaitForFile;
|
|
||||||
:global WaitFullyConnected;
|
|
||||||
|
|
||||||
$ScriptLock $0;
|
:global FormatLine;
|
||||||
$WaitFullyConnected;
|
:global LogPrintExit2;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global UrlEncode;
|
||||||
|
:global WaitForFile;
|
||||||
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
# return pseudo-random string for PSK
|
$ScriptLock $ScriptName;
|
||||||
:local GeneratePSK do={
|
$WaitFullyConnected;
|
||||||
:local Date [ :tostr $1 ];
|
|
||||||
|
|
||||||
:global DailyPskSecrets;
|
# return pseudo-random string for PSK
|
||||||
|
:local GeneratePSK do={
|
||||||
|
:local Date [ :tostr $1 ];
|
||||||
|
|
||||||
:global ParseDate;
|
:global DailyPskSecrets;
|
||||||
|
|
||||||
:set Date [ $ParseDate $Date ];
|
:global ParseDate;
|
||||||
|
|
||||||
:local A ((14 - ($Date->"month")) / 12);
|
:set Date [ $ParseDate $Date ];
|
||||||
:local B (($Date->"year") - $A);
|
|
||||||
:local C (($Date->"month") + 12 * $A - 2);
|
|
||||||
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
|
||||||
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
|
||||||
|
|
||||||
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
:local A ((14 - ($Date->"month")) / 12);
|
||||||
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
:local B (($Date->"year") - $A);
|
||||||
($DailyPskSecrets->2->$WeekDay));
|
:local C (($Date->"month") + 12 * $A - 2);
|
||||||
}
|
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
||||||
|
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
||||||
|
|
||||||
:local Seen ({});
|
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
||||||
:local Date [ /system/clock/get date ];
|
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
||||||
:local NewPsk [ $GeneratePSK $Date ];
|
($DailyPskSecrets->2->$WeekDay));
|
||||||
|
}
|
||||||
|
|
||||||
:foreach AccList in=[ /interface/wireless/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local Seen ({});
|
||||||
:local IntName [ /interface/wireless/access-list/get $AccList interface ];
|
:local Date [ /system/clock/get date ];
|
||||||
:local Ssid [ /interface/wireless/get $IntName ssid ];
|
:local NewPsk [ $GeneratePSK $Date ];
|
||||||
:local OldPsk [ /interface/wireless/access-list/get $AccList private-pre-shared-key ];
|
|
||||||
:local Skip 0;
|
|
||||||
|
|
||||||
:if ($NewPsk != $OldPsk) do={
|
:foreach AccList in=[ /interface/wireless/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
$LogPrintExit2 info $0 ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
:local IntName [ /interface/wireless/access-list/get $AccList interface ];
|
||||||
/interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
|
:local Ssid [ /interface/wireless/get $IntName ssid ];
|
||||||
|
:local OldPsk [ /interface/wireless/access-list/get $AccList private-pre-shared-key ];
|
||||||
|
:local Skip 0;
|
||||||
|
|
||||||
:if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
|
:if ($NewPsk != $OldPsk) do={
|
||||||
:if ($Seen->$Ssid = 1) do={
|
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
||||||
$LogPrintExit2 debug $0 ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
/interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
|
||||||
} else={
|
|
||||||
:local Link ($DailyPskQrCodeUrl . \
|
:if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
:if ($Seen->$Ssid = 1) do={
|
||||||
$SendNotification2 ({ origin=$0; \
|
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
||||||
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
} else={
|
||||||
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
:local Link ($DailyPskQrCodeUrl . \
|
||||||
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
"A client device specific rule must not exist!"); link=$Link });
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
:set ($Seen->$Ssid) 1;
|
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
||||||
|
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
||||||
|
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
||||||
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
|
:set ($Seen->$Ssid) 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Main [ :jobname ];
|
||||||
|
|
|
@ -12,98 +12,103 @@
|
||||||
# !! This is just a template to generate the real script!
|
# !! This is just a template to generate the real script!
|
||||||
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
|
# !! Pattern '%TEMPL%' is replaced, paths are filtered.
|
||||||
|
|
||||||
:local 0 [ :jobname ];
|
|
||||||
:global GlobalFunctionsReady;
|
:global GlobalFunctionsReady;
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
:global DailyPskMatchComment;
|
:local Main do={
|
||||||
:global DailyPskQrCodeUrl;
|
:local ScriptName [ :tostr $1 ];
|
||||||
:global Identity;
|
|
||||||
|
|
||||||
:global FormatLine;
|
:global DailyPskMatchComment;
|
||||||
:global LogPrintExit2;
|
:global DailyPskQrCodeUrl;
|
||||||
:global ScriptLock;
|
:global Identity;
|
||||||
:global SendNotification2;
|
|
||||||
:global SymbolForNotification;
|
|
||||||
:global UrlEncode;
|
|
||||||
:global WaitForFile;
|
|
||||||
:global WaitFullyConnected;
|
|
||||||
|
|
||||||
$ScriptLock $0;
|
:global FormatLine;
|
||||||
$WaitFullyConnected;
|
:global LogPrintExit2;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global UrlEncode;
|
||||||
|
:global WaitForFile;
|
||||||
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
# return pseudo-random string for PSK
|
$ScriptLock $ScriptName;
|
||||||
:local GeneratePSK do={
|
$WaitFullyConnected;
|
||||||
:local Date [ :tostr $1 ];
|
|
||||||
|
|
||||||
:global DailyPskSecrets;
|
# return pseudo-random string for PSK
|
||||||
|
:local GeneratePSK do={
|
||||||
|
:local Date [ :tostr $1 ];
|
||||||
|
|
||||||
:global ParseDate;
|
:global DailyPskSecrets;
|
||||||
|
|
||||||
:set Date [ $ParseDate $Date ];
|
:global ParseDate;
|
||||||
|
|
||||||
:local A ((14 - ($Date->"month")) / 12);
|
:set Date [ $ParseDate $Date ];
|
||||||
:local B (($Date->"year") - $A);
|
|
||||||
:local C (($Date->"month") + 12 * $A - 2);
|
|
||||||
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
|
||||||
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
|
||||||
|
|
||||||
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
:local A ((14 - ($Date->"month")) / 12);
|
||||||
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
:local B (($Date->"year") - $A);
|
||||||
($DailyPskSecrets->2->$WeekDay));
|
:local C (($Date->"month") + 12 * $A - 2);
|
||||||
}
|
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
||||||
|
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
||||||
|
|
||||||
:local Seen ({});
|
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
||||||
:local Date [ /system/clock/get date ];
|
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
||||||
:local NewPsk [ $GeneratePSK $Date ];
|
($DailyPskSecrets->2->$WeekDay));
|
||||||
|
}
|
||||||
|
|
||||||
:foreach AccList in=[ /caps-man/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local Seen ({});
|
||||||
:foreach AccList in=[ /interface/wifi/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local Date [ /system/clock/get date ];
|
||||||
:foreach AccList in=[ /interface/wifiwave2/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local NewPsk [ $GeneratePSK $Date ];
|
||||||
:foreach AccList in=[ /interface/wireless/access-list/find where comment~$DailyPskMatchComment ] do={
|
|
||||||
:local SsidRegExp [ /caps-man/access-list/get $AccList ssid-regexp ];
|
|
||||||
:local SsidRegExp [ /interface/wifi/access-list/get $AccList ssid-regexp ];
|
|
||||||
:local SsidRegExp [ /interface/wifiwave2/access-list/get $AccList ssid-regexp ];
|
|
||||||
:local Configuration ([ /caps-man/configuration/find where ssid~$SsidRegExp ]->0);
|
|
||||||
:local Configuration ([ /interface/wifi/configuration/find where ssid~$SsidRegExp ]->0);
|
|
||||||
:local Configuration ([ /interface/wifiwave2/configuration/find where ssid~$SsidRegExp ]->0);
|
|
||||||
:local Ssid [ /caps-man/configuration/get $Configuration ssid ];
|
|
||||||
:local Ssid [ /interface/wifi/configuration/get $Configuration ssid ];
|
|
||||||
:local Ssid [ /interface/wifiwave2/configuration/get $Configuration ssid ];
|
|
||||||
:local OldPsk [ /caps-man/access-list/get $AccList private-passphrase ];
|
|
||||||
:local OldPsk [ /interface/wifi/access-list/get $AccList passphrase ];
|
|
||||||
:local OldPsk [ /interface/wifiwave2/access-list/get $AccList passphrase ];
|
|
||||||
# /caps-man/ /interface/wifi/ /interface/wifiwave2/ above - /interface/wireless/ below
|
|
||||||
:local IntName [ /interface/wireless/access-list/get $AccList interface ];
|
|
||||||
:local Ssid [ /interface/wireless/get $IntName ssid ];
|
|
||||||
:local OldPsk [ /interface/wireless/access-list/get $AccList private-pre-shared-key ];
|
|
||||||
:local Skip 0;
|
|
||||||
|
|
||||||
:if ($NewPsk != $OldPsk) do={
|
:foreach AccList in=[ /caps-man/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
$LogPrintExit2 info $0 ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
:foreach AccList in=[ /interface/wifi/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
/caps-man/access-list/set $AccList private-passphrase=$NewPsk;
|
:foreach AccList in=[ /interface/wifiwave2/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
/interface/wifi/access-list/set $AccList passphrase=$NewPsk;
|
:foreach AccList in=[ /interface/wireless/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
/interface/wifiwave2/access-list/set $AccList passphrase=$NewPsk;
|
:local SsidRegExp [ /caps-man/access-list/get $AccList ssid-regexp ];
|
||||||
/interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
|
:local SsidRegExp [ /interface/wifi/access-list/get $AccList ssid-regexp ];
|
||||||
|
:local SsidRegExp [ /interface/wifiwave2/access-list/get $AccList ssid-regexp ];
|
||||||
|
:local Configuration ([ /caps-man/configuration/find where ssid~$SsidRegExp ]->0);
|
||||||
|
:local Configuration ([ /interface/wifi/configuration/find where ssid~$SsidRegExp ]->0);
|
||||||
|
:local Configuration ([ /interface/wifiwave2/configuration/find where ssid~$SsidRegExp ]->0);
|
||||||
|
:local Ssid [ /caps-man/configuration/get $Configuration ssid ];
|
||||||
|
:local Ssid [ /interface/wifi/configuration/get $Configuration ssid ];
|
||||||
|
:local Ssid [ /interface/wifiwave2/configuration/get $Configuration ssid ];
|
||||||
|
:local OldPsk [ /caps-man/access-list/get $AccList private-passphrase ];
|
||||||
|
:local OldPsk [ /interface/wifi/access-list/get $AccList passphrase ];
|
||||||
|
:local OldPsk [ /interface/wifiwave2/access-list/get $AccList passphrase ];
|
||||||
|
# /caps-man/ /interface/wifi/ /interface/wifiwave2/ above - /interface/wireless/ below
|
||||||
|
:local IntName [ /interface/wireless/access-list/get $AccList interface ];
|
||||||
|
:local Ssid [ /interface/wireless/get $IntName ssid ];
|
||||||
|
:local OldPsk [ /interface/wireless/access-list/get $AccList private-pre-shared-key ];
|
||||||
|
:local Skip 0;
|
||||||
|
|
||||||
:if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={
|
:if ($NewPsk != $OldPsk) do={
|
||||||
:if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
||||||
:if ([ :len [ /interface/wifiwave2/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
/caps-man/access-list/set $AccList private-passphrase=$NewPsk;
|
||||||
:if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
|
/interface/wifi/access-list/set $AccList passphrase=$NewPsk;
|
||||||
:if ($Seen->$Ssid = 1) do={
|
/interface/wifiwave2/access-list/set $AccList passphrase=$NewPsk;
|
||||||
$LogPrintExit2 debug $0 ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
/interface/wireless/access-list/set $AccList private-pre-shared-key=$NewPsk;
|
||||||
} else={
|
|
||||||
:local Link ($DailyPskQrCodeUrl . \
|
:if ([ :len [ /caps-man/actual-interface-configuration/find where configuration.ssid=$Ssid !disabled ] ] > 0) do={
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
:if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
||||||
$SendNotification2 ({ origin=$0; \
|
:if ([ :len [ /interface/wifiwave2/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
||||||
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
:if ([ :len [ /interface/wireless/find where name=$IntName !disabled ] ] = 1) do={
|
||||||
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
:if ($Seen->$Ssid = 1) do={
|
||||||
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
||||||
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
} else={
|
||||||
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
:local Link ($DailyPskQrCodeUrl . \
|
||||||
"A client device specific rule must not exist!"); link=$Link });
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
:set ($Seen->$Ssid) 1;
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
|
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
||||||
|
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
||||||
|
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
||||||
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
|
:set ($Seen->$Ssid) 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Main [ :jobname ];
|
||||||
|
|
|
@ -11,77 +11,82 @@
|
||||||
#
|
#
|
||||||
# !! Do not edit this file, it is generated from template!
|
# !! Do not edit this file, it is generated from template!
|
||||||
|
|
||||||
:local 0 [ :jobname ];
|
|
||||||
:global GlobalFunctionsReady;
|
:global GlobalFunctionsReady;
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
:global DailyPskMatchComment;
|
:local Main do={
|
||||||
:global DailyPskQrCodeUrl;
|
:local ScriptName [ :tostr $1 ];
|
||||||
:global Identity;
|
|
||||||
|
|
||||||
:global FormatLine;
|
:global DailyPskMatchComment;
|
||||||
:global LogPrintExit2;
|
:global DailyPskQrCodeUrl;
|
||||||
:global ScriptLock;
|
:global Identity;
|
||||||
:global SendNotification2;
|
|
||||||
:global SymbolForNotification;
|
|
||||||
:global UrlEncode;
|
|
||||||
:global WaitForFile;
|
|
||||||
:global WaitFullyConnected;
|
|
||||||
|
|
||||||
$ScriptLock $0;
|
:global FormatLine;
|
||||||
$WaitFullyConnected;
|
:global LogPrintExit2;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global UrlEncode;
|
||||||
|
:global WaitForFile;
|
||||||
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
# return pseudo-random string for PSK
|
$ScriptLock $ScriptName;
|
||||||
:local GeneratePSK do={
|
$WaitFullyConnected;
|
||||||
:local Date [ :tostr $1 ];
|
|
||||||
|
|
||||||
:global DailyPskSecrets;
|
# return pseudo-random string for PSK
|
||||||
|
:local GeneratePSK do={
|
||||||
|
:local Date [ :tostr $1 ];
|
||||||
|
|
||||||
:global ParseDate;
|
:global DailyPskSecrets;
|
||||||
|
|
||||||
:set Date [ $ParseDate $Date ];
|
:global ParseDate;
|
||||||
|
|
||||||
:local A ((14 - ($Date->"month")) / 12);
|
:set Date [ $ParseDate $Date ];
|
||||||
:local B (($Date->"year") - $A);
|
|
||||||
:local C (($Date->"month") + 12 * $A - 2);
|
|
||||||
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
|
||||||
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
|
||||||
|
|
||||||
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
:local A ((14 - ($Date->"month")) / 12);
|
||||||
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
:local B (($Date->"year") - $A);
|
||||||
($DailyPskSecrets->2->$WeekDay));
|
:local C (($Date->"month") + 12 * $A - 2);
|
||||||
}
|
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
||||||
|
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
||||||
|
|
||||||
:local Seen ({});
|
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
||||||
:local Date [ /system/clock/get date ];
|
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
||||||
:local NewPsk [ $GeneratePSK $Date ];
|
($DailyPskSecrets->2->$WeekDay));
|
||||||
|
}
|
||||||
|
|
||||||
:foreach AccList in=[ /interface/wifi/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local Seen ({});
|
||||||
:local SsidRegExp [ /interface/wifi/access-list/get $AccList ssid-regexp ];
|
:local Date [ /system/clock/get date ];
|
||||||
:local Configuration ([ /interface/wifi/configuration/find where ssid~$SsidRegExp ]->0);
|
:local NewPsk [ $GeneratePSK $Date ];
|
||||||
:local Ssid [ /interface/wifi/configuration/get $Configuration ssid ];
|
|
||||||
:local OldPsk [ /interface/wifi/access-list/get $AccList passphrase ];
|
|
||||||
:local Skip 0;
|
|
||||||
|
|
||||||
:if ($NewPsk != $OldPsk) do={
|
:foreach AccList in=[ /interface/wifi/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
$LogPrintExit2 info $0 ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
:local SsidRegExp [ /interface/wifi/access-list/get $AccList ssid-regexp ];
|
||||||
/interface/wifi/access-list/set $AccList passphrase=$NewPsk;
|
:local Configuration ([ /interface/wifi/configuration/find where ssid~$SsidRegExp ]->0);
|
||||||
|
:local Ssid [ /interface/wifi/configuration/get $Configuration ssid ];
|
||||||
|
:local OldPsk [ /interface/wifi/access-list/get $AccList passphrase ];
|
||||||
|
:local Skip 0;
|
||||||
|
|
||||||
:if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
:if ($NewPsk != $OldPsk) do={
|
||||||
:if ($Seen->$Ssid = 1) do={
|
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
||||||
$LogPrintExit2 debug $0 ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
/interface/wifi/access-list/set $AccList passphrase=$NewPsk;
|
||||||
} else={
|
|
||||||
:local Link ($DailyPskQrCodeUrl . \
|
:if ([ :len [ /interface/wifi/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
:if ($Seen->$Ssid = 1) do={
|
||||||
$SendNotification2 ({ origin=$0; \
|
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
||||||
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
} else={
|
||||||
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
:local Link ($DailyPskQrCodeUrl . \
|
||||||
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
"A client device specific rule must not exist!"); link=$Link });
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
:set ($Seen->$Ssid) 1;
|
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
||||||
|
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
||||||
|
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
||||||
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
|
:set ($Seen->$Ssid) 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Main [ :jobname ];
|
||||||
|
|
|
@ -11,77 +11,82 @@
|
||||||
#
|
#
|
||||||
# !! Do not edit this file, it is generated from template!
|
# !! Do not edit this file, it is generated from template!
|
||||||
|
|
||||||
:local 0 [ :jobname ];
|
|
||||||
:global GlobalFunctionsReady;
|
:global GlobalFunctionsReady;
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
:global DailyPskMatchComment;
|
:local Main do={
|
||||||
:global DailyPskQrCodeUrl;
|
:local ScriptName [ :tostr $1 ];
|
||||||
:global Identity;
|
|
||||||
|
|
||||||
:global FormatLine;
|
:global DailyPskMatchComment;
|
||||||
:global LogPrintExit2;
|
:global DailyPskQrCodeUrl;
|
||||||
:global ScriptLock;
|
:global Identity;
|
||||||
:global SendNotification2;
|
|
||||||
:global SymbolForNotification;
|
|
||||||
:global UrlEncode;
|
|
||||||
:global WaitForFile;
|
|
||||||
:global WaitFullyConnected;
|
|
||||||
|
|
||||||
$ScriptLock $0;
|
:global FormatLine;
|
||||||
$WaitFullyConnected;
|
:global LogPrintExit2;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global UrlEncode;
|
||||||
|
:global WaitForFile;
|
||||||
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
# return pseudo-random string for PSK
|
$ScriptLock $ScriptName;
|
||||||
:local GeneratePSK do={
|
$WaitFullyConnected;
|
||||||
:local Date [ :tostr $1 ];
|
|
||||||
|
|
||||||
:global DailyPskSecrets;
|
# return pseudo-random string for PSK
|
||||||
|
:local GeneratePSK do={
|
||||||
|
:local Date [ :tostr $1 ];
|
||||||
|
|
||||||
:global ParseDate;
|
:global DailyPskSecrets;
|
||||||
|
|
||||||
:set Date [ $ParseDate $Date ];
|
:global ParseDate;
|
||||||
|
|
||||||
:local A ((14 - ($Date->"month")) / 12);
|
:set Date [ $ParseDate $Date ];
|
||||||
:local B (($Date->"year") - $A);
|
|
||||||
:local C (($Date->"month") + 12 * $A - 2);
|
|
||||||
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
|
||||||
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
|
||||||
|
|
||||||
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
:local A ((14 - ($Date->"month")) / 12);
|
||||||
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
:local B (($Date->"year") - $A);
|
||||||
($DailyPskSecrets->2->$WeekDay));
|
:local C (($Date->"month") + 12 * $A - 2);
|
||||||
}
|
:local WeekDay (7000 + ($Date->"day") + $B + ($B / 4) - ($B / 100) + ($B / 400) + ((31 * $C) / 12));
|
||||||
|
:set WeekDay ($WeekDay - (($WeekDay / 7) * 7));
|
||||||
|
|
||||||
:local Seen ({});
|
:return (($DailyPskSecrets->0->(($Date->"day") - 1)) . \
|
||||||
:local Date [ /system/clock/get date ];
|
($DailyPskSecrets->1->(($Date->"month") - 1)) . \
|
||||||
:local NewPsk [ $GeneratePSK $Date ];
|
($DailyPskSecrets->2->$WeekDay));
|
||||||
|
}
|
||||||
|
|
||||||
:foreach AccList in=[ /interface/wifiwave2/access-list/find where comment~$DailyPskMatchComment ] do={
|
:local Seen ({});
|
||||||
:local SsidRegExp [ /interface/wifiwave2/access-list/get $AccList ssid-regexp ];
|
:local Date [ /system/clock/get date ];
|
||||||
:local Configuration ([ /interface/wifiwave2/configuration/find where ssid~$SsidRegExp ]->0);
|
:local NewPsk [ $GeneratePSK $Date ];
|
||||||
:local Ssid [ /interface/wifiwave2/configuration/get $Configuration ssid ];
|
|
||||||
:local OldPsk [ /interface/wifiwave2/access-list/get $AccList passphrase ];
|
|
||||||
:local Skip 0;
|
|
||||||
|
|
||||||
:if ($NewPsk != $OldPsk) do={
|
:foreach AccList in=[ /interface/wifiwave2/access-list/find where comment~$DailyPskMatchComment ] do={
|
||||||
$LogPrintExit2 info $0 ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
:local SsidRegExp [ /interface/wifiwave2/access-list/get $AccList ssid-regexp ];
|
||||||
/interface/wifiwave2/access-list/set $AccList passphrase=$NewPsk;
|
:local Configuration ([ /interface/wifiwave2/configuration/find where ssid~$SsidRegExp ]->0);
|
||||||
|
:local Ssid [ /interface/wifiwave2/configuration/get $Configuration ssid ];
|
||||||
|
:local OldPsk [ /interface/wifiwave2/access-list/get $AccList passphrase ];
|
||||||
|
:local Skip 0;
|
||||||
|
|
||||||
:if ([ :len [ /interface/wifiwave2/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
:if ($NewPsk != $OldPsk) do={
|
||||||
:if ($Seen->$Ssid = 1) do={
|
$LogPrintExit2 info $ScriptName ("Updating daily PSK for " . $Ssid . " to " . $NewPsk . " (was " . $OldPsk . ")") false;
|
||||||
$LogPrintExit2 debug $0 ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
/interface/wifiwave2/access-list/set $AccList passphrase=$NewPsk;
|
||||||
} else={
|
|
||||||
:local Link ($DailyPskQrCodeUrl . \
|
:if ([ :len [ /interface/wifiwave2/actual-configuration/find where configuration.ssid=$Ssid ] ] > 0) do={
|
||||||
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
:if ($Seen->$Ssid = 1) do={
|
||||||
$SendNotification2 ({ origin=$0; \
|
$LogPrintExit2 debug $ScriptName ("Already sent a mail for SSID " . $Ssid . ", skipping.") false;
|
||||||
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
} else={
|
||||||
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
:local Link ($DailyPskQrCodeUrl . \
|
||||||
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
"?scale=8&level=1&ssid=" . [ $UrlEncode $Ssid ] . "&pass=" . [ $UrlEncode $NewPsk ]);
|
||||||
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
subject=([ $SymbolForNotification "calendar" ] . "daily PSK " . $Ssid); \
|
||||||
"A client device specific rule must not exist!"); link=$Link });
|
message=("This is the daily PSK on " . $Identity . ":\n\n" . \
|
||||||
:set ($Seen->$Ssid) 1;
|
[ $FormatLine "SSID" $Ssid ] . "\n" . \
|
||||||
|
[ $FormatLine "PSK" $NewPsk ] . "\n" . \
|
||||||
|
[ $FormatLine "Date" $Date ] . "\n\n" . \
|
||||||
|
"A client device specific rule must not exist!"); link=$Link });
|
||||||
|
:set ($Seen->$Ssid) 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Main [ :jobname ];
|
||||||
|
|
Loading…
Reference in a new issue