feat(admin): add comprehensive SSL certificate management page with shamsi/gregorian validity, live domain tester, and live Traefik volume sync
Deploy Canina / deploy (push) Successful in 41s
Deploy Canina / deploy (push) Successful in 41s
This commit is contained in:
1 parent
5c13dd2f29
commit
fd5eb9dd1d
9 files changed
+879
No files matched your search
@@ -0,0 +1,100 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user