def perform_destroy(self, instance): rid = instance.id dns_zone_id = instance.dns_zone_id try: model = DnsZone.objects.get(id=dns_zone_id) except DnsZone.DoesNotExist: return Response('Zone文件不存在,可能已经删除', status=status.HTTP_404_NOT_FOUND) else: zone = Zone(model) zone.user = self.request.user.username zone.delete_record(rid)
def record_del(request): if request.method == 'POST': rid = request.REQUEST.get('id', 0) rid = int(rid) if rid and rid.isdigit() else 0 dns_zone_id = request.REQUEST.get('dns_zone_id', 0) dns_zone_id = int( dns_zone_id) if dns_zone_id and dns_zone_id.isdigit() else 0 try: model = DnsZone.objects.get(id=dns_zone_id) except DnsZone.DoesNotExist: return Response('Zone文件不存在,可能已经删除', status=status.HTTP_404_NOT_FOUND) else: zone = Zone(model) zone.user = request.user.username zone.delete_record(rid) return Response('删除记录成功', status=status.HTTP_200_OK)
def domain_del(request): ''' 删除域名列表 ''' if request.methed == 'POST': key = request.REQUEST.get('key', 'merchant_shop') intime = request.REQUEST.get('intime', '1') intime = int(intime) if intime and intime.isdigit() else 1 lists = [ item.strip() for item in request.REQUEST.get('lists', '').split(',') ] if not lists: response = simplejson.dumps({'success': False, 'msg': u'请输入域名列表'}) return HttpResponse(response) pat = r'^[a-zA-Z0-9]{4,20}(\.yhd\.com)?$' for domain in lists: m = re.match(pat, domain) if not m: response = simplejson.dumps({ 'success': False, 'msg': u'域名不符合规则, 请检查' }) return HttpResponse(response) try: item = DnsApiZone.objects.get(key=key) except DnsApiZone.DoesNotExist: response = simplejson.dumps({'success': False, 'msg': u'无效的请求'}) return HttpResponse(response) model = item.zone if not model: response = simplejson.dumps({'success': False, 'msg': u'Zone不存在'}) return HttpResponse(response) zone = Zone(model) zone.user = '******' zone.owner = 9 # owner = 9 表示属于API result = [] rlists = [] for domain in lists: domain = domain.strip() domains = zone.get_domains(domain, 'CNAME') if not domains: result.append({'domainName': domain, 'msg': u'域名不存在,无法删除'}) rlists.append(domain) continue o = domains[0] if o.owner != 9: # 只能删除API添加的域名 result.append({ 'domainName': domain, 'msg': u'没有权限删除该域名,请联系SA' }) rlists.append(domain) continue try: zone.delete_record(o.id) except ZoneException as e: result.append({'domainName': domain, 'msg': str(e)}) rlists.append(domain) else: result.append({'domainName': domain, 'msg': 'success'}) response = simplejson.dumps({ 'success': True, 'lists': rlists, 'result': result }) return HttpResponse(response)