예제 #1
0
def view_add_cname_record(request, dns_server, zone_name, record_name):
    """View to allow to add CNAME records."""
    if not request.user.is_staff and not request.user.is_superuser:
        return render(request, "403.html", status=403)
    this_server = get_object_or_404(models.BindServer, hostname=dns_server)

    if request.method == 'POST':
        form = forms.FormAddCnameRecord(request.POST)
        if form.is_valid():
            form_cleaned = form.cleaned_data
            try:
                helpers.add_cname_record(form_cleaned["dns_server"],
                                         str(form_cleaned["zone_name"]),
                                         str(form_cleaned["cname"]),
                                         '%s.%s' % (str(form_cleaned["originating_record"]),
                                                    str(form_cleaned["zone_name"])),
                                         form_cleaned["ttl"],
                                         form_cleaned["key_name"])
            except (KeyringException, RecordException) as exc:
                messages.error(request, "Adding %s.%s failed: %s" %
                               (form_cleaned["cname"], zone_name, exc))
            else:
                messages.success(request, "%s.%s was added successfully." %
                                 (form_cleaned["cname"], zone_name))
                return redirect('zone_list',
                                dns_server=dns_server,
                                zone_name=zone_name)
    else:
        form = forms.FormAddCnameRecord(initial={'originating_record': record_name,
                                                 'zone_name': zone_name})

    return render(request, "bcommon/add_cname_record_form.html",
                  {"dns_server": this_server,
                   "form": form})
예제 #2
0
def view_add_cname_record(request, dns_server, zone_name, record_name):
    """View to allow to add CNAME records."""
    this_server = get_object_or_404(models.BindServer, hostname=dns_server)

    if request.method == 'POST':
        form = forms.FormAddCnameRecord(request.POST)
        if form.is_valid():
            form_cleaned = form.cleaned_data
            try:
                helpers.add_cname_record(
                    form_cleaned["dns_server"], str(form_cleaned["zone_name"]),
                    str(form_cleaned["cname"]),
                    '%s.%s' % (str(form_cleaned["originating_record"]),
                               str(form_cleaned["zone_name"])),
                    form_cleaned["ttl"], form_cleaned["key_name"])
            except (exceptions.KeyringException,
                    exceptions.RecordException) as exc:
                messages.error(
                    request, "Adding %s.%s failed: %s" %
                    (form_cleaned["cname"], zone_name, exc))
            else:
                messages.success(
                    request, "%s.%s was added successfully." %
                    (form_cleaned["cname"], zone_name))
                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.FormAddCnameRecord(
            initial={
                'originating_record': record_name,
                'zone_name': zone_name,
                'key_name': key_id
            })

    return render(request, "bcommon/add_cname_record_form.html", {
        "dns_server": this_server,
        "form": form
    })
예제 #3
0
def view_add_cname_result(request):
    """ Process input on the CNAME form and provide a response."""
    if request.method == "GET":
        return redirect("/")

    errors = ""
    add_cname_response = ""
    form = forms.FormAddCnameRecord(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        try:
            add_cname_response = helpers.add_cname_record(
                cd["dns_server"],
                cd["zone_name"],
                cd["cname"],
                str(cd["originating_record"]),
                cd["ttl"],
                cd["key_name"])
        except exceptions.RecordException, err:
            errors = err

        return render(request, "bcommon/response_result.html",
                      {"response" : add_cname_response,
                       "errors" : errors })