This commit is contained in:
2025-11-18 19:36:08 +00:00
parent b94aa17eee
commit 11142b9cb0
6 changed files with 55 additions and 0 deletions

View File

@@ -224,6 +224,13 @@ export class OneboxHttpServer {
} else if (path.match(/^\/api\/ssl\/[^/]+\/renew$/) && method === 'POST') {
const domain = path.split('/')[3];
return await this.handleRenewCertificateRequest(domain);
} else if (path === '/api/domains' && method === 'GET') {
return await this.handleGetDomainsRequest();
} else if (path === '/api/domains/sync' && method === 'POST') {
return await this.handleSyncDomainsRequest();
} else if (path.match(/^\/api\/domains\/[^/]+$/) && method === 'GET') {
const domainName = path.split('/').pop()!;
return await this.handleGetDomainDetailRequest(domainName);
} else {
return this.jsonResponse({ success: false, error: 'Not found' }, 404);
}

View File

@@ -89,6 +89,52 @@ export class OneboxSslManager {
return this.smartacme !== null && this.acmeEmail !== null;
}
/**
* Acquire certificate and return certificate data (for CertRequirementManager)
* Returns certificate paths and expiry information
*/
async acquireCertificate(
domain: string,
includeWildcard = false
): Promise<{
certPath: string;
keyPath: string;
fullChainPath: string;
expiryDate: number;
issuer: string;
}> {
try {
if (!this.isConfigured()) {
throw new Error('SSL manager not configured');
}
logger.info(`Acquiring SSL certificate for ${domain} via SmartACME DNS-01...`);
// Use SmartACME to obtain certificate via DNS-01 challenge
const cert = await this.smartacme!.getCertificateForDomain(domain, {
includeWildcard,
});
logger.success(`SSL certificate obtained for ${domain}`);
logger.info(`Certificate valid until: ${new Date(cert.validUntil).toISOString()}`);
// Reload certificates in reverse proxy
await this.oneboxRef.reverseProxy.reloadCertificates();
// Return certificate data
return {
certPath: cert.certFilePath,
keyPath: cert.keyFilePath,
fullChainPath: cert.chainFilePath || cert.certFilePath,
expiryDate: cert.validUntil,
issuer: cert.issuer || 'Let\'s Encrypt',
};
} catch (error) {
logger.error(`Failed to acquire certificate for ${domain}: ${error.message}`);
throw error;
}
}
/**
* Obtain SSL certificate for a domain using SmartACME
*/