|
@@ -1,16 +1,19 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
-function parseZoneFile(string $zone_content, array $types, bool|string $filter_domain = false): array {
|
|
|
|
|
|
+function parseZoneFile(string $zone_content, array $types, bool|string $filter_domain = false, bool $filter_include_subdomains = true): array {
|
|
$parsed_zone_content = [];
|
|
$parsed_zone_content = [];
|
|
foreach (explode(LF, $zone_content) as $zone_line) {
|
|
foreach (explode(LF, $zone_content) as $zone_line) {
|
|
if ($zone_line === '' OR str_starts_with($zone_line, ';'))
|
|
if ($zone_line === '' OR str_starts_with($zone_line, ';'))
|
|
continue; // Ignore empty lines and comments
|
|
continue; // Ignore empty lines and comments
|
|
$elements = preg_split('/[\t ]+/', $zone_line, 4);
|
|
$elements = preg_split('/[\t ]+/', $zone_line, 4);
|
|
- if ($filter_domain !== false AND !str_ends_with($elements[0], $filter_domain))
|
|
|
|
|
|
+ if ($filter_domain !== false AND match ($filter_include_subdomains) {
|
|
|
|
+ true => !str_ends_with($elements[0], $filter_domain),
|
|
|
|
+ false => $elements[0] !== $filter_domain,
|
|
|
|
+ })
|
|
continue; // Ignore records for other domains
|
|
continue; // Ignore records for other domains
|
|
if (!in_array($elements[2], $types, true))
|
|
if (!in_array($elements[2], $types, true))
|
|
continue; // Ignore records generated by Knot
|
|
continue; // Ignore records generated by Knot
|
|
- array_push($parsed_zone_content, array_map('htmlspecialchars', $elements));
|
|
|
|
|
|
+ array_push($parsed_zone_content, $elements);
|
|
}
|
|
}
|
|
return $parsed_zone_content;
|
|
return $parsed_zone_content;
|
|
}
|
|
}
|