Created
April 24, 2017 19:52
-
-
Save mdunham/526614350d3d211ccbef37d78145f6c5 to your computer and use it in GitHub Desktop.
Scrape WHM DNS zone file editor and compare with another WHM zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* WHM DNS Zone Scraper | |
* | |
* There are two steps to the process first login to WHM and start esiting the zone | |
* file you want to sync from and run the first script beloew. | |
* | |
* Take the output of that script and pass it as JSON to the oldEntries var on part 2. | |
* Now run part two while editing the DNS zone to the target domain. This will | |
* output the DNS entries that are not in the current zonefile in proper zone format | |
* | |
* @author Matthew Dunham <matt@matthewdunham.net> | |
*/ | |
// PART ONE | |
var dnsEntries = []; | |
[].map.call(document.querySelectorAll('#zoneform tr'), function(row){ | |
var | |
name = row.querySelector(':scope td:nth-child(1) > input[type="text"]'), | |
host = row.querySelector(':scope td:nth-child(5) > input[type="text"]'), | |
type = row.querySelector(':scope td:nth-child(4) > select'); | |
if (name && host && type) { | |
dnsEntries.push({ | |
type: type.value, | |
name: name.value, | |
host: host.value | |
}); | |
} | |
}); | |
// Copy this output for part two | |
console.log(JSON.stringify(dnsEntries)); | |
// PART TWO | |
var | |
oldEntries = outputFromPartOne, // Expected format: [{"type":"NS","name":"domain.com.","host":"ns1.domain.com."}, ...], | |
dnsEntries = []; | |
[].map.call(document.querySelectorAll('#zoneform tr'), function(row){ | |
var | |
name = row.querySelector(':scope td:nth-child(1) > input[type="text"]'), | |
host = row.querySelector(':scope td:nth-child(5) > input[type="text"]'), | |
type = row.querySelector(':scope td:nth-child(4) > select'); | |
if (name && host && type) { | |
dnsEntries.push({ | |
type: type.value, | |
name: name.value, | |
host: host.value | |
}); | |
} | |
}); | |
var newEntries; | |
for (var i = 0; i < oldEntries.length; i++) { | |
var found = false; | |
for (var ii = 0; ii < dnsEntries; ii++) { | |
if (dnsEntries[ii].type == oldEntries[i].type && dnsEntries[ii].name == oldEntries[i].name) { | |
console.log('found one :)'); | |
found = true; | |
break; | |
} | |
} | |
if ( ! found) { | |
newEntries = newEntries + oldEntries[i].name + ' 14400 IN ' + oldEntries[i].type + ' ' + oldEntries[i].host + "\n"; | |
} | |
} | |
// Output should be valid DNS zone file entries | |
console.log(newEntries); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment