Fixed Color Logic

This commit is contained in:
2026-02-12 21:33:15 +00:00
parent 4864cd6a3e
commit ccc0720cfc
4 changed files with 47 additions and 11 deletions

View File

@@ -20,7 +20,7 @@ use function PHPSTORM_META\type;
}
}
function status_class_bg($ssl, $word, $expiry, $retcol=null){
function status_class_bg($ssl, $word, $expiry, $retcol=null, $showday="null"){
// CSS CLASS
$red = "alert_red";
@@ -38,6 +38,10 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null){
$days = ssl_days_left($expiry);
if ($showday == "on"){
return $days;
}
if ($ssl != 1 || $word != 1) {
echo $red;
return;
@@ -45,7 +49,6 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null){
if ($days !== null) {
if ($days <= SSL_CRITICAL_DAYS) {
@@ -53,7 +56,7 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null){
if ($retcol){ // CRITICAL
echo $style . $col_orange . ";'";
}else{
echo $red;
echo $orange;
return;
}
}elseif ($days <= SSL_WARNING_DAYS) {
@@ -123,6 +126,21 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null){
$ssl_expiry=$check_element['ssl-expiry'];
$ssl_company=$check_element['ssl-company'];
$http_error=$check_element['content_http_code'];
$expirying_days=status_class_bg($sslcheck_ok, $checkword_ok, $ssl_expiry, false, 'on');
$col_red = "#ff4747";
$col_orange = "#ff830f";
$col_yellow = "#ffd70f";
$col_green = "#42c500";
if($expirying_days < 0){
$expiry_col='style="font-weight:bold; color:' . $col_red . ';"';
}elseif($expirying_days <= SSL_CRITICAL_DAYS ){
$expiry_col='style="font-weight:bold; color:' . $col_orange . ';"';
}elseif($expirying_days <= SSL_WARNING_DAYS){
$expiry_col='style="font-weight:bold; color:' . $col_yellow . ';"';
}else{
$expiry_col='style="font-weight:bold; color:' . $col_green . ';"';
}
if ($path == ""){
$path = "/";
@@ -139,13 +157,14 @@ function status_class_bg($ssl, $word, $expiry, $retcol=null){
<div class="alert-details">
<div><b>WORD TO CHECK: </b> <span><?= $wordtocheck ?></span></div>
<div><b>SSL RELEASED: </b> <span><?= $ssl_released ?></span></div>
<div><b>SSL EXPIRY: </b> <span <?php echo status_class_bg($sslcheck_ok, $checkword_ok, $ssl_expiry, true)?>> <?= $ssl_expiry ?></span></div>
<div><b>SSL EXPIRY: </b> <span <?= $expiry_col ?>> <?= $ssl_expiry ?></span></div>
<div><b>SSL DAYS LEFT: </b> <span <?= $expiry_col ?>><?= $expirying_days ?></span></div>
<div><b>SSL COMPANY: </b> <span> <?= $ssl_company ?></span></div>
<div><b>PATH: </b> <span><?= $path ?></span></div>
<div><b>ERROR CODE: </b> <span><?= $http_error ?></span></div>
</div>
</div>
</div>
<?php
}

View File

@@ -7,6 +7,22 @@ $timeout = 10; // timeout secondi per connessioni
// --- Helpers ---
// Estrae hostname da domain (rimuove eventuali schema/port/path)
function ssl_days_left($expiry_date) {
if (empty($expiry_date)) return null;
$expiry = DateTime::createFromFormat('d/m/Y', $expiry_date);
if (!$expiry) return null;
$now = new DateTime();
$interval = $now->diff($expiry);
$days = (int)$interval->format('%r%a'); // giorni con segno
return $days;
}
function normalizeDomainHost(string $domain): string {
// rimuovi schema se presente
if (preg_match('#^https?://#i', $domain)) {

View File

@@ -1,7 +1,8 @@
<footer>
<div>
<span><b>TOTAL DOMAIN: </b> <?php get_totals('total') ?></span>
<span><b>TOTAL DOMAIN: </b> <?php get_totals('total') ?>
</span>
</div>
<div>
<span><b>TOTAL OK: </b> <?php get_totals('ok') ?></span>
@@ -22,7 +23,7 @@
aggiornaDati();
// Ripete la chiamata ogni 10 secondi (10000 millisecondi)
setInterval(aggiornaDati, 10000);
setInterval(aggiornaDati, 30000);
</script>
</body>
</html>

View File

@@ -33,9 +33,9 @@
"path": "/doku.php?id=start",
"wordtocheck": "Benvenuto",
"wordcheck_ok": 1,
"sslcheck_ok": 0,
"sslcheck_ok": 1,
"ssl-released": "24/12/2025",
"ssl-expiry": "15/02/2026",
"ssl-expiry": "3/02/2026",
"ssl-company": "Cloudflare TLS Issuing ECC CA 3",
"content_http_code": 200,
"content_error": null,