Exemple #1
0
def del_record_api():
    tmp_dict = {}
    tmp_dict["success"] = "False"
    auth_result = auth_user()
    if not auth_result[0]:
        tmp_dict["msg"] = "no sso auth"
        return json.dumps(tmp_dict)
    else:
        userinfo = auth_result[1]
    if request.method == "POST":
        try:
            domain_id = request.form["domain_id"]
            domain_info = Domain.get_domain_by_domain_id(domain_id)
            record_id = request.form["record_id"]
            if if_user_id_have_domain_rights(userinfo["user_id"], domain_id):
                Logger.action_log(userinfo["username"] + " del record ")
                if domain_info[2] == "dnspod":
                    result = del_dnspod_record_lib(domain_id, record_id)
                    tmp_dict["success"] = result[0]
                    tmp_dict["msg"] = result[1]
                    return json.dumps(tmp_dict)
                elif domain_info[2] == "local_bind":
                    result = del_dns_record_lib(domain_id, record_id)
                    tmp_dict["success"] = result[0]
                    tmp_dict["msg"] = result[1]
                    return json.dumps(tmp_dict)
            else:
                tmp_dict["msg"] = "no this domain rights"
                return json.dumps(tmp_dict)
        except Exception, e:
            print e
            tmp_dict["msg"] = "unknown error"
            return json.dumps(tmp_dict)
Exemple #2
0
def change_dnspod_record_status(domain_id, record_id, status):
    values = {'login_email': config.DNSPOD_USER, 'login_password': config.DNSPOD_PW, 'format': 'json', 'domain_id': domain_id, 'record_id': record_id, 'status': status} 
    json_data = curl_dnspod(values, "/Record.Status")
    Logger.action_log(str(json_data))
    if json_data['status']['code'] == "1":
        return ["true", ""]
    else:
        return ["false", json_data['status']['message']]
Exemple #3
0
def update_dnspod_record(domain_id, record_id, name, type, line, value, ttl):
    values = {'login_email': config.DNSPOD_USER, 'login_password': config.DNSPOD_PW, 'format': 'json', 'domain_id': domain_id, 'record_id': record_id, 'sub_domain': name, 'record_type':type, 'record_line':line, 'value':value, 'ttl':ttl} 
    json_data = curl_dnspod(values, "/Record.Modify")
    Logger.action_log(str(json_data))
    if json_data['status']['code'] == "1":
        return ["true", json_data['record']['id']]
    else:
        return ["false", json_data['status']['message']]
Exemple #4
0
def add_record_api():
    tmp_dict = {}
    tmp_dict["success"] = "False"
    auth_result = auth_user()
    if not auth_result[0]:
        tmp_dict["msg"] = "no sso auth"
        return json.dumps(tmp_dict)
    else:
        userinfo = auth_result[1]
    if request.method == "POST":
        try:
            domain_id = request.form["domain_id"]
            domain_info = Domain.get_domain_by_domain_id(domain_id)
            name = request.form["name"]
            type = request.form["type"]
            line = request.form["line"]
            line = line.encode("utf-8")
            value = request.form["value"]
            ttl = request.form["ttl"]
            if if_user_id_have_domain_rights(userinfo["user_id"], domain_id):
                Logger.action_log(userinfo["username"] + " add record ")
                if domain_info[2] == "dnspod":
                    result = add_dnspod_record_lib(domain_id, name, type, line, value, ttl)
                    tmp_dict["success"] = result[0]
                    tmp_dict["msg"] = result[1]
                    return json.dumps(tmp_dict)
                elif domain_info[2] == "local_bind":
                    result = add_dns_record_lib(domain_id, name, ttl, type, value, line)
                    tmp_dict["success"] = result[0]
                    print result[1]
                    tmp_dict["msg"] = result[1]
                    return json.dumps(tmp_dict)
            else:
                tmp_dict["msg"] = "no this domain rights"
                return json.dumps(tmp_dict)
        except Exception, e:
            print e
            tmp_dict["msg"] = "unknown error"
            return json.dumps(tmp_dict)