'' AND (certificate_checked_at IS NULL OR certificate_checked_at < NOW() - INTERVAL 20 HOUR) ORDER BY certificate_checked_at IS NOT NULL, certificate_checked_at ASC LIMIT 1000"); while ($row = mysqli_fetch_assoc($sql)) { if (time() - $started > 600) { break; } $check = certificateCheckAndSave($row['certificate_id']); if ($check === null) { // Not a host it can connect to - leave it be, but out of the queue until tomorrow mysqli_query($mysqli, "UPDATE certificates SET certificate_checked_at = NOW(), certificate_check_status = NULL WHERE certificate_id = " . intval($row['certificate_id'])); continue; } $status = empty($check['reachable']) ? 'unreachable' : $check['status']; $tally[$status]++; echo "{$row['certificate_domain']}: $status\n"; // Was fine yesterday, isn't today - someone installed the wrong one, or it lapsed. // (A host not answering is left to the list - that is as often a blip as a fault.) if ($row['certificate_check_status'] === 'ok' && in_array($status, ['mismatch', 'untrusted', 'expired'], true)) { $certificate_id = intval($row['certificate_id']); $client_id = intval($row['certificate_client_id']); appNotify("Certificate Problem", escapeSql("Certificate {$row['certificate_name']} for {$row['client_name']}: " . CERTIFICATE_CHECK_STATES[$status]['text']), "/agent/certificates.php?client_id=$client_id&open=$certificate_id", $client_id); } } $checked = array_sum($tally); if ($checked) { $parts = []; foreach ($tally as $status => $count) { if ($count) { $parts[] = "$count $status"; } } logApp("Cron-Certificate-Refresher", "info", "Checked $checked certificate(s): " . implode(', ', $parts) . '.'); }