Fix: Display all SSL up to 200 records

- The SSL certs table in the SSL & Domain dashboard was not displaying all certs records
This commit is contained in:
Tola Leng
2025-07-15 16:21:56 +07:00
parent 6512d4974a
commit f235043417
5 changed files with 16 additions and 46 deletions
@@ -14,7 +14,7 @@ export async function sendSSLNotification(
try {
// Check if notification channel is set
if (!certificate.notification_channel) {
console.log(`No notification channel set for certificate: ${certificate.domain}`);
// console.log(`No notification channel set for certificate: ${certificate.domain}`);
return false;
}
@@ -22,12 +22,12 @@ export async function sendSSLNotification(
const alertConfigRecord = await pb.collection('alert_configurations').getOne(certificate.notification_channel);
if (!alertConfigRecord) {
console.error(`Alert configuration not found for ID: ${certificate.notification_channel}`);
// console.error(`Alert configuration not found for ID: ${certificate.notification_channel}`);
return false;
}
if (!alertConfigRecord.enabled) {
console.log(`Alert configuration is disabled for certificate: ${certificate.domain}`);
// console.log(`Alert configuration is disabled for certificate: ${certificate.domain}`);
return false;
}
@@ -63,7 +63,7 @@ export async function sendSSLNotification(
return await sendNotificationByType(alertConfig, certificate, message, isCritical, sslNotification);
} catch (error) {
console.error("Error sending SSL notification:", error);
// console.error("Error sending SSL notification:", error);
return false;
}
}
@@ -87,7 +87,7 @@ async function sendNotificationByType(
// case 'slack':
// return await sendSlackNotification(alertConfig, certificate, message, isCritical);
default:
console.log(`Notification type ${alertConfig.notification_type} not implemented yet for SSL certificates`);
// console.log(`Notification type ${alertConfig.notification_type} not implemented yet for SSL certificates`);
return false;
}
}
@@ -102,7 +102,7 @@ async function sendTelegramNotification(
isCritical: boolean
): Promise<boolean> {
if (!alertConfig.bot_token || !alertConfig.telegram_chat_id) {
console.error("Missing Telegram bot token or chat ID");
// console.error("Missing Telegram bot token or chat ID");
return false;
}
@@ -112,10 +112,10 @@ export const deleteSSLCertificate = async (id: string): Promise<boolean> => {
*/
export const refreshAllCertificates = async (): Promise<{ success: number; failed: number }> => {
try {
const response = await pb.collection("ssl_certificates").getList(1, 100);
const response = await pb.collection("ssl_certificates").getList(1, 200);
const certificates = response.items as unknown as SSLCertificate[];
console.log(`Refreshing ${certificates.length} certificates...`);
// console.log(`Refreshing ${certificates.length} certificates...`);
let success = 0;
let failed = 0;
@@ -125,14 +125,14 @@ export const refreshAllCertificates = async (): Promise<{ success: number; faile
await checkCertificateAndNotify(cert);
success++;
} catch (error) {
console.error(`Failed to refresh certificate ${cert.domain}:`, error);
// console.error(`Failed to refresh certificate ${cert.domain}:`, error);
failed++;
}
}
return { success, failed };
} catch (error) {
console.error("Error refreshing certificates:", error);
// console.error("Error refreshing certificates:", error);
throw error;
}
};
@@ -1,7 +1,6 @@
import type { SSLCheckerResponse } from "./types";
import { toast } from "sonner";
import { checkWithFetch } from "./sslPrimaryChecker";
import { normalizeDomain, createErrorResponse } from "./sslCheckerUtils";
/**
@@ -10,7 +9,7 @@ import { normalizeDomain, createErrorResponse } from "./sslCheckerUtils";
*/
export const checkSSLCertificate = async (domain: string): Promise<SSLCheckerResponse> => {
try {
console.log(`Checking SSL certificate for domain: ${domain}`);
// console.log(`Checking SSL certificate for domain: ${domain}`);
// Normalize domain (remove protocol if present)
const normalizedDomain = normalizeDomain(domain);
@@ -20,11 +19,11 @@ export const checkSSLCertificate = async (domain: string): Promise<SSLCheckerRes
}
// Use the working CORS proxy approach
const result = await checkWithFetch(normalizedDomain);
console.log("SSL check result:", result);
return result;
// const result = await checkWithFetch(normalizedDomain);
// console.log("SSL check result:", result);
// return result;
} catch (error) {
console.error("SSL check failed completely:", error);
//console.error("SSL check failed completely:", error);
toast.error(`SSL check failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
return createErrorResponse(domain, error);
}
@@ -14,7 +14,7 @@ export const fetchSSLCertificates = async (): Promise<SSLCertificate[]> => {
const endpoint = "/api/collections/ssl_certificates/records";
const params = {
page: 1,
perPage: 50,
perPage: 200,
sort: "-created",
cache: Date.now() // Prevent caching by adding a timestamp
};
@@ -1,29 +0,0 @@
import { createErrorResponse } from "./sslCheckerUtils";
import type { SSLCheckerResponse } from "./types";
/**
* Check SSL certificate using fetch with CORS proxy
* This is our primary method that's proven to work
*/
export const checkWithFetch = async (domain: string): Promise<SSLCheckerResponse> => {
console.log(`Checking SSL via CORS proxy for: ${domain}`);
try {
// Use the working CORS proxy
const corsProxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(`https://ssl-checker.io/api/v1/check/${domain}`)}`;
console.log("Using CORS proxy for SSL check:", corsProxyUrl);
const proxyResponse = await fetch(corsProxyUrl);
if (!proxyResponse.ok) {
throw new Error(`CORS proxy request failed with status: ${proxyResponse.status}`);
}
const proxyData = await proxyResponse.json();
console.log("CORS proxy returned SSL data:", proxyData);
return proxyData;
} catch (error) {
console.error("SSL check failed:", error);
return createErrorResponse(domain, error);
}
};