/*
Syntax:
createreverse
reads forward zones and creates PTR records in in-addr.arpa
Version 0.1, 2002.06.18, Carsten Strotmann (cas), Men & Mice
*/
PARSE VERSION version
scriptname = "createreverse"
scriptversion = 0.1
hostmaster = "hostmaster"
SAY scriptname scriptversion ':' version
masterzonefilepath = 'var/named/master'
slavezonefilepath = 'var/named/slave'
namedmasters = 'etc/named.conf.masters'
namedslaves = 'etc/named.conf.slaves'
secondarynameservers = 'ns2.example.com'
'ls' masterzonefilepath '> zones.tmp'
datafile = 'zones.tmp'
rc = Stream(datafile, 'C', 'OPEN READ')
i = 1
DO WHILE Lines(datafile) > 0
line.i = LineIn(datafile)
i = i + 1
END
line.0 = i - 1
ptr. = ''
rc = Stream(datafile, 'C', 'CLOSE')
DO i = 1 to line.0
zonefile = masterzonefilepath'/'line.i
rc = Stream(zonefile,'C', 'OPEN READ')
DO WHILE Lines(zonefile) > 0
zdata = LineIn(zonefile)
PARSE VALUE zdata WITH fqdn type record address
IF type = 'IN' & record = 'A' THEN
DO
PARSE VALUE address WITH ip1'.'ip2'.'ip3'.'ip4
IF ptr.ip1.ip2.ip3.0 = '' THEN
DO
ptr.ip1.ip2.ip3.0 = 1
ptr.ip1.ip2.ip3.1 = fqdn address
END
ELSE
DO
cnt = ptr.ip1.ip2.ip3.0
cnt = cnt +1
ptr.ip1.ip2.ip3.cnt = fqdn address
ptr.ip1.ip2.ip3.0 = cnt
END
END
END
rc = Stream(zonefile,'C', 'CLOSE')
END
DO ip1 = 0 TO 255
DO ip2 = 0 TO 255
DO ip3 = 0 TO 255
IF ptr.ip1.ip2.ip3.0 <> '' THEN
DO
SAY ptr.ip1.ip2.ip3.0
DO u = 1 TO ptr.ip1.ip2.ip3.0
SAY ptr.ip1.ip2.ip3.u
END
END
END
END
END
zone.0 =zonenum -1
DO z = 1 to zone.0
zonefile = masterzonefilepath'/'zone.z.fqdn
rc = Stream(zonefile,'C', 'OPEN READ')
IF Pos('NOTREADY',rc) = 0 THEN
DO
SAY 'ERROR: Zonefile' zonefile 'already exists. Please check if zone is already there!'
rc = Stream(zonefile,'C', 'CLOSE')
RETURN
END
SAY "Creating new domain" zone.z.fqdn "with nameserver "
SAY 'Creating Zonefile' zonefile 'with' zone.z.ns.0 'NS,' zone.z.mx.0 'MX,' zone.z.cn.0 'CNAME und' zone.z.a.0 'A Records.'
rc = Stream(zonefile,'C', 'OPEN WRITE')
rc = LineOut(zonefile,"; Zonefile for" zone.z.fqdn " created " date() "with script" scriptname scriptversion version)
rc = LineOut(zonefile,zone.z.fqdn || '. IN SOA' zone.z.ns.1'.' hostmaster'.'zone.z.fqdn'. (')
rc = LineOut(zonefile,' ' Date('S') || '00 ; Serial yymmddnn')
rc = LineOut(zonefile,' 1d ; Refresh after 1 day(s)')
rc = LineOut(zonefile,' 1h ; Retry after 1 hour(s)')
rc = LineOut(zonefile,' 1w ; Expire after 1 week')
rc = LineOut(zonefile,' 1h ) ; Negative caching TTL of 1h')
IF zone.z.ns.0 > 0 THEN DO
rc = LineOut(zonefile,';')
rc = LineOut(zonefile,'; nameserver')
END
DO j = 1 TO zone.z.ns.0
rc = LineOut(zonefile, zone.z.fqdn || '.' Right('IN NS ', 60-Length(zone.z.fqdn)) zone.z.ns.j'.')
END
IF zone.z.mx.0 > 0 THEN DO
rc = LineOut(zonefile,';')
rc = LineOut(zonefile,'; mailroutes')
END
DO j = 1 TO zone.z.mx.0
rc = LineOut(zonefile, zone.z.fqdn || '.' Right('IN MX ', 60-Length(zone.z.fqdn)) zone.z.mx.j.pref zone.z.mx.j'.')
END
IF zone.z.cn.0 > 0 THEN DO
rc = LineOut(zonefile,';')
rc = LineOut(zonefile,'; Alias Names (CNAMES)')
END
DO j = 1 TO zone.z.cn.0
rc = LineOut(zonefile, zone.z.cn.j || '.' Right('IN CNAME', 60-Length(zone.z.cn.j)) zone.z.cn.j.cname'.')
END
IF zone.z.a.0 > 0 THEN DO
rc = LineOut(zonefile,';')
rc = LineOut(zonefile,'; Address Records (A Records)')
END
DO j = 1 TO zone.z.a.0
rc = LineOut(zonefile, zone.z.a.j || '.' Right('IN A ', 60-Length(zone.z.a.j)) zone.z.a.j.ip)
END
rc = Stream(zonefile,'C', 'CLOSE')
rc = Stream(namedmasters,'C','OPEN WRITE')
rc = Stream(namedmasters,'C','SEEK < 0')
rc = LineOut(namedmasters,' ')
rc = LineOut(namedmasters,'/* ##'zone.z.fqdn'## -- Start of Zone Configuration for' zone.z.fqdn ' */')
rc = LineOut(namedmasters,' ')
rc = LineOut(namedmasters,'zone "'zone.z.fqdn'" in')
rc = LineOut(namedmasters,'{')
rc = LineOut(namedmasters,' type master;')
rc = LineOut(namedmasters,' file "master/'zone.z.fqdn'";')
rc = LineOut(namedmasters,' /* allow zone transfer for slaves */')
rc = LineOut(namedmasters,' allow-transfer { 'secondarynameservers'; };')
rc = LineOut(namedmasters,'};')
rc = LineOut(namedmasters,' ')
rc = LineOut(namedmasters,'/* ##'zone.z.fqdn'## -- End of Zone Configuration for' zone.z.fqdn ' */')
rc = Stream(namedmasters,'C','CLOSE')
END
RETURN