telebit-relay.js/lib/extensions/data-files-to-json.js

48 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2018-08-05 05:48:31 +00:00
'use strict';
var fs = require('fs');
var path = require('path');
var basedir = path.join(__dirname, 'emails');
var files = fs.readdirSync(basedir)
var emails = {};
files.forEach(function (fname) {
var fpath = path.join(basedir, fname);
var data;
var email;
var iat;
2018-08-05 07:20:06 +00:00
var mdata;
2018-08-05 05:48:31 +00:00
if (!/\.data$/.test(fname)) {
return;
}
data = JSON.parse(fs.readFileSync(fpath));
email = fname.replace('\.' + data.domains.join('') + '\.data', '');
2018-08-05 07:20:06 +00:00
mdata = JSON.parse(fs.readFileSync(path.join(basedir, email)));
2018-08-05 05:48:31 +00:00
if (data.iat) {
2018-08-05 08:11:54 +00:00
iat = new Date(data.iat * 1000).toISOString();
2018-08-05 05:48:31 +00:00
}
if (!emails[email]) {
emails[email] = {
domains: []
, ports: []
2018-08-05 07:20:06 +00:00
, nodes: [ { createdAt: iat, scheme: 'mailto', type: 'email', name: email } ]
2018-08-05 05:48:31 +00:00
, jtis: []
};
}
emails[email].jtis.push(data.id);
data.domains.forEach(function (d) {
2018-08-05 07:20:06 +00:00
emails[email].domains.push({ createdAt: iat, name: d, wildcard: true, hostname: mdata.hostname
, os: mdata.os_type, arch: mdata.os_arch });
2018-08-05 05:48:31 +00:00
});
data.ports.forEach(function (p) {
2018-08-05 07:20:06 +00:00
emails[email].ports.push({ createdAt: iat, number: p, hostname: mdata.hostname
, os: mdata.os_type, arch: mdata.os_arch });
2018-08-05 05:48:31 +00:00
});
});
2018-10-08 01:14:55 +00:00
console.log('');
2018-08-05 05:48:31 +00:00
console.log('[\n' + Object.keys(emails).map(function (k) { return JSON.stringify(emails[k]); }).join(',\n') + '\n]');
2018-10-08 01:14:55 +00:00
console.log('');
console.log('');
console.log(Object.keys(emails).join(', '));
console.log('');