1773ed5f95
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m11s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m28s
Version and Release / version-bump (push) Successful in 32s
Version and Release / trigger-drone (push) Has been skipped
Original: feat: enhance security logging and ensure rate limit blocks are properly tracked - Add comprehensive logging for rate limit blocks with full request details - IP address (with proper proxy detection), user agent, headers, timestamps - Rate limit info (current count, limit, remaining, reset time) - Separate tracking for auth vs general endpoints - Enhance authentication failure logging - JWT validation failures with detailed error info - Admin auth attempts without token - Failed token validation with user context - All events include IP, path, method, user agent - Improve Winston logger configuration for production - Add automatic log rotation (10MB errors, 50MB combined) - Create separate security.log for auth/rate limit events - Ensure logs directory exists automatically - Add structured JSON format for log aggregation - Support container logging with LOG_TO_CONSOLE env var - Create comprehensive documentation - Security logging guide with examples - Monitoring recommendations - Configuration reference - Add test script to verify logging functionality All rate limit settings remain configurable via admin panel: - Window duration, max requests, auth limits - Skip authenticated requests option - Public endpoints only option 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
83 lines
2.3 KiB
JavaScript
83 lines
2.3 KiB
JavaScript
const express = require('express');
|
|
const { body, validationResult } = require('express-validator');
|
|
const { db, logActivity } = require('../database/db');
|
|
const { adminAuth } = require('../middleware/auth-enhanced-v2');
|
|
const router = express.Router();
|
|
|
|
// Get all CMS pages
|
|
router.get('/pages', adminAuth, async (req, res) => {
|
|
try {
|
|
const pages = await db('cms_pages').select('*').orderBy('slug', 'asc');
|
|
res.json(pages);
|
|
} catch (error) {
|
|
console.error('Error fetching CMS pages:', error);
|
|
res.status(500).json({ error: 'Failed to fetch pages' });
|
|
}
|
|
});
|
|
|
|
// Get a single CMS page
|
|
router.get('/pages/:slug', adminAuth, async (req, res) => {
|
|
try {
|
|
const { slug } = req.params;
|
|
const page = await db('cms_pages').where('slug', slug).first();
|
|
|
|
if (!page) {
|
|
return res.status(404).json({ error: 'Page not found' });
|
|
}
|
|
|
|
res.json(page);
|
|
} catch (error) {
|
|
console.error('Error fetching CMS page:', error);
|
|
res.status(500).json({ error: 'Failed to fetch page' });
|
|
}
|
|
});
|
|
|
|
// Update a CMS page
|
|
router.put('/pages/:slug', adminAuth, [
|
|
body('title_en').optional().isString(),
|
|
body('title_de').optional().isString(),
|
|
body('content_en').optional().isString(),
|
|
body('content_de').optional().isString()
|
|
], async (req, res) => {
|
|
try {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) {
|
|
return res.status(400).json({ errors: errors.array() });
|
|
}
|
|
|
|
const { slug } = req.params;
|
|
const { title_en, title_de, content_en, content_de } = req.body;
|
|
|
|
const page = await db('cms_pages').where('slug', slug).first();
|
|
if (!page) {
|
|
return res.status(404).json({ error: 'Page not found' });
|
|
}
|
|
|
|
// Update the page
|
|
await db('cms_pages')
|
|
.where('slug', slug)
|
|
.update({
|
|
title_en,
|
|
title_de,
|
|
content_en,
|
|
content_de,
|
|
updated_at: new Date()
|
|
});
|
|
|
|
const updated = await db('cms_pages').where('slug', slug).first();
|
|
|
|
// Log activity
|
|
await logActivity('cms_page_updated',
|
|
{ page: slug },
|
|
null,
|
|
{ type: 'admin', id: req.admin.id, name: req.admin.username }
|
|
);
|
|
|
|
res.json(updated);
|
|
} catch (error) {
|
|
console.error('Error updating CMS page:', error);
|
|
res.status(500).json({ error: 'Failed to update page' });
|
|
}
|
|
});
|
|
|
|
module.exports = router; |