Created
May 3, 2011 21:22
-
-
Save natebenes/954279 to your computer and use it in GitHub Desktop.
Quick and dirty way to import a Zonefile into PointHQ DNS
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
# | |
# PointHQ Importer for BIND Records | |
# Disclaimer: This will probably break stuff | |
# | |
# Copyright (C) 2011 Nate (@rdnck76) | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
require 'rubygems' | |
require 'point' | |
require 'zonefile' | |
Point.username = "[email protected]" | |
Point.apitoken = "apikey" | |
zonefile = "zone.db" | |
zoneId = 1234 | |
zoneName = 'example.com' | |
# Find ID | |
zone = Point::Zone.find(zoneId) | |
# Load Zonefile | |
puts "Parsing DNS records:" | |
zf = Zonefile.from_file(zonefile) | |
# Display A-Records | |
puts "Uploading DNS records:" | |
zf.a.each do |a_record| | |
new_record = zone.build_record | |
new_record.record_type = "A" | |
zhost = a_record[:name] | |
if zhost.include? "@" | |
zhost = zoneName + "." | |
end | |
new_record.name = zhost | |
new_record.data = a_record[:host] | |
success = new_record.save | |
puts "A: #{a_record[:name]} --> #{a_record[:host]} --> (#{success})" | |
end | |
# Display MX-Records | |
zf.mx.each do |mx_record| | |
new_record = zone.build_record | |
new_record.record_type = "MX" | |
zhost = mx_record[:name] | |
if zhost.include? "@" | |
zhost = zoneName + "." | |
end | |
new_record.name = zhost | |
new_record.data = mx_record[:host] | |
new_record.aux = mx_record[:pri] | |
success = new_record.save | |
puts "MX: #{mx_record[:name]} --> #{mx_record[:host]} (#{success})" | |
end | |
# Display NS-Records | |
zf.ns.each do |ns_record| | |
unless ns_record[:name] = "@" | |
new_record = zone.build_record | |
new_record.record_type = "NS" | |
new_record.name = ns_record[:name] | |
new_record.data = ns_record[:host] | |
success = new_record.save | |
puts "NS: #{ns_record[:name]} --> #{ns_record[:host]} (#{success})" | |
end | |
end | |
# Display CNAME-Records | |
zf.cname.each do |cname_record| | |
new_record = zone.build_record | |
new_record.record_type = "CNAME" | |
new_record.name = cname_record[:name] | |
zhost = cname_record[:name] | |
if zhost.include? "@" | |
zhost = zoneName + "." | |
end | |
new_record.name = zhost | |
ztarget = cname_record[:host] | |
if ztarget.include? "@" | |
ztarget = zoneName | |
end | |
new_record.data = ztarget + "." | |
success = new_record.save | |
puts "CNAME: #{cname_record[:name]} --> #{cname_record[:host]} (#{success})" | |
end | |
# Display TXT-Records | |
zf.txt.each do |txt_record| | |
new_record = zone.build_record | |
new_record.record_type = "TXT" | |
zhost = txt_record[:name] | |
if zhost.include? "@" | |
zhost = zoneName + "." | |
end | |
new_record.name = zhost | |
new_record.data = txt_record[:text] | |
success = new_record.save | |
puts "TXT: #{txt_record[:name]} --> #{txt_record[:text]} (#{success})" | |
end | |
# Display AAAA-Records | |
zf.a4.each do |aaaa_record| | |
new_record = zone.build_record | |
new_record.record_type = "AAAA" | |
zhost = aaaa_record[:name] | |
if zhost.include? "@" | |
zhost = zoneName + "." | |
end | |
new_record.name = zhost | |
new_record.data = aaaa_record[:host] + "." | |
new_record.aux = aaaa_record[:pri] | |
success = new_record.save | |
puts "AAAA: #{aaaa_record[:name]} --> #{aaaa_record[:pri]} --> #{aaaa_record[:host]} (#{success})" | |
end | |
# Display SRV-Records | |
zf.srv.each do |srv_record| | |
new_record = zone.build_record | |
new_record.record_type = "SRV" | |
zhost = srv_record[:name] | |
if zhost.include? "@" | |
zhost = zoneName + "." | |
end | |
new_record.name = zhost | |
new_record.data = srv_record[:weight] + " " + srv_record[:port] + " " + srv_record[:host] | |
new_record.aux = srv_record[:pri] | |
success = new_record.save | |
puts "SRV: #{srv_record[:name]} --> #{srv_record[:pri]} --> #{srv_record[:host]} (#{success})" | |
end | |
puts "Finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently this dies on TXT records that aren't wrapped in quotes like they're supposed to be.