ソースを参照

use certbot for gatering informations

andre 8 ヶ月 前
コミット
5d56011e7b
1 ファイル変更11 行追加26 行削除
  1. 11 26
      controllers/GetSSLDaysController.php

+ 11 - 26
controllers/GetSSLDaysController.php

@@ -12,33 +12,18 @@ class GetSSLDaysController {
         }
 
         exec("sudo certbot certificates --cert-name $domain | grep 'Expiry' | grep 'Expiry'", $phpOutput, $phpReturnCode);
-        $sslData = explode(" ",$phpOutput[0]);
-        /*
-        $certFile = "/etc/letsencrypt/live/$domain/fullchain.pem";
-        if (!file_exists($certFile)) {
-            error_log("certfile: " . $certFile);
-            http_response_code(404);
-            echo json_encode(['error' => 'SSL certificate not found']);
-            return;
-        }
-            [ssl_expiry] =>     Expiry Date: 2025-08-05 08:21:58+00:00 (VALID: 86 days)
 
-        $certData = openssl_x509_parse(file_get_contents($certFile));
-        if (!$certData || !isset($certData['validTo_time_t'])) {
-            http_response_code(500);
-            echo json_encode(['error' => 'Failed to parse SSL certificate']);
-            return;
+        if(empty($phpOutput)){
+            echo json_encode([
+                'ssl_expiry' => "-",
+                'ssl_remaining' => "-"
+            ]);
+        } else {
+            $sslData = explode(" ",$phpOutput[0]);
+            echo json_encode([
+                'ssl_expiry' => $sslData[6],
+                'ssl_remaining' => $sslData[9]
+            ]);
         }
-
-        $expiryTimestamp = $certData['validTo_time_t'];
-        $expiryDate = date('Y-m-d', $expiryTimestamp);
-        $daysRemaining = ceil(($expiryTimestamp - time()) / 86400);
-        */
-
-        echo json_encode([
-	        'ssl_expiry' => $sslData,
-	        'ssl_remaining' => $phpOutput
-	    ]);
-
     }
 }