Created
November 13, 2010 15:45
-
-
Save argent-smith/675426 to your computer and use it in GitHub Desktop.
a ruby script to generate IDN BIND configuration
This file contains hidden or 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
#!/usr/bin/env ruby18 | |
# | |
# == IDN zone generator | |
# | |
# = Usage: | |
# | |
# $ mkdomains_idn крутой.домен.рф ... | |
# | |
# = What does it do? | |
# | |
# - Creates a punycode name from an IDN input | |
# - Makes a zone file of this name and writes zone stub into it | |
# - adds zone information to *.conf BIND config file (see config section) | |
# | |
# Author:: Pavel Argentov <[email protected]> | |
# | |
require 'rubygems' | |
require 'iconv' | |
require 'date' | |
require 'idn' # see on rubygems.org for Ruby 1.8, on GitHub for 1.9 | |
##### Editable config ### | |
CONFIG = { | |
:local_enc => 'KOI8-R', | |
:bind_file => 'cyr.conf', # where to write zone config | |
:dns => [ | |
'ns1.mydomain.net', | |
'ns2.mydomain.net' | |
], | |
:admin => 'admin.mydomain.net.' | |
} | |
######################### | |
date = Date.today.strftime("%Y%m%d") | |
dir = Dir.pwd | |
ARGV.each do |d| | |
n = IDN::Idna.toASCII(Iconv.conv('UTF-8', CONFIG[:local_enc], d)) | |
open(n,"a") do |io| | |
io.print <<EOF | |
; IDN: "#{d}" ==> "#{n}" | |
; this part is autogenerated; edit it if you know what'ya doing | |
$ORIGIN #{n}. | |
$TTL 3600 | |
@ IN SOA #{CONFIG[:dns][0]}. #{CONFIG[:admin]} ( | |
#{date}01 | |
28800 | |
7200 | |
604800 | |
86400 ) | |
IN NS #{CONFIG[:dns][0]}. | |
IN NS #{CONFIG[:dns][1]}. | |
; end of autogen part | |
; editable section below | |
; | |
; end of editable section | |
EOF | |
end | |
open(CONFIG[:bind_file],"a") do |io| | |
io.print <<EOF | |
// domain for "#{d}" | |
zone "#{n}" { | |
type master; | |
file "#{File.join(dir.gsub(/\/var\/named/,''), n)}"; | |
}; | |
EOF | |
end | |
puts "Generating #{Iconv.conv(CONFIG[:local_enc], "UTF-8", IDN::Idna.toUnicode(n))} ==> #{n} DONE" | |
end |
This file contains hidden or 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
#!/usr/bin/env ruby18 | |
# | |
# == IDN zone generator, slave DNS variant | |
# | |
# = Usage: | |
# | |
# $ mkdomains_idn крутой.домен.рф ... | |
# | |
# = What does it do? | |
# | |
# - Creates a punycode name from an IDN input | |
# - Makes a zone file of this name and writes zone stub into it | |
# - adds zone information to *.conf BIND config file (see config section) | |
# | |
# Author:: Pavel Argentov <[email protected]> | |
# | |
require 'rubygems' | |
require 'iconv' | |
require 'idn' # see on rubygems.org for Ruby 1.8, on GitHub for 1.9 | |
##### Editable config ### | |
CONFIG = { | |
:local_enc => 'KOI8-R', | |
:bind_file => 'slave.conf', # where to write zone config | |
:m_dns => [ | |
'1.1.1.1', | |
'2.2.2.2' | |
] | |
} | |
######################### | |
def m_dnses() | |
CONFIG[:m_dns].join("; ") + "; " | |
end | |
dir = Dir.pwd | |
ARGV.each do |d| | |
n = IDN::Idna.toASCII(Iconv.conv('UTF-8', CONFIG[:local_enc], d)) | |
open(CONFIG[:bind_file],"a") do |io| | |
io.print <<EOF | |
// domain for "#{d}" | |
zone "#{n}" { | |
type slave; | |
masters { #{m_dnses()}}; | |
file "#{File.join(dir.gsub(/\/var\/named/,''), n)}"; | |
}; | |
EOF | |
end | |
puts "Generating #{Iconv.conv(CONFIG[:local_enc], "UTF-8", IDN::Idna.toUnicode(n))} ==> #{n} DONE" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment