1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Productionize the SPF optimizer (#279)

* Productionize the SPF optimizer
* SPF_BUILDER(): New helper function
* docs/spf-optimizer.md: Document SPF_BUILDER()
This commit is contained in:
Tom Limoncelli
2017-12-06 15:50:21 -05:00
committed by GitHub
parent 95fb79dfcc
commit c6e244d8da
5 changed files with 353 additions and 70 deletions

View File

@@ -538,3 +538,43 @@ var CF_TEMP_REDIRECT = recordBuilder('CF_TEMP_REDIRECT', {
var URL = recordBuilder('URL')
var URL301 = recordBuilder('URL301')
var FRAME = recordBuilder('FRAME')
// SPF_BUILDER takes an object:
// parts: The parts of the SPF record (to be joined with ' ').
// label: The DNS label for the primary SPF record. (default: '@')
// raw: If defined, also
// split: The template for additional records to be created (default: '_spf%d')
// flatten: A list of domains to be flattened.
function SPF_BUILDER(value) {
if (!value.parts || value.parts.length < 2) {
throw "SPF_BUILDER requires at least 2 elements";
}
if (!value.label) {
value.label = "@";
}
if (!value.raw) {
value.raw = "_rawspf";
}
r = [] // The list of records to return.
p = {} // The metaparameters to set on the main TXT record.
rawspf = value.parts.join(" "); // The unaltered SPF settings.
// If flattening is requested, generate a TXT record with the raw SPF settings.
if (value.flatten && value.flatten.length > 0) {
p.flatten = value.flatten.join(",");
r.push(TXT(value.raw, rawspf))
}
// If overflow is specified, enable splitting.
if (value.overflow) {
p.split = value.overflow
}
// Generate a TXT record with the metaparameters.
r.push(TXT(value.label, rawspf, p))
return r
}