Esempio n. 1
0
    def test_soa_record(self):
        domain = Domain()
        domain.domain = 'example.com'
        model = Record()

        # joined domain on domain_id
        model.domain_id = domain
        model.type = 'S'
        model.host = 'hostmaster.example.com:ns1.example.com'
        model.val = '16384:2048:1048576:2560:'
        model.ttl = '86400'

        expected = (
            "Zexample.com"
            ":ns1.example.com"
            ":hostmaster.example.com"
            ":"
            ":16384"
            ":2048"
            ":1048576"
            ":2560"
            ":86400\n"
        )

        self.assertEquals(
            self.export.data_line_from_model(model),
            expected
        )
Esempio n. 2
0
    def post(self):
        domain = request.form.get("domain")
        if domain is None:
            abort(400, message="domain parameter is required")

        # check for duplicate first
        try:
            ModelDomain.get(ModelDomain.domain == domain)
            abort(400, message="Domain already exists")
        except peewee.DoesNotExist:
            pass

        model = ModelDomain()
        model.domain = domain
        if self.auth.account.account_type != 'senior_admin':
            model.status = 'inactive'
            model.owner_id = self.auth.account.account_id

        try:
            model.save()

            self.dns_log(
                model.domain_id,
                "Added domain " + model.domain + " with status " + model.status
            )
        except ValueError:
            abort(400, message="Invalid parameters")
        except peewee.IntegrityError:
            # race condition, unique constraint will catch it
            abort(400, message="Domain already exists")

        # add default records
        model.add_default_records(self)
        default_records = model.get_records()
        records = []
        for record in default_records:
            records.append(record.to_clean_dict())

        if self.auth.account.account_type != 'senior_admin':
            common = vegadns.api.email.common.Common()
            to = common.get_support_email()
            subject = "New Inactive Domain Created"
            msg_body = "Inactive domain \"" + model.domain + \
                "\" added by " + self.auth.account.email + ".\n\n" + \
                "Thanks,\n\nVegaDNS"

            vegadns.api.email.send(to, subject, msg_body)

        return {
            'status': 'ok',
            'domain': model.to_clean_dict(),
            'records': records
        }, 201
    def test_format_map(self):
        domain = Domain()
        domain.domain_id = 252
        domain.domain = "example.com"

        group = Group()
        group.group_id = 252
        group.name = "Test Group 1"

        map = DomainGroupMap()
        map.map_id = 1
        map.group_id = group
        map.domain_id = domain
        map.permissions = 7

        formatted = map.format_map(map)
        self.assertTrue(formatted["can_read"])
        self.assertTrue(formatted["can_write"])
        self.assertTrue(formatted["can_delete"])
        self.assertEquals(formatted["map_id"], map.map_id)
        self.assertEquals(formatted["group"], map.group_id.to_clean_dict())
        self.assertEquals(formatted["domain"], map.domain_id.to_clean_dict())
Esempio n. 4
0
    def test_soa_record(self):
        domain = Domain()
        domain.domain = 'example.com'
        model = Record()

        # joined domain on domain_id
        model.domain_id = domain
        model.type = 'S'
        model.host = 'hostmaster.example.com:ns1.example.com'
        model.val = '16384:2048:1048576:2560:'
        model.ttl = '86400'

        expected = ("Zexample.com"
                    ":ns1.example.com"
                    ":hostmaster.example.com"
                    ":"
                    ":16384"
                    ":2048"
                    ":1048576"
                    ":2560"
                    ":86400\n")

        self.assertEquals(self.export.data_line_from_model(model), expected)
Esempio n. 5
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('domain',
                            required=True,
                            location=['form', 'json'],
                            help='domain parameter is required')
        parser.add_argument('move_colliding_records',
                            type=bool,
                            location=['form', 'json'],
                            default=False)
        parser.add_argument('skip_soa',
                            type=bool,
                            location=['form', 'json'],
                            default=False)
        parser.add_argument('skip_default_records',
                            type=bool,
                            location=['form', 'json'],
                            default=False)
        args = parser.parse_args()

        # Lower case the domain
        domain = args['domain'].lower()

        # check for duplicate first
        try:
            ModelDomain.get(ModelDomain.domain == domain)
            abort(400, message="Domain already exists")
        except peewee.DoesNotExist:
            pass

        # check for duplicate records
        duplicate_records = ModelRecord().select().where((ModelRecord.host**(
            '%.' + domain)) | (ModelRecord.host == domain))

        move_colliding_records = False
        if duplicate_records.count() > 0:
            move_colliding_records = args['move_colliding_records']
            if (move_colliding_records is True
                    and self.auth.account.account_type != 'senior_admin'):

                m = "You must be a senior_admin to move colliding records"
                abort(403, message=m)
            if move_colliding_records is False:
                m = "Unable to create domain, there are colliding records"
                abort(409, message=m)

        model = ModelDomain()
        model.domain = domain
        if self.auth.account.account_type != 'senior_admin':
            model.status = 'inactive'
            model.owner_id = self.auth.account.account_id

        try:
            model.save()

            self.dns_log(
                model.domain_id, "Added domain " + model.domain +
                " with status " + model.status)
        except ValueError:
            abort(400, message="Invalid parameters")
        except peewee.IntegrityError:
            # race condition, unique constraint will catch it
            abort(400, message="Domain already exists")

        # add default records
        records = []
        if args['skip_default_records'] is False:
            model.add_default_records(self, skipSoa=args['skip_soa'])
            default_records = model.get_records()
            for record in default_records:
                records.append(record.to_clean_dict())

        # move colliding records
        if move_colliding_records is True:
            for dr in duplicate_records:
                dr.domain_id = model.domain_id
                dr.save()
                records.append(dr.to_clean_dict())

        if self.auth.account.account_type != 'senior_admin':
            common = vegadns.api.email.common.Common()
            to = common.get_support_email()
            subject = "New Inactive Domain Created"
            msg_body = "Inactive domain \"" + model.domain + \
                "\" added by " + self.auth.account.email + ".\n\n" + \
                "Thanks,\n\nVegaDNS"

            vegadns.api.email.send(to, subject, msg_body)

        # notify listeners of dns data change
        self.send_update_notification()

        return {
            'status': 'ok',
            'domain': model.to_clean_dict(),
            'records': records
        }, 201