Example #1
0
def mod_record(request):
    '''
    修改dnspod域名的记录
    :return:
    '''
    if request.method == "GET":  # 获取该条记录的信息
        record_id = request.GET.get("record_id", "")
        domain_id = request.GET.get("domain_id", "")
        r_obj = record.Record(domain_id=domain_id)

        status, data = r_obj.info(record_id)
        if status:
            return HttpResponse(json.dumps(data.get("record", {})))
        else:
            return HttpResponse(json.dumps(data))

    elif request.method == "POST":  # 修改该条记录
        domain_id = request.POST.get("domain_id", "")
        record_id = request.POST.get("record_id", "")
        sub_domain = request.POST.get("sub_domain", "")
        record_type = request.POST.get("record_type", "")
        record_line = request.POST.get("record_line", "")
        value = request.POST.get("value", "")
        mx = request.POST.get("mx", "")
        ttl = request.POST.get("ttl", "")
        status = request.POST.get("status", "")
        weight = request.POST.get("weight", "")

        r_obj = record.Record(domain_id=domain_id)
        try:
            status_val, data = r_obj.modify(record_id=record_id,
                                            sub_domain=sub_domain,
                                            record_type=record_type,
                                            record_line=record_line,
                                            value=value,
                                            mx=mx,
                                            ttl=ttl,
                                            status=status,
                                            weight=weight)

            if status_val:
                result = {"code": 0, "message": data['status']['message']}
            else:
                result = {"code": 1, "message": data}
        except Exception as e:
            result = {"code": 1, "message": e}

        return HttpResponseRedirect(
            '/dnspod_record/?status={0}&message={1}&domain_id={2}'.format(
                result.get("code", ""), result.get("message", ""), domain_id))
    else:
        return HttpResponse(
            json.dumps(dict(code=1, message="please use get/post method!")))
Example #2
0
def del_record(request):
    '''
    删除dnspod域名的记录
    :return:
    '''
    if request.method == "GET":
        record_id = request.GET.get("record_id", "")
        domain_id = request.GET.get("domain_id", "")
        r_obj = record.Record(domain_id=domain_id)

        status, data = r_obj.remove(record_id)
        try:
            if status:
                result = {"code": 0, "message": data['status']['message']}
            else:
                result = {"code": 1, "message": data}
        except Exception as e:
            result = {"code": 1, "message": e}

        return HttpResponseRedirect(
            '/dnspod_record/?status={0}&message={1}&domain_id={2}'.format(
                result.get("code", ""), result.get("message", ""), domain_id))
    else:
        return HttpResponse(
            json.dumps(dict(code=1, message="please use get method!")))
Example #3
0
def dnspod_record(request):
    '''
    获取dnspod域名的记录列表
    :return:
    '''
    result = {}
    record_list = []
    domain_info = {"id": "", "name": ""}

    status = request.GET.get("status", "")
    message = request.GET.get("message", "")
    if status.isdigit():
        result = {"code": int(status), "message": message}

    if request.method == "GET":
        domain_id = request.GET.get("domain_id", "")
        r_obj = record.Record(domain_id=domain_id)
        status_val, data = r_obj.list()
        if status_val:
            record_list = data.get("records", [])
            domain_info = data.get("domain", {"id": "", "name": ""})
        else:
            result = {"code": 1, "message": data}
        types = record.RECORD_TYPE
        lines = record.RECORD_LINE

        return render(request,
                      "dnspod_record.html", {
                          "record_list": record_list,
                          "domain_info": domain_info,
                          "types": types,
                          "lines": lines,
                          "result": result
                      },
                      using='jinja2')
    else:
        return HttpResponse(
            json.dumps(dict(code=1, message="please use get method!")))
Example #4
0
def record_status(request):
    '''
    修改记录状态
    :return:
    '''
    if request.method == "GET":
        record_id = request.GET.get("record_id", "")
        domain_id = request.GET.get("domain_id", "")
        status = request.GET.get("status", "")
        r_obj = record.Record(domain_id=domain_id)

        status_val, data = r_obj.status(record_id=record_id, status=status)
        if status_val:
            result = {"code": 0, "message": data['status']['message']}
        else:
            result = {"code": 1, "message": data}

        return HttpResponseRedirect(
            '/dnspod_record/?status={0}&message={1}&domain_id={2}'.format(
                result.get("code", ""), result.get("message", ""), domain_id))
    else:
        return HttpResponse(
            json.dumps(dict(code=1, message="please use get method!")))
Example #5
0
def record_remark(request):
    '''
    修改记录备注
    :return:
    '''
    if request.method == "POST":
        record_id = request.POST.get("record_id", "")
        domain_id = request.POST.get("domain_id", "")
        remark = request.POST.get("remark", "")
        r_obj = record.Record(domain_id=domain_id)
        try:
            status_val, data = r_obj.remark(record_id=record_id, remark=remark)
            if status_val:
                result = {"code": 0, "message": data['status']['message']}
            else:
                result = {"code": 1, "message": data}
        except Exception as e:
            result = {"code": 1, "message": e}
        return HttpResponseRedirect(
            '/dnspod_record/?status={0}&message={1}&domain_id={2}'.format(
                result.get("code", ""), result.get("message", ""), domain_id))
    else:
        return HttpResponse(
            json.dumps(dict(code=1, message="please use post method!")))