Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SPF records #11

Merged
merged 1 commit into from
Jul 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/zonefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
\n\
; SRV Records\n\
{srv}\n\
\n\
; SPF Records\n\
{spf}\n\
';

//var fs = require('fs');
Expand All @@ -57,6 +60,7 @@
template = processPTR(options['ptr'], template);
template = processTXT(options['txt'], template);
template = processSRV(options['srv'], template);
template = processSPF(options['spf'], template);
template = processValues(options, template);
return template.replace(/\n{2,}/gim, '\n\n');
};
Expand Down Expand Up @@ -171,6 +175,16 @@
return template.replace('{srv}', ret);
};

var processSPF = function (data, template) {
var ret = '';
for (var i in data) {
ret += (data[i].name || '@') + '\t';
if (data[i].ttl) ret += data[i].ttl + '\t';
ret += 'IN\tSPF\t' + data[i].data + '\n';
}
return template.replace('{spf}', ret);
};

var processValues = function (options, template) {
template = template.replace('{zone}', options['$origin'] || options['soa']['name'] || '');
template = template.replace('{datetime}', (new Date()).toISOString());
Expand Down Expand Up @@ -246,6 +260,9 @@
} else if (/\s+SRV\s+/.test(uRR)) {
ret.srv = ret.srv || [];
ret.srv.push(parseSRV(rr));
} else if (/\s+SPF\s+/.test(uRR)) {
ret.spf = ret.spf || [];
ret.spf.push(parseSPF(rr));
}
}
return ret;
Expand Down Expand Up @@ -384,6 +401,22 @@
return result;
};

var parseSPF = function (rr) {
var rrTokens = rr.trim().split(/\s+/g);
var result = {
name: rrTokens[0],
data: ''
};

var l = rrTokens.length;
while (l-- > 4) {
result.data = rrTokens[l] + ' ' + result.data.trim();
}

if (!isNaN(rrTokens[1])) result.ttl = parseInt(rrTokens[1], 10);
return result;
};

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
exports.generate = generate;
exports.parse = parse;
Expand Down