- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
105 lines
3.3 KiB
TypeScript
105 lines
3.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
UseGuards,
|
|
UseInterceptors,
|
|
UploadedFiles,
|
|
Query,
|
|
BadRequestException,
|
|
} from "@nestjs/common";
|
|
import { AnyFilesInterceptor } from "@nestjs/platform-express";
|
|
import { SslService } from "./ssl.service";
|
|
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
|
|
import { RolesGuard } from "../common/guards/roles.guard";
|
|
import { Roles } from "../common/decorators/roles.decorator";
|
|
import { ApiTags, ApiBearerAuth, ApiOperation } from "@nestjs/swagger";
|
|
|
|
@ApiTags("Admin SSL - مدیریت گواهیهای امنیتی SSL")
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles("Admin")
|
|
@Controller("admin/ssl")
|
|
export class SslController {
|
|
constructor(private readonly sslService: SslService) {}
|
|
|
|
@Get("status")
|
|
@ApiOperation({ summary: "دریافت وضعیت و جزئیات گواهی SSL فعلی سرور" })
|
|
getStatus() {
|
|
const status = this.sslService.getStatus();
|
|
return { success: true, data: status };
|
|
}
|
|
|
|
@Post("update-text")
|
|
@ApiOperation({ summary: "بهروزرسانی گواهی SSL از طریق متن و کلید" })
|
|
updateByText(
|
|
@Body("certificate") certificate: string,
|
|
@Body("privateKey") privateKey: string,
|
|
) {
|
|
return this.sslService.updateCertificates(certificate, privateKey);
|
|
}
|
|
|
|
@Post("upload")
|
|
@UseInterceptors(AnyFilesInterceptor())
|
|
@ApiOperation({
|
|
summary: "آپلود فایلهای گواهی SSL (FullChain/CRT و PrivateKey)",
|
|
})
|
|
uploadFiles(
|
|
@UploadedFiles() files: Array<Express.Multer.File>,
|
|
@Body("certificateText") certText?: string,
|
|
@Body("privateKeyText") keyText?: string,
|
|
) {
|
|
let certContent = certText || "";
|
|
let keyContent = keyText || "";
|
|
|
|
if (files && files.length > 0) {
|
|
for (const file of files) {
|
|
const content = file.buffer.toString("utf8");
|
|
const fieldName = file.fieldname.toLowerCase();
|
|
const originalName = file.originalname.toLowerCase();
|
|
|
|
if (
|
|
fieldName.includes("cert") ||
|
|
fieldName.includes("fullchain") ||
|
|
fieldName.includes("crt") ||
|
|
originalName.endsWith(".crt") ||
|
|
originalName.includes("fullchain") ||
|
|
originalName.includes("cert") ||
|
|
content.includes("BEGIN CERTIFICATE")
|
|
) {
|
|
certContent = content;
|
|
} else if (
|
|
fieldName.includes("key") ||
|
|
originalName.endsWith(".key") ||
|
|
originalName.includes("priv") ||
|
|
content.includes("BEGIN PRIVATE KEY") ||
|
|
content.includes("BEGIN RSA PRIVATE KEY") ||
|
|
content.includes("BEGIN EC PRIVATE KEY")
|
|
) {
|
|
keyContent = content;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!certContent || !keyContent) {
|
|
throw new BadRequestException(
|
|
"ارسال هر دو فایل گواهی (Fullchain/CRT) و کلید خصوصی (Private Key) الزامی است.",
|
|
);
|
|
}
|
|
|
|
return this.sslService.updateCertificates(certContent, keyContent);
|
|
}
|
|
|
|
@Get("test-domain")
|
|
@ApiOperation({
|
|
summary: "بررسی آنلاین گواهی SSL یک دامنه مشخص روی پورت ۴۴۳",
|
|
})
|
|
testDomain(@Query("domain") domain: string) {
|
|
if (!domain) {
|
|
throw new BadRequestException("نام دامنه الزامی است");
|
|
}
|
|
return this.sslService.testOnlineDomainSsl(domain);
|
|
}
|
|
}
|