Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.keereg = async function(req, res) {
try{
let filePath = path.resolve(path.join(process.execPath, '../keepass/')+req.body.keepassfile+'.kdbx');
if(isMobile(req)) {
//filePath = path.resolve('/tmp/keepass/'+req.body.keepassfile+'.kdbx');
filePath = path.resolve(path.join(__dirname, '../../keepass/'+req.body.keepassfile+'.kdbx'));
}
if(process.env.electron) {
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'+req.body.keepassfile+'.kdbx'));
}
let cred = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(req.body.keepassword));
let db = kdbxweb.Kdbx.create(cred, 'mydicebot');
//let subGroup = db.createGroup(db.getDefaultGroup(), 'mydicebot');
db.save().then(ab => {
fs.writeFileSync(filePath, Buffer.from(ab));
return res.status(200).json('ok');
});
} catch(err) {
console.log(err);
return res.status(500).send({err: err.toString()});
}
};
exports.keeload = async function(req, res) {
try{
let filePath = path.resolve(path.join(process.execPath, '../keepass/')+req.body.keepassfile+'.kdbx');
if(isMobile(req)) {
//filePath = path.resolve('/tmp/keepass/'+req.body.keepassfile+'.kdbx');
filePath = path.resolve(path.join(__dirname, '../../keepass/'+req.body.keepassfile+'.kdbx'));
}
if(process.env.electron) {
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'+req.body.keepassfile+'.kdbx'));
}
let cred = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(req.body.keepassword));
let data = await fs.readFileSync(filePath);
let db = await kdbxweb.Kdbx.load(new Uint8Array(data).buffer, cred);
let kees = {};
for (let group of db.groups) {
if(group.name == 'mydicebot') {
for (let subGroup of group.groups) {
let entrys = [];
for (let entry of subGroup.entries) {
let en = {};
en['username'] = field(entry, 'UserName');
en['password'] = field(entry, 'Password');
en['apikey'] = field(entry, 'ApiKey');
entrys.push(en);
}
kees[subGroup.name] = entrys;
}
const createSeedVault = async (seed, title, password) => {
const credentials = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(password));
const db = kdbxweb.Kdbx.create(credentials, 'Trinity');
const entry = db.createEntry(db.getDefaultGroup());
entry.fields.Title = title;
entry.fields.Seed = kdbxweb.ProtectedValue.fromString(seed);
const chunk = await db.save();
return chunk;
};
function getKey(isKdbx, protectedMasterPassword, fileKey) {
var creds = new kdbxweb.Credentials(protectedMasterPassword, fileKey);
return creds.ready.then(() => {
return kdbxCredentialsToJson(creds);
});
}
importWithXml(fileXml, callback) {
try {
const ts = logger.ts();
const password = kdbxweb.ProtectedValue.fromString('');
const credentials = new kdbxweb.Credentials(password);
kdbxweb.Kdbx.loadXml(fileXml, credentials)
.then(db => {
this.db = db;
this.readModel();
this.set({ active: true, created: true });
logger.info('Imported file ' + this.name + ': ' + logger.ts(ts));
callback();
})
.catch(err => {
logger.error('Error importing file', err.code, err.message, err);
callback(err);
});
} catch (e) {
logger.error('Error importing file', e, e.code, e.message, e);
callback(e);
}
const getSeedFromVault = async (buffer, password) => {
const credentials = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(password));
const db = await kdbxweb.Kdbx.load(buffer, credentials);
const entry = db.getDefaultGroup().entries[0];
const seed = entry.fields.Seed.getText();
const title = entry.fields.Title;
return JSON.stringify({ seed, title });
};
create(name) {
const password = kdbxweb.ProtectedValue.fromString('');
const credentials = new kdbxweb.Credentials(password);
this.db = kdbxweb.Kdbx.create(credentials, name);
this.name = name;
this.readModel();
this.set({ active: true, created: true, name });
}
function getKey(isKdbx, masterPassword, fileKey) {
var creds = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(masterPassword), fileKey);
return creds.ready.then(() => {
return kdbxCredentialsToJson(creds);
});
}