mirror of
https://github.com/kind-0/nsecbunkerd.git
synced 2026-08-01 07:21:42 +00:00
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:
parent
b2b79a748d
commit
6e44039bc5
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user