mirror of https://github.com/TriliumNext/Notes
db anonymization implementation
parent
fab69f411e
commit
5b08dfefd3
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const anonymization = require('../../services/anonymization');
|
||||
|
||||
router.post('/anonymize', async (req, res, next) => {
|
||||
await anonymization.anonymize();
|
||||
|
||||
res.send({});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
const data_dir = require('./data_dir');
|
||||
const utils = require('./utils');
|
||||
const fs = require('fs-extra');
|
||||
const sqlite = require('sqlite');
|
||||
|
||||
async function anonymize() {
|
||||
if (!fs.existsSync(data_dir.ANONYMIZED_DB_DIR)) {
|
||||
fs.mkdirSync(data_dir.ANONYMIZED_DB_DIR, 0o700);
|
||||
}
|
||||
|
||||
const anonymizedFile = data_dir.ANONYMIZED_DB_DIR + "/" + "backup-" + utils.getDateTimeForFile() + ".db";
|
||||
|
||||
fs.copySync(data_dir.DOCUMENT_PATH, anonymizedFile);
|
||||
|
||||
const db = await sqlite.open(anonymizedFile, {Promise});
|
||||
|
||||
await db.run("UPDATE notes SET note_title = 'title', note_text = 'text'");
|
||||
await db.run("UPDATE notes_history SET note_title = 'title', note_text = 'text'");
|
||||
await db.run("UPDATE notes_tree SET prefix = 'prefix' WHERE prefix IS NOT NULL");
|
||||
await db.run(`UPDATE options SET opt_value = 'anonymized' WHERE opt_name IN
|
||||
('document_secret', 'encrypted_data_key', 'password_verification_hash',
|
||||
'password_verification_salt', 'password_derived_key_salt')`);
|
||||
await db.run("VACUUM");
|
||||
|
||||
await db.close();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
anonymize
|
||||
};
|
||||
Loading…
Reference in New Issue