Add admin key generation to config initialization

Introduces automatic generation of a random admin key when creating or updating the configuration file. Also adds a notifyAdminsOnBoot flag and ensures missing admin keys are added to existing configs.
This commit is contained in:
Steven Noack 2025-12-11 11:55:24 +01:00
parent b2b79a748d
commit 6e44039bc5
2 changed files with 19 additions and 1 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1,8 +1,14 @@
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const configPath = '/app/config/nsecbunker.json';
// Generate a random admin key
function generateAdminKey() {
return crypto.randomBytes(32).toString('hex');
}
// Default config with nip46 relay
const defaultConfig = {
"nostr": {
@ -16,7 +22,9 @@ const defaultConfig = {
],
"adminRelays": [
"wss://nip46.stevennoack.de"
]
],
"key": generateAdminKey(),
"notifyAdminsOnBoot": true
},
"database": "sqlite://nsecbunker.db",
"logs": "./nsecbunker.log",
@ -33,6 +41,16 @@ if (!fs.existsSync(configPath)) {
console.log('✅ Config created at', configPath);
} else {
console.log('✅ Config exists at', configPath);
// Check if admin key exists
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
if (!config.admin || !config.admin.key) {
console.log('🔑 Adding missing admin key...');
if (!config.admin) config.admin = {};
config.admin.key = generateAdminKey();
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
console.log('✅ Admin key added');
}
}
// Load existing config