| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace application\controllers;
- class GetSSLDaysController {
- public static function getSSLDays($data): void {
- $domain = $data['domain'] ?? '';
- if (empty($domain)) {
- http_response_code(400);
- echo json_encode(['error' => 'Missing required parameter: domain']);
- return;
- }
- exec("sudo certbot certificates --cert-name $domain | grep 'Expiry' | sed 's/..:..:..+..:..../\n/g
- ' | sed 's/days)//g' | sed 's/[[:space:]]//g' | cut -d: -f2", $phpOutput, $phpReturnCode);
-
- /*
- $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;
- }
- $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;
- }
- $expiryTimestamp = $certData['validTo_time_t'];
- $expiryDate = date('Y-m-d', $expiryTimestamp);
- $daysRemaining = ceil(($expiryTimestamp - time()) / 86400);
- */
- logModuleCall(
- 'siteBuilder',
- __FUNCTION__,
- $data,
- 'Debug',
- $phpOutput
- );
- echo json_encode([
- 'ssl_expiry' => $phpOutput,
- 'ssl_remaining' => $phpOutput
- ]);
- }
- }
|