omit IN class in zone files

This commit is contained in:
ROTTLER Tamas 2025-05-29 15:04:28 +02:00
parent 8c6e0a70ad
commit b7a11b42a3

View File

@ -82,7 +82,7 @@ class Rev:
rec = self.revzones[zone]['ptr'][ip] rec = self.revzones[zone]['ptr'][ip]
if rec['noauto'] or rec['wikionly']: if rec['noauto'] or rec['wikionly']:
continue; continue;
ptr.append(f"{rec['ptr']}\t\tIN PTR\t{rec['name']}") ptr.append(f"{rec['ptr']}\t\tPTR\t{rec['name']}")
return other + ptr return other + ptr
def zone_wiki(self, zone): def zone_wiki(self, zone):
@ -153,8 +153,8 @@ def read_zone(zonefile, rev):
print(f"warning: legacy [vlan] in zone file {zonefile}") print(f"warning: legacy [vlan] in zone file {zonefile}")
if not revzone or not origin: if not revzone or not origin:
continue continue
if r := re.match(r"\s*([a-z0-9.-]+)\s+IN\s+A\s+([0-9.]+)(.*)", line, flags=re.I): if r := re.match(r"([a-z0-9.-]+)\s+(IN\s+)?A\s+([0-9.]+)(.*)", line, flags=re.I):
name, addr, extra = r[1], r[2], r[3] name, addr, extra = r[1], r[3], r[4]
if re.search(r"\[no_autorev\]", extra): if re.search(r"\[no_autorev\]", extra):
continue continue
try: try:
@ -197,14 +197,14 @@ def process_oldrev(oldrev, revfile, rev):
#print(f"revzone: {revzone}") #print(f"revzone: {revzone}")
elif r := re.match(r"\s*;\s*\[info\]\s*(.*)", line): elif r := re.match(r"\s*;\s*\[info\]\s*(.*)", line):
rev.add_zone_info(revzone, r[1]) rev.add_zone_info(revzone, r[1])
elif r := re.match(r"\s*([0-9.]+)\s+IN\s+PTR\s+(\S+)", line, flags=re.I): elif r := re.match(r"([0-9.]+)\s+(IN\s+)?PTR\s+(\S+)", line, flags=re.I):
if not revzone: if not revzone:
print(f"PTR record before $ORIGIN in: {revfile}") print(f"PTR record before $ORIGIN in: {revfile}")
exit(1) exit(1)
ip = revzone +"."+ ".".join(reversed(re.split(r"\.", r[1]))) ip = revzone +"."+ ".".join(reversed(re.split(r"\.", r[1])))
#print(f"ptr: {ip} {r[2]}") #print(f"ptr: {ip} {r[3]}")
try: try:
rev.ptr(revzone, ip, r[2], noauto=True) rev.ptr(revzone, ip, r[3], noauto=True)
except (RevDuplicateAddress, RevInvalidAddress) as e: except (RevDuplicateAddress, RevInvalidAddress) as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
exit(1) exit(1)
@ -215,9 +215,9 @@ def process_oldrev(oldrev, revfile, rev):
def serial_incr(zone, zonefile): def serial_incr(zone, zonefile):
if not (r := re.search(r"IN\s+SOA.*?\s+(\d{1,10})\s", zone)): if not (r := re.search(r"(IN\s+)?SOA.*?\s+(\d{1,10})\s", zone)):
print(f"no SOA record found in {zonefile}", file=sys.stderr) print(f"no SOA record found in {zonefile}", file=sys.stderr)
oldserial = r[1] oldserial = r[2]
if len(oldserial) == 9: if len(oldserial) == 9:
revdigits = 1 revdigits = 1
revbase = 10 revbase = 10
@ -250,7 +250,7 @@ def serial_incr(zone, zonefile):
newserial = f"{newdate}{newrev:02}" newserial = f"{newdate}{newrev:02}"
#print(f"serial {oldserial} -> {newserial}") #print(f"serial {oldserial} -> {newserial}")
return re.sub(r"(IN\s+SOA.*?\s+)"+ oldserial, f"\\g<1>{newserial}", zone) return re.sub(r"((IN\s+)?SOA.*?\s+)"+ oldserial, f"\\g<1>{newserial}", zone)
def dokuwiki_update(text): def dokuwiki_update(text):