Files
is-a-good-dev/utils/checkRecords.js
T
2023-01-20 13:41:20 -07:00

36 lines
1.1 KiB
JavaScript

const { checkIfValidIP, checkIfValidIPv6, checkIfValidFQDN, checkInvalidDomain, isString } = require('./utils.js');
function checkRecords(data) {
const recordType = Object.keys(data.target)[0];
const value = data.target[recordType].value;
// Check if the domain is invalid
if (checkInvalidDomain(data.target[recordType].name) === true) return false;
// Check AAAA record
if (recordType.toLowerCase() === 'aaaa') {
if (!Array.isArray(value)) return false;
for (const record of value) {
if (checkIfValidIPv6(record) == false) return false;
}
return true;
}
// Check A record
if (recordType.toLowerCase() === 'a') {
if (!Array.isArray(value)) return false;
for (const record of value) {
if (checkIfValidIP(record) == false) return false;
}
return true;
}
// Check CNAME record
if (recordType.toLowerCase() === 'cname') {
if (!isString(value)) return false;
return checkIfValidFQDN(value);
}
return false;
}
module.exports = checkRecords;