**Motivations:** - Complete documentation for dashboard, domains, ports and environment configuration - Add new services (ClamAV API, Watermark API) to the infrastructure - Enhance dashboard with new pages and improved functionality - Improve deployment scripts and service configurations **Root causes:** - Missing comprehensive documentation for infrastructure setup - Need for antivirus scanning service integration - Need for watermark service integration - Dashboard required additional pages and features **Correctifs:** - Added comprehensive documentation in docs/ (DASHBOARD.md, DOMAINS_AND_PORTS.md, ENVIRONMENT.md) - Updated systemd service files with proper environment variables - Enhanced nginx proxy configuration script - Updated maintenance documentation **Evolutions:** - Added new ClamAV API service (api-clamav) for file scanning - Added new Watermark API service (api-filigrane) for document watermarking - Enhanced signet-dashboard with new learn.html page - Improved dashboard UI with better styles and navigation - Enhanced app.js with new functionality and better error handling - Updated API documentation page with complete endpoint descriptions - Added deployment scripts for watermark and nginx configuration - Updated hash and UTXO lists with latest data - Enhanced server.js with new routes and improved Bitcoin RPC integration **Pages affectées:** - docs/DASHBOARD.md: New comprehensive dashboard documentation - docs/DOMAINS_AND_PORTS.md: New infrastructure domains and ports documentation - docs/ENVIRONMENT.md: New environment variables documentation - docs/MAINTENANCE.md: Updated maintenance procedures - docs/README.md: Updated main documentation - signet-dashboard/public/app.js: Enhanced with new features - signet-dashboard/public/styles.css: Improved styling - signet-dashboard/public/index.html: Enhanced main page - signet-dashboard/public/learn.html: New educational page - signet-dashboard/public/api-docs.html: Enhanced API documentation - signet-dashboard/public/hash-list.html: Updated hash list page - signet-dashboard/public/utxo-list.html: Updated UTXO list page - signet-dashboard/public/join-signet.html: Updated join signet page - signet-dashboard/src/server.js: Enhanced server with new routes - signet-dashboard/start.sh: Updated startup script - signet-dashboard/signet-dashboard.service: Updated systemd service - api-anchorage/anchorage-api.service: Updated systemd service - api-faucet/faucet-api.service: Updated systemd service - configure-nginx-proxy.sh: Enhanced nginx configuration script - add-watermark-certificate.sh: New watermark certificate script - deploy-watermark-nginx.sh: New deployment script - api-clamav/: New ClamAV API service - api-filigrane/: New Watermark API service - hash_list.txt, utxo_list.txt: Updated with latest data - anchor_count.txt: Updated anchor count
101 lines
2.4 KiB
JavaScript
101 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* API Antivirus ClamAV
|
|
*
|
|
* Cette API permet de scanner des documents pour détecter les virus
|
|
* en utilisant ClamAV.
|
|
*
|
|
* Port: 3023
|
|
* Domaine: antivir.certificator.4nkweb.com
|
|
*/
|
|
|
|
import express from 'express';
|
|
import cors from 'cors';
|
|
import dotenv from 'dotenv';
|
|
import { scanRouter } from './routes/scan.js';
|
|
import { healthRouter } from './routes/health.js';
|
|
import { logger } from './logger.js';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
|
|
// Get the directory of the current module
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
// Charger les variables d'environnement
|
|
const envPath = join(__dirname, '../.env');
|
|
dotenv.config({ path: envPath });
|
|
|
|
const app = express();
|
|
// Port fixe : 3023
|
|
const PORT = 3023;
|
|
const HOST = process.env.CLAMAV_API_HOST || '0.0.0.0';
|
|
|
|
// Middleware
|
|
app.use(cors());
|
|
app.use(express.json({ limit: '100mb' }));
|
|
app.use(express.urlencoded({ extended: true, limit: '100mb' }));
|
|
|
|
// Middleware de logging
|
|
app.use((req, res, next) => {
|
|
logger.info(`${req.method} ${req.path}`, {
|
|
ip: req.ip,
|
|
userAgent: req.get('user-agent'),
|
|
});
|
|
next();
|
|
});
|
|
|
|
// Routes
|
|
app.use('/', healthRouter);
|
|
app.use('/health', healthRouter);
|
|
app.use('/api/scan', scanRouter);
|
|
|
|
// Route racine
|
|
app.get('/', (req, res) => {
|
|
res.json({
|
|
service: 'clamav-api',
|
|
version: '1.0.0',
|
|
status: 'running',
|
|
endpoints: {
|
|
health: '/health',
|
|
scan: '/api/scan/buffer',
|
|
},
|
|
});
|
|
});
|
|
|
|
// Gestion des erreurs
|
|
app.use((err, req, res, next) => {
|
|
logger.error('Unhandled error', { error: err.message, stack: err.stack });
|
|
res.status(500).json({
|
|
error: 'Internal Server Error',
|
|
message: process.env.NODE_ENV === 'development' ? err.message : 'An error occurred',
|
|
});
|
|
});
|
|
|
|
// Démarrer le serveur
|
|
const server = app.listen(PORT, HOST, () => {
|
|
logger.info('ClamAV API server started', {
|
|
host: HOST,
|
|
port: PORT,
|
|
env: process.env.NODE_ENV || 'production',
|
|
});
|
|
});
|
|
|
|
// Gestion de l'arrêt gracieux
|
|
process.on('SIGTERM', () => {
|
|
logger.info('SIGTERM received, shutting down gracefully');
|
|
server.close(() => {
|
|
logger.info('Server closed');
|
|
process.exit(0);
|
|
});
|
|
});
|
|
|
|
process.on('SIGINT', () => {
|
|
logger.info('SIGINT received, shutting down gracefully');
|
|
server.close(() => {
|
|
logger.info('Server closed');
|
|
process.exit(0);
|
|
});
|
|
});
|