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>
109 lines
3.3 KiB
JavaScript
Executable File
109 lines
3.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const bcrypt = require('bcrypt');
|
|
const { db } = require('../src/database/db');
|
|
const { generateReadablePassword } = require('../src/utils/passwordGenerator');
|
|
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
const readline = require('readline');
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
async function question(prompt) {
|
|
return new Promise((resolve) => {
|
|
rl.question(prompt, resolve);
|
|
});
|
|
}
|
|
|
|
async function resetAdminPassword() {
|
|
console.log('\n========================================');
|
|
console.log('PicPeak Admin Password Reset Tool');
|
|
console.log('========================================\n');
|
|
|
|
try {
|
|
// Check if admin user exists
|
|
const admin = await db('admin_users')
|
|
.where({ username: 'admin' })
|
|
.first();
|
|
|
|
if (!admin) {
|
|
console.error('❌ No admin user found in the database.');
|
|
console.log('Run migrations first: npm run migrate');
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('Found admin user:', admin.username);
|
|
console.log('Email:', admin.email);
|
|
console.log('\nThis will reset the password for this admin account.');
|
|
|
|
const confirm = await question('\nDo you want to continue? (yes/no): ');
|
|
|
|
if (confirm.toLowerCase() !== 'yes' && confirm.toLowerCase() !== 'y') {
|
|
console.log('\n❌ Password reset cancelled.');
|
|
process.exit(0);
|
|
}
|
|
|
|
// Generate new password
|
|
const newPassword = generateReadablePassword();
|
|
const passwordHash = await bcrypt.hash(newPassword, 12);
|
|
|
|
// Update the admin user
|
|
await db('admin_users')
|
|
.where({ username: 'admin' })
|
|
.update({
|
|
password_hash: passwordHash,
|
|
must_change_password: true,
|
|
updated_at: new Date()
|
|
});
|
|
|
|
// Save to file
|
|
const resetInfoPath = path.join(__dirname, '..', '..', 'ADMIN_PASSWORD_RESET.txt');
|
|
const resetInfo = `
|
|
========================================
|
|
PicPeak Admin Password Reset
|
|
========================================
|
|
|
|
Password has been reset for admin account:
|
|
|
|
Username: admin
|
|
New Password: ${newPassword}
|
|
|
|
IMPORTANT:
|
|
1. You MUST change this password on next login
|
|
2. This file contains sensitive information
|
|
3. Delete this file after noting the password
|
|
|
|
Login URL: ${process.env.ADMIN_URL || 'http://localhost:3001'}/admin
|
|
|
|
Reset performed on: ${new Date().toISOString()}
|
|
========================================
|
|
`;
|
|
|
|
await fs.writeFile(resetInfoPath, resetInfo, 'utf8');
|
|
|
|
console.log('\n✅ Password reset successful!\n');
|
|
console.log('========================================');
|
|
console.log('New Credentials:');
|
|
console.log('========================================');
|
|
console.log('Username: admin');
|
|
console.log(`Password: ${newPassword}`);
|
|
console.log('\n⚠️ IMPORTANT:');
|
|
console.log('1. You will be required to change this password on next login');
|
|
console.log('2. Credentials are also saved in: ADMIN_PASSWORD_RESET.txt');
|
|
console.log('3. Delete the file after noting the password');
|
|
console.log('========================================\n');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error resetting password:', error.message);
|
|
process.exit(1);
|
|
} finally {
|
|
rl.close();
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
// Run the reset
|
|
resetAdminPassword(); |