Files
cloudron-box/src/dns/manual.js
T

66 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-12-14 13:19:12 -08:00
'use strict';
exports = module.exports = {
upsert: upsert,
get: get,
del: del,
2017-01-10 11:12:38 +01:00
waitForDns: require('./waitfordns.js'),
verifyDnsConfig: verifyDnsConfig
2016-12-14 13:19:12 -08:00
};
var assert = require('assert'),
2017-02-19 20:30:35 -08:00
debug = require('debug')('box:dns/manual'),
2018-02-08 10:21:31 -08:00
dns = require('../native-dns.js'),
2018-04-29 11:20:12 -07:00
DomainsError = require('../domains.js').DomainsError,
2016-12-14 13:19:12 -08:00
util = require('util');
function upsert(dnsConfig, zoneName, subdomain, type, values, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof subdomain, 'string');
assert.strictEqual(typeof type, 'string');
assert(util.isArray(values));
assert.strictEqual(typeof callback, 'function');
debug('upsert: %s for zone %s of type %s with values %j', subdomain, zoneName, type, values);
return callback(null, 'noop-record-id');
}
function get(dnsConfig, zoneName, subdomain, type, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof subdomain, 'string');
assert.strictEqual(typeof type, 'string');
assert.strictEqual(typeof callback, 'function');
callback(null, [ ]); // returning ip confuses apptask into thinking the entry already exists
}
function del(dnsConfig, zoneName, subdomain, type, values, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof subdomain, 'string');
assert.strictEqual(typeof type, 'string');
assert(util.isArray(values));
assert.strictEqual(typeof callback, 'function');
return callback();
}
2017-06-11 22:32:05 -07:00
function verifyDnsConfig(dnsConfig, domain, zoneName, ip, callback) {
2017-01-10 11:12:38 +01:00
assert.strictEqual(typeof dnsConfig, 'object');
assert.strictEqual(typeof domain, 'string');
2017-06-11 22:32:05 -07:00
assert.strictEqual(typeof zoneName, 'string');
2017-01-10 11:12:38 +01:00
assert.strictEqual(typeof ip, 'string');
assert.strictEqual(typeof callback, 'function');
// Very basic check if the nameservers can be fetched
2018-02-08 14:39:35 -08:00
dns.resolve(zoneName, 'NS', { timeout: 5000 }, function (error, nameservers) {
2018-05-15 12:23:41 -07:00
if (error && error.code === 'ENOTFOUND') return callback(new DomainsError(DomainsError.BAD_FIELD, 'Unable to resolve nameservers for this domain'));
if (error || !nameservers) return callback(new DomainsError(DomainsError.BAD_FIELD, error ? error.message : 'Unable to get nameservers'));
2017-01-10 11:49:23 +01:00
2018-01-09 14:46:38 -08:00
callback(null, { wildcard: !!dnsConfig.wildcard });
2017-01-10 11:12:38 +01:00
});
}