import dns.rdataclass
import dns.zone
import io
+import tarfile
class Exporter(abc.ABC):
"""
"""
type = dns.rdatatype.CNAME
content = "."
+
+
+class SquidGuardExporter(Exporter):
+ """
+ Export a list in the format that squidguard can process it
+ """
+ def export(self, f):
+ # Create a tar file
+ with tarfile.open(fileobj=f, mode="w|gz") as tarball:
+ # Write the list
+ self._write_list(tarball, self.list)
+
+ def _write_list(self, tarball, list):
+ # Create a new
+ file = tarfile.TarInfo(name="%s/domains" % list.slug)
+
+ # Write the payload to memory
+ f = io.BytesIO()
+
+ # Create a domain exporter
+ exporter = DomainsExporter(self.backend, list)
+
+ # Write all domains to the buffer
+ exporter(f)
+
+ # Assign the list to be owned by nobody
+ file.uname = file.gname = "nobody"
+
+ # Set the length
+ file.size = f.tell()
+
+ # Set the mtime
+ file.mtime = list.updated_at.timestamp()
+
+ # Reset the buffer
+ f.seek(0)
+
+ # Write the buffer to the tarball
+ tarball.addfile(file, fileobj=f)
Exports the list
"""
formats = {
- "domains" : exporters.DomainsExporter,
- "dnsbl" : exporters.BlocklistExporter,
- "hosts" : exporters.HostsExporter,
- "rpz" : exporters.RPZExporter,
+ "domains" : exporters.DomainsExporter,
+ "dnsbl" : exporters.BlocklistExporter,
+ "hosts" : exporters.HostsExporter,
+ "rpz" : exporters.RPZExporter,
+ "squidguard" : exporters.SquidGuardExporter,
}
# Fetch the exporter
export.add_argument("output", type=argparse.FileType("wb"),
help=_("The output file"))
export.add_argument("--format", default="domains",
- choices=("domains", "dnsbl", "hosts", "rpz",), help=_("Output Format"))
+ choices=("domains", "dnsbl", "hosts", "rpz", "squidguard",),
+ help=_("Output Format"))
export.set_defaults(func=self.__export)
# export-all
Exports all lists
"""
formats = {
- "domains" : "domains.txt",
- "dnsbl" : "dnsbl.zone",
- "hosts" : "hosts.txt",
- "rpz" : "rpz.zone",
+ "domains" : "domains.txt",
+ "dnsbl" : "dnsbl.zone",
+ "hosts" : "hosts.txt",
+ "rpz" : "rpz.zone",
+ "squidguard" : "squidguard.tar.gz",
}
# Ensure the output directory exists