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 get_delete_domain(self, domain_id): if self.auth.account.account_type == 'senior_admin': return ModelDomain.get(ModelDomain.domain_id == domain_id) if self.auth.account.can_delete_domain(domain_id): return self.auth.account.domains[domain_id]["domain"] abort(403, message="Not authorized to delete this domain")
def get_domain(self, domain_id): return ModelDomain.get(ModelDomain.domain_id == domain_id)
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