Ejemplo n.º 1
0
Archivo: dns.py Proyecto: allgi/mmc
 def reverseZone(self, network):
     """
     Build a reverse zone name
     """
     ret = network.split(".")
     ret.reverse()
     return ".".join(ret) + self.reversePrefix
Ejemplo n.º 2
0
Archivo: dns.py Proyecto: allgi/mmc
 def reverseZone(self, network):
     """
     Build a reverse zone name
     """
     ret = network.split(".")
     ret.reverse()
     return ".".join(ret) + self.reversePrefix
Ejemplo n.º 3
0
Archivo: dns.py Proyecto: allgi/mmc
    def addZone(self,
                name,
                network=None,
                netmask=None,
                reverse=False,
                description=None,
                nameserver="ns",
                nameserverip=None):
        """
        @param name: the zone name
        @param network: the network address defined in this zone (needed to build the reverse zone)
        @param netmask: the netmask address (needed to build the reverse zone)
        """
        r = AF().log(PLUGIN_NAME, AA.NETWORK_ADD_DNS_ZONE, [(name, AT.ZONE)],
                     network)
        if reverse:
            if network == None or netmask == None:
                raise "Won't create reverse zone as asked, missing network or netmask"
            netmask = int(netmask)
            # Build network address start according to netmask
            elements = network.split(".")
            if netmask == 8:
                network = elements[0]
            elif netmask == 16:
                network = ".".join(elements[0:2])
            elif netmask == 24:
                network = ".".join(elements[0:3])
            else:
                raise "Won't create reverse zone as asked, netmask is not 8, 16 or 24"

        if not self.pdns:
            # Create Bind configuration files
            f = open(os.path.join(self.configDns.bindLdapDir, name), "w")
            d = {
                "zone": name,
                "ldapurl": self.config.ldapurl + "/" + self.configDns.dnsDN,
                "dnsreader": urllib.quote(self.configDns.dnsReader),
                "dnsreaderpasswd":
                urllib.quote(self.configDns.dnsReaderPassword)
            }
            f.write(self.templateZone % d)
            if reverse:
                d["zone"] = self.reverseZone(network)
                f.write(self.templateZone % d)
            f.close()
            os.chmod(os.path.join(self.configDns.bindLdapDir, name), 0640)

            f = open(self.configDns.bindLdap, "r")
            found = False
            toadd = 'include "' + os.path.join(
                self.configDns.bindLdapChrootConfPath, name) + '";\n'
            for line in f:
                if line == toadd:
                    found = True
                    break
            f.close()
            if not found:
                f = open(self.configDns.bindLdap, "a")
                f.write(toadd)
                f.close()

        # Create the needed zones object in LDAP
        if reverse:
            reverseZone = self.reverseZone(network)
            self.addDnsZone(reverseZone, "Reverse zone for " + name, name)
        else:
            reverseZone = None
        self.addDnsZone(name, description)

        # Fill SOA
        self.addSOA(name)
        if self.pdns:
            ns = nameserver + "." + name
            mailaddr = "admin." + name
        else:
            ns = nameserver + "." + name + "."
            mailaddr = "admin." + name + "."
        rec = {
            "nameserver": ns,
            "emailaddr": mailaddr,
            "serial": self.computeSerial(),
            "refresh": "2D",
            "retry": "15M",
            "expiry": "2W",
            "minimum": "1H",
        }
        self.setSOARecord(name, rec)
        self.setSOANSRecord(name, ns)
        # A record defaults to the server ip
        self.setSOAARecord(name, nameserverip)

        # Fill SOA for reverse zone too
        if reverse:
            self.addSOA(reverseZone, name)
            self.setSOARecord(reverseZone, rec)
            self.setSOANSRecord(reverseZone, ns)

        if nameserverip:
            # Add a A record for the primary nameserver
            self.addRecordA(name, nameserver, nameserverip)
        r.commit()
Ejemplo n.º 4
0
Archivo: dns.py Proyecto: allgi/mmc
    def addZone(self, name, network = None, netmask = None, reverse = False, description = None, nameserver = "ns", nameserverip = None):
        """
        @param name: the zone name
        @param network: the network address defined in this zone (needed to build the reverse zone)
        @param netmask: the netmask address (needed to build the reverse zone)
        """
        r = AF().log(PLUGIN_NAME, AA.NETWORK_ADD_DNS_ZONE, [(name, AT.ZONE)], network)
        if reverse:
            if network == None or netmask == None:
                raise "Won't create reverse zone as asked, missing network or netmask"
            netmask = int(netmask)
            # Build network address start according to netmask
            elements = network.split(".")
            if netmask == 8:
                network = elements[0]
            elif netmask == 16:
                network = ".".join(elements[0:2])
            elif netmask == 24:
                network = ".".join(elements[0:3])
            else:
                raise "Won't create reverse zone as asked, netmask is not 8, 16 or 24"

        if not self.pdns:
            # Create Bind configuration files
            f = open(os.path.join(self.configDns.bindLdapDir, name), "w")
            d = {
                "zone" : name,
                "ldapurl" : self.config.ldapurl + "/" + self.configDns.dnsDN,
                "dnsreader": urllib.quote(self.configDns.dnsReader),
                "dnsreaderpasswd" : urllib.quote(self.configDns.dnsReaderPassword)
                }
            f.write(self.templateZone % d)
            if reverse:
                d["zone"] = self.reverseZone(network)
                f.write(self.templateZone % d)
            f.close()
            os.chmod(os.path.join(self.configDns.bindLdapDir, name), 0640)

            f = open(self.configDns.bindLdap, "r")
            found = False
            toadd = 'include "' + os.path.join(self.configDns.bindLdapChrootConfPath, name) + '";\n'
            for line in f:
                if line == toadd:
                    found = True
                    break
            f.close()
            if not found:
                f = open(self.configDns.bindLdap, "a")
                f.write(toadd)
                f.close()

        # Create the needed zones object in LDAP
        if reverse:
            reverseZone = self.reverseZone(network)
            self.addDnsZone(reverseZone, "Reverse zone for " + name, name)
        else:
            reverseZone = None
        self.addDnsZone(name, description)

        # Fill SOA
        self.addSOA(name)
        if self.pdns:
            ns = nameserver + "." + name
            mailaddr = "admin." + name
        else:
            ns = nameserver + "." + name + "."
            mailaddr = "admin." + name + "."
        rec = {
            "nameserver" : ns,
            "emailaddr" :  mailaddr,
            "serial" : self.computeSerial(),
            "refresh" : "2D",
            "retry" : "15M",
            "expiry" : "2W",
            "minimum" : "1H",
            }
        self.setSOARecord(name, rec)
        self.setSOANSRecord(name, ns)
        # A record defaults to the server ip
        self.setSOAARecord(name, nameserverip)

        # Fill SOA for reverse zone too
        if reverse:
            self.addSOA(reverseZone, name)
            self.setSOARecord(reverseZone, rec)
            self.setSOANSRecord(reverseZone, ns)

        if nameserverip:
            # Add a A record for the primary nameserver
            self.addRecordA(name, nameserver, nameserverip)
        r.commit()