import datetime
import subprocess
def check_system_time():
try:
local_time = datetime.datetime.utcnow()
aws_time = subprocess.check_output("curl -s --head http://google.com | grep '^date:' | cut -d' ' -f3-6", shell=True).decode().strip()
if aws_time:
aws_time = datetime.datetime.strptime(aws_time, "%d %b %Y %H:%M:%S")
time_diff = abs((aws_time - local_time).total_seconds())
if time_diff > 300: # More than 5 minutes difference
print(f"⚠️ WARNING: System clock is out of sync! (Drift: {int(time_diff)} seconds)")
print("🔥 FireProx may fail due to AWS signature expiration. Run sudo timedatectl set-ntp on to fix.")
except Exception as e:
print(f"⚠️ Could not verify system time: {e}")
check_system_time()