Remove SSL Checker service
Remove the SSL Checker service from the React application, as the SSL checks are now handled by the Go backend. This involves removing the `sslCheckerService.ts` file and related imports.
This commit is contained in:
@@ -2,9 +2,6 @@
|
|||||||
// Re-export all SSL-related functionality for domain SSL checking
|
// Re-export all SSL-related functionality for domain SSL checking
|
||||||
// Use explicit re-exports to avoid naming conflicts
|
// Use explicit re-exports to avoid naming conflicts
|
||||||
|
|
||||||
// SSL Checker service
|
|
||||||
export { checkSSLCertificate, checkSSLApi } from './sslCheckerService';
|
|
||||||
|
|
||||||
// SSL Status utilities
|
// SSL Status utilities
|
||||||
export { determineSSLStatus } from './sslStatusUtils';
|
export { determineSSLStatus } from './sslStatusUtils';
|
||||||
|
|
||||||
@@ -28,10 +25,7 @@ export {
|
|||||||
} from './notification';
|
} from './notification';
|
||||||
|
|
||||||
// Export types
|
// Export types
|
||||||
export type { SSLCheckerResponse, SSLCertificate, AddSSLCertificateDto, SSLNotification } from './types';
|
export type { SSLCertificate, AddSSLCertificateDto, SSLNotification } from './types';
|
||||||
|
|
||||||
// Export utility functions
|
// Export utility functions for SSL operations
|
||||||
export { normalizeDomain, createErrorResponse } from './sslCheckerUtils';
|
export { calculateDaysRemaining, isValid } from './utils';
|
||||||
|
|
||||||
// Export checking mechanisms
|
|
||||||
export { checkWithFetch } from './sslPrimaryChecker';
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
import { pb } from "@/lib/pocketbase";
|
import { pb } from "@/lib/pocketbase";
|
||||||
import { SSLCertificate } from "../types";
|
import { SSLCertificate } from "../types";
|
||||||
import { checkSSLCertificate } from "../sslCheckerService";
|
|
||||||
import { determineSSLStatus } from "../sslStatusUtils";
|
import { determineSSLStatus } from "../sslStatusUtils";
|
||||||
import { sendSSLNotification } from "./sslNotificationSender";
|
import { sendSSLNotification } from "./sslNotificationSender";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@@ -35,20 +34,14 @@ export async function checkAllCertificatesAndNotify(): Promise<void> {
|
|||||||
/**
|
/**
|
||||||
* Checks a specific SSL certificate and sends notification if needed
|
* Checks a specific SSL certificate and sends notification if needed
|
||||||
* This respects the Warning and Expiry Thresholds set on the certificate
|
* This respects the Warning and Expiry Thresholds set on the certificate
|
||||||
|
* Note: SSL checking is now handled by the Go service, this function focuses on notifications
|
||||||
*/
|
*/
|
||||||
export async function checkCertificateAndNotify(certificate: SSLCertificate): Promise<boolean> {
|
export async function checkCertificateAndNotify(certificate: SSLCertificate): Promise<boolean> {
|
||||||
console.log(`Checking certificate for ${certificate.domain}...`);
|
console.log(`Checking certificate for ${certificate.domain}...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get fresh SSL data
|
// Use the current certificate data (updated by Go service)
|
||||||
const sslData = await checkSSLCertificate(certificate.domain);
|
const daysLeft = certificate.days_left || 0;
|
||||||
if (!sslData || !sslData.result) {
|
|
||||||
console.error(`Failed to check SSL for ${certificate.domain}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract days left from the check result
|
|
||||||
const daysLeft = sslData.result.days_left || 0;
|
|
||||||
|
|
||||||
// Get threshold values (ensure they are numbers)
|
// Get threshold values (ensure they are numbers)
|
||||||
const warningThreshold = Number(certificate.warning_threshold) || 30;
|
const warningThreshold = Number(certificate.warning_threshold) || 30;
|
||||||
@@ -76,21 +69,10 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
|
|||||||
|
|
||||||
console.log(`${certificate.domain}: ${daysLeft} days left, status: ${status}, should notify: ${shouldNotify}, critical: ${isCritical}`);
|
console.log(`${certificate.domain}: ${daysLeft} days left, status: ${status}, should notify: ${shouldNotify}, critical: ${isCritical}`);
|
||||||
|
|
||||||
// Update certificate data in database
|
// Update certificate status in database
|
||||||
const updateData: Partial<SSLCertificate> = {
|
await pb.collection('ssl_certificates').update(certificate.id, {
|
||||||
days_left: daysLeft,
|
status: status
|
||||||
status: status,
|
});
|
||||||
// Other fields from the SSL check that should be updated
|
|
||||||
issuer_o: sslData.result.issuer_o || certificate.issuer_o,
|
|
||||||
valid_from: sslData.result.valid_from || certificate.valid_from,
|
|
||||||
valid_till: sslData.result.valid_till || certificate.valid_till,
|
|
||||||
validity_days: sslData.result.validity_days || certificate.validity_days,
|
|
||||||
cert_sans: sslData.result.cert_sans,
|
|
||||||
cert_alg: sslData.result.cert_alg,
|
|
||||||
serial_number: sslData.result.cert_sn
|
|
||||||
};
|
|
||||||
|
|
||||||
await pb.collection('ssl_certificates').update(certificate.id, updateData);
|
|
||||||
|
|
||||||
// Send notification if needed
|
// Send notification if needed
|
||||||
if (shouldNotify && certificate.notification_channel) {
|
if (shouldNotify && certificate.notification_channel) {
|
||||||
@@ -136,33 +118,3 @@ export async function checkCertificateAndNotify(certificate: SSLCertificate): Pr
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Manual trigger for certificate notification test
|
|
||||||
* Useful for testing notification channels
|
|
||||||
*/
|
|
||||||
export async function testCertificateNotification(certificate: SSLCertificate): Promise<boolean> {
|
|
||||||
try {
|
|
||||||
console.log(`Testing notification for ${certificate.domain}...`);
|
|
||||||
|
|
||||||
// Create test message
|
|
||||||
const message = `🧪 TEST: SSL Certificate notification for ${certificate.domain}.`;
|
|
||||||
|
|
||||||
// We set isCritical to false for test notifications
|
|
||||||
const notificationSent = await sendSSLNotification(certificate, message, false);
|
|
||||||
|
|
||||||
if (notificationSent) {
|
|
||||||
console.log(`Test notification sent for ${certificate.domain}`);
|
|
||||||
toast.success(`Test notification sent for ${certificate.domain}`);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
console.error(`Failed to send test notification for ${certificate.domain}`);
|
|
||||||
toast.error(`Failed to send test notification for ${certificate.domain}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error sending test notification for ${certificate.domain}:`, error);
|
|
||||||
toast.error(`Error sending test notification: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +1,32 @@
|
|||||||
|
|
||||||
import { pb } from "@/lib/pocketbase";
|
import { pb } from "@/lib/pocketbase";
|
||||||
import type { AddSSLCertificateDto, SSLCertificate } from "./types";
|
import type { AddSSLCertificateDto, SSLCertificate } from "./types";
|
||||||
import { checkSSLCertificate } from "./sslCheckerService";
|
|
||||||
import { determineSSLStatus } from "./sslStatusUtils";
|
import { determineSSLStatus } from "./sslStatusUtils";
|
||||||
import { checkCertificateAndNotify } from "./notification"; // Import notification service
|
import { checkCertificateAndNotify } from "./notification"; // Import notification service
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new SSL certificate to monitor
|
* Add a new SSL certificate to monitor
|
||||||
|
* Note: SSL checking is now handled by the Go service
|
||||||
*/
|
*/
|
||||||
export const addSSLCertificate = async (
|
export const addSSLCertificate = async (
|
||||||
certificateData: AddSSLCertificateDto
|
certificateData: AddSSLCertificateDto
|
||||||
): Promise<SSLCertificate> => {
|
): Promise<SSLCertificate> => {
|
||||||
try {
|
try {
|
||||||
// First check if the SSL certificate is valid and can be fetched
|
|
||||||
const sslData = await checkSSLCertificate(certificateData.domain);
|
|
||||||
|
|
||||||
if (!sslData || !sslData.result) {
|
|
||||||
throw new Error(`Could not fetch SSL certificate for ${certificateData.domain}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare the data for saving to database
|
// Prepare the data for saving to database
|
||||||
|
// The Go service will handle the actual SSL checking
|
||||||
const data = {
|
const data = {
|
||||||
domain: certificateData.domain,
|
domain: certificateData.domain,
|
||||||
issued_to: sslData.result.issued_to || certificateData.domain,
|
issued_to: certificateData.domain, // Will be updated by Go service
|
||||||
issuer_o: sslData.result.issuer_o || "",
|
issuer_o: "", // Will be updated by Go service
|
||||||
status: determineSSLStatus(
|
status: "pending", // Initial status
|
||||||
sslData.result.days_left || 0,
|
cert_sans: "",
|
||||||
certificateData.warning_threshold,
|
cert_alg: "",
|
||||||
certificateData.expiry_threshold
|
serial_number: "",
|
||||||
),
|
valid_from: new Date().toISOString(), // Will be updated by Go service
|
||||||
cert_sans: sslData.result.cert_sans || "",
|
valid_till: new Date().toISOString(), // Will be updated by Go service
|
||||||
cert_alg: sslData.result.cert_alg || "",
|
validity_days: 0, // Will be updated by Go service
|
||||||
serial_number: sslData.result.cert_sn || "",
|
days_left: 0, // Will be updated by Go service
|
||||||
valid_from: sslData.result.valid_from || new Date().toISOString(),
|
|
||||||
valid_till: sslData.result.valid_till || new Date().toISOString(),
|
|
||||||
validity_days: sslData.result.validity_days || 0,
|
|
||||||
days_left: sslData.result.days_left || 0,
|
|
||||||
warning_threshold: Number(certificateData.warning_threshold) || 30,
|
warning_threshold: Number(certificateData.warning_threshold) || 30,
|
||||||
expiry_threshold: Number(certificateData.expiry_threshold) || 7,
|
expiry_threshold: Number(certificateData.expiry_threshold) || 7,
|
||||||
notification_channel: certificateData.notification_channel || "",
|
notification_channel: certificateData.notification_channel || "",
|
||||||
@@ -54,6 +44,7 @@ export const addSSLCertificate = async (
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check and update a specific SSL certificate
|
* Check and update a specific SSL certificate
|
||||||
|
* Note: This now relies on the Go service for SSL data fetching
|
||||||
*/
|
*/
|
||||||
export const checkAndUpdateCertificate = async (
|
export const checkAndUpdateCertificate = async (
|
||||||
certificateId: string
|
certificateId: string
|
||||||
@@ -67,45 +58,13 @@ export const checkAndUpdateCertificate = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const typedCertificate = certificate as unknown as SSLCertificate;
|
const typedCertificate = certificate as unknown as SSLCertificate;
|
||||||
const domain = typedCertificate.domain;
|
|
||||||
|
|
||||||
// Check SSL certificate
|
// The Go service will handle the actual SSL checking and updating
|
||||||
const sslData = await checkSSLCertificate(domain);
|
// For now, we'll just trigger notifications based on current data
|
||||||
|
await checkCertificateAndNotify(typedCertificate);
|
||||||
|
|
||||||
if (!sslData || !sslData.result) {
|
// Return the current certificate data
|
||||||
throw new Error(`Could not fetch SSL certificate for ${domain}`);
|
return typedCertificate;
|
||||||
}
|
|
||||||
|
|
||||||
// Update certificate data
|
|
||||||
const updateData = {
|
|
||||||
issued_to: sslData.result.issued_to || domain,
|
|
||||||
issuer_o: sslData.result.issuer_o || typedCertificate.issuer_o,
|
|
||||||
status: determineSSLStatus(
|
|
||||||
sslData.result.days_left || 0,
|
|
||||||
typedCertificate.warning_threshold,
|
|
||||||
typedCertificate.expiry_threshold
|
|
||||||
),
|
|
||||||
cert_sans: sslData.result.cert_sans || typedCertificate.cert_sans,
|
|
||||||
cert_alg: sslData.result.cert_alg || typedCertificate.cert_alg,
|
|
||||||
serial_number: sslData.result.cert_sn || typedCertificate.serial_number,
|
|
||||||
valid_from: sslData.result.valid_from || typedCertificate.valid_from,
|
|
||||||
valid_till: sslData.result.valid_till || typedCertificate.valid_till,
|
|
||||||
validity_days: sslData.result.validity_days || typedCertificate.validity_days,
|
|
||||||
days_left: sslData.result.days_left || 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Update in database
|
|
||||||
const updatedCert = await pb
|
|
||||||
.collection("ssl_certificates")
|
|
||||||
.update(certificateId, updateData);
|
|
||||||
|
|
||||||
const updatedCertificate = updatedCert as unknown as SSLCertificate;
|
|
||||||
|
|
||||||
// After updating, check if notification should be sent
|
|
||||||
// This will respect the Warning and Expiry Thresholds
|
|
||||||
await checkCertificateAndNotify(updatedCertificate);
|
|
||||||
|
|
||||||
return updatedCertificate;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error updating SSL certificate:", error);
|
console.error("Error updating SSL certificate:", error);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -127,6 +86,7 @@ export const deleteSSLCertificate = async (id: string): Promise<boolean> => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh all SSL certificates
|
* Refresh all SSL certificates
|
||||||
|
* Note: The Go service handles the actual SSL checking
|
||||||
*/
|
*/
|
||||||
export const refreshAllCertificates = async (): Promise<{ success: number; failed: number }> => {
|
export const refreshAllCertificates = async (): Promise<{ success: number; failed: number }> => {
|
||||||
try {
|
try {
|
||||||
@@ -140,7 +100,7 @@ export const refreshAllCertificates = async (): Promise<{ success: number; faile
|
|||||||
|
|
||||||
for (const cert of certificates) {
|
for (const cert of certificates) {
|
||||||
try {
|
try {
|
||||||
await checkAndUpdateCertificate(cert.id);
|
await checkCertificateAndNotify(cert);
|
||||||
success++;
|
success++;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to refresh certificate ${cert.domain}:`, error);
|
console.error(`Failed to refresh certificate ${cert.domain}:`, error);
|
||||||
|
|||||||
@@ -1,74 +1,40 @@
|
|||||||
|
|
||||||
// SSL Checker response type
|
// SSL Certificate DTO for adding new certificates
|
||||||
export interface SSLCheckerResponse {
|
export interface AddSSLCertificateDto {
|
||||||
version: string;
|
domain: string;
|
||||||
app: string;
|
warning_threshold: number;
|
||||||
host: string;
|
expiry_threshold: number;
|
||||||
response_time_sec: string;
|
notification_channel: string;
|
||||||
status: string; // "ok", "error"
|
}
|
||||||
message?: string;
|
|
||||||
error?: string;
|
|
||||||
result: {
|
|
||||||
host: string;
|
|
||||||
resolved_ip?: string;
|
|
||||||
issued_to: string;
|
|
||||||
issued_o?: string | null;
|
|
||||||
issuer_c?: string;
|
|
||||||
issuer_o?: string | null;
|
|
||||||
issuer_ou?: string | null;
|
|
||||||
issuer_cn?: string;
|
|
||||||
cert_sn: string;
|
|
||||||
cert_sha1?: string;
|
|
||||||
cert_alg: string;
|
|
||||||
cert_ver?: number;
|
|
||||||
cert_sans: string;
|
|
||||||
cert_exp?: boolean;
|
|
||||||
cert_valid?: boolean;
|
|
||||||
valid_from?: string;
|
|
||||||
valid_till?: string;
|
|
||||||
validity_days?: number;
|
|
||||||
days_left?: number;
|
|
||||||
valid_days_to_expire?: number;
|
|
||||||
hsts_header_enabled?: boolean;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSL Certificate DTO for adding new certificates
|
// SSL Certificate model
|
||||||
export interface AddSSLCertificateDto {
|
export interface SSLCertificate {
|
||||||
domain: string;
|
id: string;
|
||||||
warning_threshold: number;
|
domain: string;
|
||||||
expiry_threshold: number;
|
issued_to: string;
|
||||||
notification_channel: string;
|
issuer_o: string;
|
||||||
}
|
status: string;
|
||||||
|
cert_sans?: string;
|
||||||
|
cert_alg?: string;
|
||||||
|
serial_number?: number | string;
|
||||||
|
valid_from: string;
|
||||||
|
valid_till: string;
|
||||||
|
validity_days: number;
|
||||||
|
days_left: number;
|
||||||
|
valid_days_to_expire?: number;
|
||||||
|
warning_threshold: number;
|
||||||
|
expiry_threshold: number;
|
||||||
|
notification_channel: string;
|
||||||
|
last_notified?: string;
|
||||||
|
created?: string;
|
||||||
|
updated?: string;
|
||||||
|
}
|
||||||
|
|
||||||
// SSL Certificate model
|
// SSL specific notification types
|
||||||
export interface SSLCertificate {
|
export interface SSLNotification {
|
||||||
id: string;
|
certificateId: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
issued_to: string;
|
message: string;
|
||||||
issuer_o: string;
|
isCritical: boolean;
|
||||||
status: string;
|
timestamp: string;
|
||||||
cert_sans?: string;
|
}
|
||||||
cert_alg?: string;
|
|
||||||
serial_number?: number | string;
|
|
||||||
valid_from: string;
|
|
||||||
valid_till: string;
|
|
||||||
validity_days: number;
|
|
||||||
days_left: number;
|
|
||||||
valid_days_to_expire?: number;
|
|
||||||
warning_threshold: number;
|
|
||||||
expiry_threshold: number;
|
|
||||||
notification_channel: string;
|
|
||||||
last_notified?: string;
|
|
||||||
created?: string;
|
|
||||||
updated?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SSL specific notification types
|
|
||||||
export interface SSLNotification {
|
|
||||||
certificateId: string;
|
|
||||||
domain: string;
|
|
||||||
message: string;
|
|
||||||
isCritical: boolean;
|
|
||||||
timestamp: string;
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
|
|
||||||
import { SSLCheckerResponse } from "./types";
|
|
||||||
|
|
||||||
// Calculate days remaining from expiration date
|
// Calculate days remaining from expiration date
|
||||||
export function calculateDaysRemaining(validTo: string): number {
|
export function calculateDaysRemaining(validTo: string): number {
|
||||||
try {
|
try {
|
||||||
@@ -23,29 +21,3 @@ export function isValid(validTo: string): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert results to our expected response format
|
|
||||||
export function convertResultToResponse(result: any): SSLCheckerResponse {
|
|
||||||
return {
|
|
||||||
version: "1.0",
|
|
||||||
app: "ssl-checker",
|
|
||||||
host: result.host || "",
|
|
||||||
response_time_sec: result.response_time_sec || "0.5",
|
|
||||||
status: result.status || "ok",
|
|
||||||
result: {
|
|
||||||
host: result.host || "",
|
|
||||||
issued_to: result.subject || result.host || "",
|
|
||||||
issuer_o: result.issuer || "Unknown",
|
|
||||||
cert_sn: result.serial_number || "0",
|
|
||||||
cert_alg: result.algorithm || "Unknown",
|
|
||||||
cert_sans: result.sans || "",
|
|
||||||
cert_exp: !result.is_valid,
|
|
||||||
cert_valid: result.is_valid || false,
|
|
||||||
valid_from: result.valid_from || new Date().toISOString(),
|
|
||||||
valid_till: result.valid_to || new Date().toISOString(),
|
|
||||||
validity_days: result.validity_days || 365,
|
|
||||||
days_left: result.days_remaining || 0,
|
|
||||||
valid_days_to_expire: result.days_remaining || 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
// This file re-exports all SSL certificate related services for backward compatibility
|
// This file re-exports all SSL certificate related services for backward compatibility
|
||||||
import {
|
import {
|
||||||
checkSSLCertificate,
|
|
||||||
fetchSSLCertificates,
|
fetchSSLCertificates,
|
||||||
addSSLCertificate,
|
addSSLCertificate,
|
||||||
checkAndUpdateCertificate
|
checkAndUpdateCertificate
|
||||||
@@ -17,7 +16,6 @@ import {
|
|||||||
} from './ssl/notification';
|
} from './ssl/notification';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
checkSSLCertificate,
|
|
||||||
determineSSLStatus,
|
determineSSLStatus,
|
||||||
fetchSSLCertificates,
|
fetchSSLCertificates,
|
||||||
addSSLCertificate,
|
addSSLCertificate,
|
||||||
|
|||||||
Reference in New Issue
Block a user