Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
38 lines
3.9 KiB
JavaScript
Executable File
38 lines
3.9 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict';
|
|
// ============================================================================
|
|
// 와일드카드 인증서 감지·적용 명령줄 도구 (v1.5.17, 요구 1)
|
|
//
|
|
// 서버를 설치할 때 이미 *.<플랫폼 도메인> 인증서를 받아 둔 경우(certbot certonly -d '*.example.com' 등, 이름 무관)를 인지해
|
|
// 서브 도메인 사이트에 자동으로 HTTPS 를 적용하기 위한 도구. 설치·갱신 스크립트(deploy/install.sh, remote-install.sh, remote-update.sh)가
|
|
// 마지막에 한 번 부르고, 운영자가 직접 확인할 때도 쓴다.
|
|
//
|
|
// node scripts/ssl-wildcard.js 감지 결과만 출력 (플랫폼 도메인 · 찾은 인증서 · 후보 목록)
|
|
// node scripts/ssl-wildcard.js --apply 감지 뒤, HTTP 로 배포돼 있는 서브 도메인 사이트의 nginx 설정을 그 인증서로 다시 쓴다 (서비스 기동 때 autoApply 와 같음)
|
|
//
|
|
// 플랫폼 도메인은 관리자 설정(settings.domains.platformDomain), 비어 있으면 서비스 공개 주소에서 유도한다(webmaker.example.com → example.com).
|
|
// 환경 변수 DATA_ROOT / SITES_ROOT 는 서비스와 같게 준다. 배포 서버 목록이 아직 없으면(설치 직후) 이 서버 자신을 local 로 보고 감지만 한다.
|
|
// 종료 코드: 0 = 인증서 있음, 1 = 없음(또는 확인 못 함) — 스크립트에서는 || true 로 받는다.
|
|
// ============================================================================
|
|
const path = require('path');
|
|
const deploy = require('../lib/deploy');
|
|
const ssl = require('../lib/ssl');
|
|
|
|
(async () => {
|
|
const apply = process.argv.includes('--apply');
|
|
let d = await ssl.detect();
|
|
if (!d.target && d.platformDomain) { // 배포 서버가 아직 없음(설치 직후): 이 서버를 local 로 보고 감지만
|
|
try { d = { ...d, target: { id: null, name: '(이 서버)', type: 'local' }, cert: await deploy.findWildcardCert({ type: 'local' }, d.platformDomain), reason: '' }; } catch (e) { d.reason = e.message; }
|
|
}
|
|
const c = d.cert;
|
|
console.log(`플랫폼 도메인: ${d.platformDomain || '(없음 — 서비스 공개 주소가 IP 이거나 설정이 없음)'}${d.target ? ` · 배포 서버: ${d.target.name}` : ''}`);
|
|
if (!d.platformDomain) { console.log('와일드카드 인증서: 확인할 도메인이 없습니다. 도메인이 정해지면 설정 페이지에서 서비스 공개 주소(또는 관리자 콘솔 › 설정 › 도메인 서비스 › 플랫폼 도메인)를 넣으세요.'); process.exit(1); }
|
|
if (!c) { console.log(`와일드카드 인증서: 확인 못 함 — ${d.reason}`); process.exit(1); }
|
|
if (!c.hasCert) { console.log(`와일드카드 인증서 *.${d.platformDomain}: 없음 (letsencrypt 인증서 ${c.scanned || 0}개 확인) — 서브 도메인 사이트는 HTTP 로 열립니다. 관리자 콘솔 › 설정 › SSL 에서 발급하거나 서버에서 certbot 으로 *.${d.platformDomain} 인증서를 받아 두면(이름 무관) 자동 적용됩니다.`); process.exit(1); }
|
|
console.log(`와일드카드 인증서 *.${d.platformDomain}: 있음 — 이름 ${c.certName}${c.external ? ' (서버에 미리 발급된 인증서, 서비스가 발급한 것이 아님)' : ''}, SAN ${c.sans.join(', ')}, 만료 ${c.expires}${c.daysLeft != null ? ` (${c.daysLeft}일)` : ''} → 서브 도메인 사이트에 자동 적용`);
|
|
if (c.candidates && c.candidates.length > 1) console.log(` 후보 ${c.candidates.length}개: ${c.candidates.map((x) => `${x.name} (${x.expires})`).join(', ')}`);
|
|
if (apply && d.target && d.target.id) { const r = await ssl.autoApply(); console.log(`적용: 서브 도메인 사이트 ${r.reconfigured}개 설정을 HTTPS 로 갱신${r.sites.length ? ' (' + r.sites.join(', ') + ')' : ''}`); }
|
|
else if (apply) console.log('적용: 배포 서버가 아직 등록되지 않아 건너뜀 (서비스 기동 때 자동 적용됨)');
|
|
process.exit(0);
|
|
})().catch((e) => { console.error('오류: ' + e.message); process.exit(2); });
|