"use strict"; var conf = { registrars: [], dns_providers: [], domains: [] }; var defaultArgs = []; function initialize(){ conf = { registrars: [], dns_providers: [], domains: [] }; defaultArgs = []; } function NewRegistrar(name,type,meta) { if (type) { type == "MANUAL"; } var reg = {name: name, type: type, meta: meta}; conf.registrars.push(reg); return name; } function NewDnsProvider(name, type, meta) { if ((typeof meta === 'object') && ('ip_conversions' in meta)) { meta.ip_conversions = format_tt(meta.ip_conversions) } var dsp = {name: name, type: type, meta: meta}; conf.dns_providers.push(dsp); return name; } function newDomain(name,registrar) { return {name: name, registrar: registrar, meta:{}, records:[], dnsProviders: {}, defaultTTL: 0, nameservers:[]}; } function processDargs(m, domain) { // for each modifier, if it is a... // function: call it with domain // array: process recursively // object: merge it into metadata if (_.isFunction(m)) { m(domain); } else if (_.isArray(m)) { for (var j in m) { processDargs(m[j], domain) } } else if (_.isObject(m)) { _.extend(domain.meta,m); } else { throw "WARNING: domain modifier type unsupported: "+ typeof m + " Domain: "+ domain.name; } } // D(name,registrar): Create a DNS Domain. Use the parameters as records and mods. function D(name,registrar) { var domain = newDomain(name,registrar); for (var i = 0; i< defaultArgs.length; i++){ processDargs(defaultArgs[i],domain) } for (var i = 2; i 1) { // run validator if supplied if(!argDefinition[1](value)){ throw type + " record " + argDefinition[0] + " argument validation failed"; } } parsedArgs[argDefinition[0]] = value; } // collect modifiers for (var i = opts.args.length; i < arguments.length; i++) { modifiers.push(arguments[i]); } return function(d){ var record = { type: type, meta: {}, ttl: d.defaultTTL, }; opts.applyModifier(record, modifiers); opts.transform(record, parsedArgs, modifiers); d.records.push(record); return record; }; }; } /** * @deprecated */ function addRecord(d,type,name,target,mods) { // if target is number, assume ip address. convert it. if (_.isNumber(target)) { target = num2dot(target); } var rec = {type: type, name: name, target: target, ttl:d.defaultTTL, priority: 0, meta:{}}; // for each modifier, decide based on type: // - Function: call is with the record as the argument // - Object: merge it into the metadata // - Number: IF MX record assume it is priority if (mods) { for (var i = 0; i< mods.length; i++) { var m = mods[i] if (_.isFunction(m)) { m(rec); } else if (_.isObject(m)) { //convert transforms to strings if (m.transform && _.isArray(m.transform)){ m.transform = format_tt(m.transform) } _.extend(rec.meta,m); _.extend(rec.meta,m); } else { console.log("WARNING: Modifier type unsupported:", typeof m, "(Skipping!)"); } } } d.records.push(rec); return rec; } //ip conversion functions from http://stackoverflow.com/a/8105740/121660 // via http://javascript.about.com/library/blipconvert.htm function IP(dot) { var d = dot.split('.'); return ((((((+d[0])*256)+(+d[1]))*256)+(+d[2]))*256)+(+d[3]); } function num2dot(num) { if(num === undefined){ return ""; } if (_.isString(num)){ return num } var d = num%256; for (var i = 3; i > 0; i--) { num = Math.floor(num/256); d = num%256 + '.' + d; } return d; } // Cloudflare aliases: // Meta settings for individual records. var CF_PROXY_OFF = {'cloudflare_proxy': 'off'}; // Proxy disabled. var CF_PROXY_ON = {'cloudflare_proxy': 'on'}; // Proxy enabled. var CF_PROXY_FULL = {'cloudflare_proxy': 'full'}; // Proxy+Railgun enabled. // Per-domain meta settings: // Proxy default off for entire domain (the default): var CF_PROXY_DEFAULT_OFF = {'cloudflare_proxy_default': 'off'}; // Proxy default on for entire domain: var CF_PROXY_DEFAULT_ON = {'cloudflare_proxy_default': 'on'}; // CUSTOM, PROVIDER SPECIFIC RECORD TYPES function _validateCloudFlareRedirect(value){ if(!_.isString(value)){ return false; } return value.indexOf(",") === -1; } var CF_REDIRECT = recordBuilder("CF_REDIRECT", { args: [ ["source", _validateCloudFlareRedirect], ["destination", _validateCloudFlareRedirect], ], transform: function(record, args, modifiers){ record.name = "@"; record.target = args.source + "," + args.destination; }, }); var CF_TEMP_REDIRECT = recordBuilder("CF_TEMP_REDIRECT", { args: [ ["source", _validateCloudFlareRedirect], ["destination", _validateCloudFlareRedirect], ], transform: function(record, args, modifiers){ record.name = "@"; record.target = args.source + "," + args.destination; }, });