コード例 #1
0
ファイル: dns-server.py プロジェクト: izogain/playground21
def cmd_host_update():

    # Validate JSON body w/ API params
    try:
        body = request.data.decode('utf-8')
        in_obj = json.loads(body)
    except:
        return http400("JSON Decode failed")

    # Validate JSON object basics
    try:
        if (not 'name' in in_obj or not 'domain' in in_obj
                or not 'hosts' in in_obj):
            return http400("Missing name/hosts")

        name = in_obj['name']
        domain = in_obj['domain']
        if not valid_name(name):
            return http400("Invalid name")
        if not db.valid_domain(domain):
            return http404("Domain not found")
    except:
        return http400("JSON validation exception")

    # Validate and collect host records for updating
    host_records = parse_hosts(name, domain, in_obj)
    if isinstance(host_records, str):
        return http400(host_records)

    # Verify host exists, and is not expired
    try:
        hostinfo = db.get_host(name, domain)
        if hostinfo is None:
            return http404("Unknown name")
    except:
        return http500("DB Exception")

    # Check permission to update
    pkh = hostinfo['pkh']
    if pkh is None:
        abort(403)
    sig_str = request.headers.get('X-Bitcoin-Sig')
    try:
        if not sig_str or not wallet.verify_bitcoin_message(
                body, sig_str, pkh):
            abort(403)
    except:
        abort(403)

    # Add to database.  Rely on db to filter out dups.
    try:
        if not nsupdate_exec(name, domain, host_records):
            http500("nsupdate failure")
        db.update_records(name, domain, host_records)
    except:
        return http400("DB Exception")

    return httpjson(True)
コード例 #2
0
ファイル: dns-server.py プロジェクト: nivertech/playground21
def cmd_host_update():

    # Validate JSON body w/ API params
    try:
        body = request.data.decode("utf-8")
        in_obj = json.loads(body)
    except:
        return http400("JSON Decode failed")

    # Validate JSON object basics
    try:
        if not "name" in in_obj or not "domain" in in_obj or not "hosts" in in_obj:
            return http400("Missing name/hosts")

        name = in_obj["name"]
        domain = in_obj["domain"]
        if not valid_name(name):
            return http400("Invalid name")
        if not db.valid_domain(domain):
            return http404("Domain not found")
    except:
        return http400("JSON validation exception")

    # Validate and collect host records for updating
    host_records = parse_hosts(name, domain, in_obj)
    if isinstance(host_records, str):
        return http400(host_records)

    # Verify host exists, and is not expired
    try:
        hostinfo = db.get_host(name, domain)
        if hostinfo is None:
            return http404("Unknown name")
    except:
        return http500("DB Exception")

    # Check permission to update
    pkh = hostinfo["pkh"]
    if pkh is None:
        abort(403)
    sig_str = request.headers.get("X-Bitcoin-Sig")
    try:
        if not sig_str or not wallet.verify_bitcoin_message(body, sig_str, pkh):
            abort(403)
    except:
        abort(403)

    # Add to database.  Rely on db to filter out dups.
    try:
        if not nsupdate_exec(name, domain, host_records):
            http500("nsupdate failure")
        db.update_records(name, domain, host_records)
    except:
        return http400("DB Exception")

    return httpjson(True)
コード例 #3
0
ファイル: dns-server.py プロジェクト: izogain/playground21
def cmd_host_delete():

    # Validate JSON body w/ API params
    try:
        body = request.data.decode('utf-8')
        in_obj = json.loads(body)
    except:
        return http400("JSON Decode failed")

    # Validate JSON object basics
    try:
        if (not 'name' in in_obj or not 'domain' in in_obj
                or not 'pkh' in in_obj):
            return http400("Missing name/pkh")

        name = in_obj['name']
        domain = in_obj['domain']
        pkh = in_obj['pkh']
        if (not valid_name(name) or (len(pkh) < 10)):
            return http400("Invalid name")
        if not db.valid_domain(domain):
            return http404("Domain not found")
    except:
        return http400("JSON validation exception")

    # Verify host exists, and is not expired
    try:
        hostinfo = db.get_host(name, domain)
        if hostinfo is None:
            return http404("Unknown name")
    except:
        return http500("DB Exception - get host")

    # Check permission to update
    if (hostinfo['pkh'] is None) or (pkh != hostinfo['pkh']):
        abort(403)
    sig_str = request.headers.get('X-Bitcoin-Sig')
    try:
        if not sig_str or not wallet.verify_bitcoin_message(
                body, sig_str, pkh):
            abort(403)
    except:
        abort(403)

    # Remove from database.  Rely on db to filter out dups.
    try:
        if not nsupdate_exec(name, domain, []):
            http500("nsupdate failure")
        db.delete_host(name, domain)
    except:
        return http400("DB Exception - delete host")

    return httpjson(True)
コード例 #4
0
ファイル: dns-server.py プロジェクト: nivertech/playground21
def cmd_host_delete():

    # Validate JSON body w/ API params
    try:
        body = request.data.decode("utf-8")
        in_obj = json.loads(body)
    except:
        return http400("JSON Decode failed")

    # Validate JSON object basics
    try:
        if not "name" in in_obj or not "domain" in in_obj or not "pkh" in in_obj:
            return http400("Missing name/pkh")

        name = in_obj["name"]
        domain = in_obj["domain"]
        pkh = in_obj["pkh"]
        if not valid_name(name) or (len(pkh) < 10):
            return http400("Invalid name")
        if not db.valid_domain(domain):
            return http404("Domain not found")
    except:
        return http400("JSON validation exception")

    # Verify host exists, and is not expired
    try:
        hostinfo = db.get_host(name, domain)
        if hostinfo is None:
            return http404("Unknown name")
    except:
        return http500("DB Exception - get host")

    # Check permission to update
    if (hostinfo["pkh"] is None) or (pkh != hostinfo["pkh"]):
        abort(403)
    sig_str = request.headers.get("X-Bitcoin-Sig")
    try:
        if not sig_str or not wallet.verify_bitcoin_message(body, sig_str, pkh):
            abort(403)
    except:
        abort(403)

    # Remove from database.  Rely on db to filter out dups.
    try:
        if not nsupdate_exec(name, domain, []):
            http500("nsupdate failure")
        db.delete_host(name, domain)
    except:
        return http400("DB Exception - delete host")

    return httpjson(True)
コード例 #5
0
ファイル: dns-server.py プロジェクト: izogain/playground21
def cmd_host_register():

    # Validate JSON body w/ API params
    try:
        body = request.data.decode('utf-8')
        in_obj = json.loads(body)
    except:
        return http400("JSON Decode failed")

    try:
        if (not 'name' in in_obj or not 'domain' in in_obj):
            return http400("Missing name/domain")

        name = in_obj['name']
        domain = in_obj['domain']
        pkh = None
        days = 1
        if 'pkh' in in_obj:
            pkh = in_obj['pkh']
        if 'days' in in_obj:
            days = int(in_obj['days'])

        if not valid_name(name) or days < 1 or days > 365:
            return http400("Invalid name/days")
        if not db.valid_domain(domain):
            return http404("Domain not found")
        if pkh:
            base58.b58decode_check(pkh)
            if (len(pkh) < 20) or (len(pkh) > 40):
                return http400("Invalid pkh")
    except:
        return http400("JSON validation exception")

    # Check against reserved host name list
    if reserved_name(name):
        return http400("Reserved name.  Name not available for registration.")

    # Validate and collect host records for updating
    host_records = parse_hosts(name, domain, in_obj)
    if isinstance(host_records, str):
        return http400(host_records)

    return store_host(name, domain, days, pkh, host_records)
コード例 #6
0
ファイル: dns-server.py プロジェクト: nivertech/playground21
def cmd_host_register():

    # Validate JSON body w/ API params
    try:
        body = request.data.decode("utf-8")
        in_obj = json.loads(body)
    except:
        return http400("JSON Decode failed")

    try:
        if not "name" in in_obj or not "domain" in in_obj:
            return http400("Missing name/domain")

        name = in_obj["name"]
        domain = in_obj["domain"]
        pkh = None
        days = 1
        if "pkh" in in_obj:
            pkh = in_obj["pkh"]
        if "days" in in_obj:
            days = int(in_obj["days"])

        if not valid_name(name) or days < 1 or days > 365:
            return http400("Invalid name/days")
        if not db.valid_domain(domain):
            return http404("Domain not found")
        if pkh:
            base58.b58decode_check(pkh)
            if (len(pkh) < 20) or (len(pkh) > 40):
                return http400("Invalid pkh")
    except:
        return http400("JSON validation exception")

    # Check against reserved host name list
    if reserved_name(name):
        return http400("Reserved name.  Name not available for registration.")

    # Validate and collect host records for updating
    host_records = parse_hosts(name, domain, in_obj)
    if isinstance(host_records, str):
        return http400(host_records)

    return store_host(name, domain, days, pkh, host_records)
コード例 #7
0
ファイル: dns-server.py プロジェクト: izogain/playground21
def cmd_host_simpleRegister():
    try:
        name = request.args.get('name')
        domain = request.args.get('domain')
        days = int(request.args.get('days'))
        ip = request.args.get('ip')

        if not valid_name(name) or days < 1 or days > 365:
            return http400("Invalid name/days")
        if not db.valid_domain(domain):
            return http404("Domain not found")
    except:
        return http400("Invalid name / domain / days supplied")

    try:
        address = ipaddress.ip_address(ip)
    except:
        return http400("Invalid IP address supplied")

    if isinstance(address, ipaddress.IPv4Address):
        rec_type = 'A'
    elif isinstance(address, ipaddress.IPv6Address):
        rec_type = 'AAAA'
    else:
        return http500("bonkers")

    # Check against reserved host name list
    if reserved_name(name):
        return http400("Reserved name.  Name not available for registration.")

    # Validate and collect host records
    host_records = []
    host_rec = (name, domain, rec_type, str(address), 1000)
    host_records.append(host_rec)

    return store_host(name, domain, days, None, host_records)
コード例 #8
0
ファイル: dns-server.py プロジェクト: nivertech/playground21
def cmd_host_simpleRegister():
    try:
        name = request.args.get("name")
        domain = request.args.get("domain")
        days = int(request.args.get("days"))
        ip = request.args.get("ip")

        if not valid_name(name) or days < 1 or days > 365:
            return http400("Invalid name/days")
        if not db.valid_domain(domain):
            return http404("Domain not found")
    except:
        return http400("Invalid name / domain / days supplied")

    try:
        address = ipaddress.ip_address(ip)
    except:
        return http400("Invalid IP address supplied")

    if isinstance(address, ipaddress.IPv4Address):
        rec_type = "A"
    elif isinstance(address, ipaddress.IPv6Address):
        rec_type = "AAAA"
    else:
        return http500("bonkers")

    # Check against reserved host name list
    if reserved_name(name):
        return http400("Reserved name.  Name not available for registration.")

    # Validate and collect host records
    host_records = []
    host_rec = (name, domain, rec_type, str(address), 1000)
    host_records.append(host_rec)

    return store_host(name, domain, days, None, host_records)