Compare commits

..

4 Commits

Author SHA1 Message Date
AJ ONeal be91254190 Merge branch 'v1.1' of ssh://git.coolaj86.com:22042/coolaj86/digd.js into v1.1 2017-11-02 12:16:38 -06:00
AJ ONeal 5839451f20 add exchange 2017-11-02 11:56:57 -06:00
AJ ONeal f67788f9db Merge branch 'v1' of git.daplie.com:Daplie/digd.js into v1 2017-11-02 11:32:51 -06:00
AJ ONeal 5cf3a3b20f add simple parser/reformatter 2017-11-02 11:32:46 -06:00
1 changed files with 73 additions and 0 deletions

73
samples/parse-records.js Normal file
View File

@ -0,0 +1,73 @@
'use strict';
/*
* parses files in the format "type|domain|value|json\n"
*/
var filename = process.argv[2];
var fs = require('fs');
var file = fs.readFileSync(filename, 'utf8');
var zone = 'daplie.com';
file.trim().split(/\n/).forEach(function (line) {
var parts = line.split(/\|/);
var type = parts[0];
var name = parts[1] || zone;
var domain = name.split('.');
var thing = parts[2];
var json = JSON.parse(parts[3]);
var address; // A, AAAA
var flag, tag, value; // CAA
var data; // CNAME, NS, PTR, ... TXT (as array)
var priority; // MX, SRV
var exchange; // MX
var weight, port, target; // SRV
if (/^(A|AAAA)$/.test(type)) {
address = thing;
}
if (/^(CNAME|NS|PTR)$/.test(type)) {
data = thing;
}
if (/^(TXT)$/.test(type)) {
data = [ thing ];
}
if (/^(MX)$/.test(type)) {
exchange = thing;
}
if (/^(MX|SRV)$/.test(type)) {
priority = json.priority || 10;
}
var obj = {
zone: zone
, name: name
, type: type
, class: 'IN'
, ttl: 5 // 12 hours 43200 // 3 days 259200
, tld: domain.pop()
, sld: domain.pop()
, sub: domain.join('.') || undefined
, address: address
, aname: undefined
, flag: flag
, tag: tag
, value: value
, data: data
, exchange: exchange
, priority: priority
, weight: weight
, port: port
, target: target
};
console.log(",", JSON.stringify(obj));
});