Exemplo n.º 1
0
def view_delete_record(request, dns_server, zone_name):
    """View to handle the deletion of records."""
    dns_server = models.BindServer.objects.get(hostname=dns_server)
    rr_list = request.POST.getlist("rr_list")

    if len(rr_list) == 0:
        messages.error(request, "Select at least one record for deletion.")
        return redirect('zone_list',
                        dns_server=dns_server,
                        zone_name=zone_name)

    if request.method == 'POST':
        form = forms.FormDeleteRecord(request.POST)
        if form.is_valid():
            form_cleaned = form.cleaned_data
            rr_list = form_cleaned["rr_list"]
            try:
                response = helpers.delete_record(form_cleaned["dns_server"],
                                                 rr_list,
                                                 form_cleaned["key_name"])
            except KeyringException as exc:
                for record in rr_list:
                    messages.error(
                        request,
                        "Deleting %s.%s failed: %s" % (record, zone_name, exc))
            else:
                for record in response:
                    if record['success'] == True:
                        messages.success(
                            request, "%s.%s was removed successfully." %
                            (record['record'], zone_name))
                    else:
                        messages.error(
                            request, "Deleting %s.%s failed: %s" %
                            (record['record'], zone_name,
                             record['description']))
                return redirect('zone_list',
                                dns_server=dns_server,
                                zone_name=zone_name)
    else:
        key_id = models.BindServer.objects.get(
            hostname=dns_server).default_transfer_key.id
        form = forms.FormDeleteRecord(initial={
            'zone_name': zone_name,
            'key_name': key_id
        })

    return render(
        request, "bcommon/delete_record.html", {
            "dns_server": dns_server,
            "zone_name": zone_name,
            "rr_list": rr_list,
            "form": form
        })
Exemplo n.º 2
0
def view_delete_record(request, dns_server, zone_name):
    """View to handle the deletion of records."""
    dns_server = models.BindServer.objects.get(hostname=dns_server)
    rr_list = request.POST.getlist("rr_list")

    if len(rr_list) == 0:
        messages.error(request, "Select at least one record for deletion.")
        return redirect('zone_list',
                        dns_server=dns_server,
                        zone_name=zone_name)

    if request.method == 'POST':
        form = forms.FormDeleteRecord(request.POST)
        if form.is_valid():
            form_cleaned = form.cleaned_data
            rr_list = form_cleaned["rr_list"]
            try:
                response = helpers.delete_record(form_cleaned["dns_server"],
                                                 rr_list,
                                                 form_cleaned["key_name"])
            except exceptions.KeyringException as exc:
                for record in rr_list:
                    messages.error(request, "Deleting %s.%s failed: %s" %
                                   (record, zone_name, exc))
            else:
                for record in response:
                    if record['success'] == True:
                        messages.success(request, "%s.%s was removed successfully." %
                                         (record['record'], zone_name))
                    else:
                        messages.error(request, "Deleting %s.%s failed: %s" %
                                       (record['record'], zone_name, record['description']))
                return redirect('zone_list',
                                dns_server=dns_server,
                                zone_name=zone_name)
    else:
        key_id = models.BindServer.objects.get(
            hostname=dns_server).default_transfer_key.id
        form = forms.FormDeleteRecord(initial={
            'zone_name': zone_name,
            'key_name': key_id
            })

    return render(request, "bcommon/delete_record.html",
                  {"dns_server": dns_server,
                   "zone_name": zone_name,
                   "rr_list": rr_list,
                   "form": form})
Exemplo n.º 3
0
def view_delete_result(request):
    """ View that deletes records and returns the response. """
    if request.method == "GET":
        return redirect("/")

    form = forms.FormDeleteRecord(request.POST)

    if form.is_valid():
        clean_form = form.cleaned_data
    else:
        # TODO: What situations would cause this form
        # not to validate?
        print "in view_delete_result, form errors: %r" % form.errors

    delete_result = helpers.delete_record(clean_form["dns_server"],
                                          clean_form["rr_list"],
                                          clean_form["key_name"])

    return render(request, "bcommon/response_result.html",
                  { "response" : delete_result })
Exemplo n.º 4
0
def view_delete_record(request, dns_server, zone_name):
    """View to handle the deletion of records."""
    if not request.user.is_staff and not request.user.is_superuser:
        return render(request, "403.html", status=403)
    dns_server = models.BindServer.objects.get(hostname=dns_server)
    rr_list = request.POST.getlist("rr_list")

    if len(rr_list) == 0:
        messages.error(request, "Select at least one record for deletion.")
        return redirect('zone_list',
                        dns_server=dns_server,
                        zone_name=zone_name)

    if request.method == 'POST':
        form = forms.FormDeleteRecord(request.POST)
        if form.is_valid():
            form_cleaned = form.cleaned_data
            name_list = form_cleaned["name_list"]
            data_list = form_cleaned["data_list"]
            type_list = form_cleaned["type_list"]
            try:
                response = helpers.delete_record(form_cleaned["dns_server"],
                                                 name_list, type_list,
                                                 data_list,
                                                 form_cleaned["key_name"])
            except KeyringException as exc:
                for record in name_list:
                    messages.error(
                        request,
                        "Deleting %s.%s failed: %s" % (record, zone_name, exc))
            else:
                for record in response:
                    if record['success'] == True:
                        messages.success(
                            request, "%s.%s was removed successfully." %
                            (record['record'], zone_name))
                    else:
                        messages.error(
                            request, "Deleting %s.%s failed: %s" %
                            (record['record'], zone_name,
                             record['description']))
                return redirect('zone_list',
                                dns_server=dns_server,
                                zone_name=zone_name)
        else:
            name_list = []
            data_list = []
            type_list = []
            for cur in rr_list:
                name_list.append(cur.split('||')[0])
                data_list.append(cur.split('||')[1])
                type_list.append(cur.split('||')[2])

    else:
        form = forms.FormDeleteRecord(initial={'zone_name': zone_name})

    return render(
        request, "bcommon/delete_record.html", {
            "dns_server": dns_server,
            "zone_name": zone_name,
            "rr_list": rr_list,
            "data_list": data_list,
            "type_list": type_list,
            "name_list": name_list,
            "form": form
        })
Exemplo n.º 5
0
def view_delete_record(request, dns_server, zone_name):
    """View to handle the deletion of records."""
    if not request.user.is_staff and not request.user.is_superuser:
        return render(request, "403.html", status=403)
    dns_server = models.BindServer.objects.get(hostname=dns_server)
    rr_list = request.POST.getlist("rr_list")

    if len(rr_list) == 0:
        messages.error(request, "Select at least one record for deletion.")
        return redirect('zone_list',
                        dns_server=dns_server,
                        zone_name=zone_name)

    if request.method == 'POST':
        form = forms.FormDeleteRecord(request.POST)
        if form.is_valid():
            form_cleaned = form.cleaned_data
            name_list = form_cleaned["name_list"]
            data_list = form_cleaned["data_list"]
            type_list = form_cleaned["type_list"]
            try:
                response = helpers.delete_record(form_cleaned["dns_server"],
                                                 name_list,
												 type_list,
												 data_list,
                                                 form_cleaned["key_name"])
            except KeyringException as exc:
                for record in name_list:
                    messages.error(request, "Deleting %s.%s failed: %s" %
                                   (record, zone_name, exc))
            else:
                for record in response:
                    if record['success'] == True:
                        messages.success(request, "%s.%s was removed successfully." %
                                         (record['record'], zone_name))
                    else:
                        messages.error(request, "Deleting %s.%s failed: %s" %
                                       (record['record'], zone_name, record['description']))
                return redirect('zone_list',
                                dns_server=dns_server,
                                zone_name=zone_name)
        else:
            name_list = []
            data_list = []
            type_list = []
            for cur in rr_list:
                name_list.append(cur.split('||')[0])
                data_list.append(cur.split('||')[1])
                type_list.append(cur.split('||')[2])

    else:
        form = forms.FormDeleteRecord(initial={'zone_name': zone_name})

    return render(request, "bcommon/delete_record.html",
                  {"dns_server": dns_server,
                   "zone_name": zone_name,
                   "rr_list": rr_list,
				   "data_list": data_list,
				   "type_list": type_list,
				   "name_list": name_list,
                   "form": form})