global-functions: $IsTimeSync: cache a positive result

The functions do not rely on perfectly synced time. About the right time
is fine, that should make sure certificates are valid and mails are sent
with reasonable headers. So cache the result if system is fine for later
use.
This commit is contained in:
Christian Hesse 2022-07-21 13:36:37 +02:00
parent 329e606b93
commit 82f27268b3

View file

@ -481,10 +481,17 @@
# check if system time is sync
:set IsTimeSync do={
:global IsTimeSyncCached;
:global LogPrintExit2;
:if ($IsTimeSyncCached = true) do={
:return true;
}
:if ([ /system/ntp/client/get enabled ] = true) do={
:if ([ /system/ntp/client/get status ] = "synchronized") do={
:set IsTimeSyncCached true;
:return true;
}
:return false;
@ -492,6 +499,7 @@
:if ([ /ip/cloud/get update-time ] = true) do={
:if ([ :typeof [ /ip/cloud/get public-address ] ] = "ip") do={
:set IsTimeSyncCached true;
:return true;
}
:return false;