mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-13 17:12:05 -04:00
stalwart-snapshot-passwords: fix for Node, and beautify
This commit is contained in:
@@ -3,38 +3,36 @@
|
||||
// - replace masked passwords with their correct value
|
||||
// - replace the defaultHostname system setting
|
||||
|
||||
const fs = require('fs');
|
||||
const readline = require('readline');
|
||||
import * as fs from 'node:fs'
|
||||
import readline from 'node:readline'
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const inputs = args.length > 0
|
||||
? args.map(file => fs.createReadStream(file))
|
||||
: [process.stdin];
|
||||
const args = process.argv.slice(2)
|
||||
const inputs = args.length > 0 ? args.map((file) => fs.createReadStream(file)) : [process.stdin]
|
||||
|
||||
async function processLines() {
|
||||
for (const stream of inputs) {
|
||||
const rl = readline.createInterface({
|
||||
input: stream,
|
||||
crlfDelay: Infinity
|
||||
});
|
||||
})
|
||||
|
||||
for await (const line of rl) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed) continue
|
||||
|
||||
const item = JSON.parse(trimmed);
|
||||
const t = item['@type'];
|
||||
const o = item['object'];
|
||||
const item = JSON.parse(trimmed)
|
||||
const t = item['@type']
|
||||
const o = item['object']
|
||||
|
||||
if (t === 'create' && o === 'Account') {
|
||||
const value = item['value'] || {};
|
||||
const value = item['value'] || {}
|
||||
for (const [id, account] of Object.entries(value)) {
|
||||
const name = account['name'];
|
||||
const name = account['name']
|
||||
if (name === 'master' || name === 'admin') {
|
||||
const credentials = account['credentials'] || {};
|
||||
const credentials = account['credentials'] || {}
|
||||
for (const [cid, creds] of Object.entries(credentials)) {
|
||||
if (creds['@type'] === 'Password') {
|
||||
creds['secret'] = 'supersecret1234';
|
||||
creds['secret'] = 'supersecret1234'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,11 +40,11 @@ async function processLines() {
|
||||
}
|
||||
|
||||
if (t === 'create' && o === 'Directory') {
|
||||
const value = item['value'] || {};
|
||||
const value = item['value'] || {}
|
||||
for (const [id, dir] of Object.entries(value)) {
|
||||
if (dir['@type'] === 'Ldap') {
|
||||
if (dir['bindSecret']) {
|
||||
dir['bindSecret']['secret'] = 'admin';
|
||||
dir['bindSecret']['secret'] = 'admin'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,13 +52,13 @@ async function processLines() {
|
||||
|
||||
if (t === 'update' && o === 'SystemSettings') {
|
||||
if (item['value']) {
|
||||
item['value']['defaultHostname'] = 'stalwart.opencloud.test';
|
||||
item['value']['defaultHostname'] = 'stalwart.opencloud.test'
|
||||
}
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(item));
|
||||
console.log(JSON.stringify(item))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processLines();
|
||||
processLines()
|
||||
|
||||
Reference in New Issue
Block a user