Esempio n. 1
0
    def add_default_records(self, endpoint=None):
        # sanity check
        if not self.domain_id:
            raise Exception("Cannot add default records when domain_id is not set")

        # don't duplicate SOA record
        try:
            existing_soa = Record.get(Record.domain_id == self.domain_id, Record.type == RecordType().set("SOA"))
        except DoesNotExist:
            # create SOA record
            try:
                default_soa = DefaultRecord.get(DefaultRecord.type == RecordType().set("SOA"))
                soa = Record()
                soa.domain_id = self.domain_id
                soa.host = default_soa.host.replace("DOMAIN", self.domain)
                soa.val = default_soa.val
                soa.ttl = default_soa.ttl
                soa.type = default_soa.type

                # replace uses of DOMAIN
                soa.save()
                if endpoint is not None:
                    endpoint.dns_log(soa.domain_id, "added soa")
            except DoesNotExist:
                # no default SOA record set!
                pass

        # create all other records
        default_records = DefaultRecord.select().where(DefaultRecord.type != RecordType().set("SOA"))

        for record in default_records:
            new = Record()

            new.domain_id = self.domain_id
            new.distance = record.distance
            new.host = record.host.replace("DOMAIN", self.domain)
            new.val = record.val.replace("DOMAIN", self.domain)
            new.distance = record.distance
            new.port = record.port
            new.ttl = record.ttl
            new.type = record.type
            new.weight = record.weight

            new.save()
            if endpoint is not None:
                endpoint.dns_log(
                    new.domain_id,
                    ("added " + RecordType().get(new.type) + " with host " + new.host + " and value " + new.val),
                )
Esempio n. 2
0
    def test_srv_record(self):
        model = Record()

        model.type = 'V'
        model.host = '_xmpp-client._tcp.example.com.'
        model.val = 'xmpp.example.com'
        model.ttl = '3600'
        model.distance = 0
        model.weight = 10
        model.port = 5222

        expected = (":_xmpp-client._tcp.example.com."
                    ":33"
                    r":\000\000\000\012\024\146\004xmpp\007example\003com\000"
                    ":3600\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)
Esempio n. 3
0
    def test_srv_record(self):
        model = Record()

        model.type = 'V'
        model.host = '_xmpp-client._tcp.example.com.'
        model.val = 'xmpp.example.com'
        model.ttl = '3600'
        model.distance = 0
        model.weight = 10
        model.port = 5222

        expected = (
            ":_xmpp-client._tcp.example.com."
            ":33"
            r":\000\000\000\012\024\146\004xmpp\007example\003com\000"
            ":3600\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )
Esempio n. 4
0
    def add_default_records(self, endpoint=None, skipSoa=False):
        # sanity check
        if not self.domain_id:
            raise Exception(
                "Cannot add default records when domain_id is not set")

        if not skipSoa:
            try:
                soa = self.add_default_soa_record(endpoint)
            except DoesNotExist:
                # no default SOA record set!
                pass

        # create all other records
        default_records = DefaultRecord.select().where(
            DefaultRecord.type != RecordType().set("SOA"))

        for record in default_records:
            new = Record()

            new.domain_id = self.domain_id
            new.distance = record.distance
            new.host = record.host.replace("DOMAIN", self.domain)
            new.val = record.val.replace("DOMAIN", self.domain)
            new.distance = record.distance
            new.port = record.port
            new.ttl = record.ttl
            new.type = record.type
            new.weight = record.weight

            new.save()
            if endpoint is not None:
                endpoint.dns_log(
                    new.domain_id,
                    ("added " + RecordType().get(new.type) + " with host " +
                     new.host + " and value " + new.val))