Exemplo n.º 1
0
def get_info():
    # API endpoint metadata - export list of services
    info_obj = [{
        "name":
        "dns/1",
        "website":
        "https://github.com/jgarzik/playground21/tree/master/dns",
        "pricing-type":
        "per-rpc",
        "pricing": [
            {
                "rpc": "domains",
                "per-req": 0,
            },
            {
                "rpc": "host.register",
                "per-day": int(USCENT / 50),
            },
            {
                "rpc": "simpleRegister",
                "per-day": int(USCENT / 50),
            },
            {
                "rpc": "records.update",
                "per-req": int(USCENT / 5),
            },
            {
                "rpc": "host.delete",
                "per-req": 0,
            },
        ]
    }]
    return httpjson(info_obj)
Exemplo n.º 2
0
def get_domains():
    try:
        domains = db.domains()
    except:
        abort(500)

    return httpjson(domains)
Exemplo n.º 3
0
def get_domains():
    try:
        domains = db.domains()
    except:
        abort(500)

    return httpjson(domains)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def store_host(name, domain, days, pkh, host_records):
    # Add to database.  Rely on db to filter out dups.
    try:
        db.add_host(name, domain, days, pkh)
        if len(host_records) > 0:
            if not nsupdate_exec(name, domain, host_records):
                http500("nsupdate failure")
            db.update_records(name, domain, host_records)
    except:
        return http400("Host addition rejected")

    return httpjson(True)
Exemplo n.º 8
0
def store_host(name, domain, days, pkh, host_records):
    # Add to database.  Rely on db to filter out dups.
    try:
        db.add_host(name, domain, days, pkh)
        if len(host_records) > 0:
            if not nsupdate_exec(name, domain, host_records):
                http500("nsupdate failure")
            db.update_records(name, domain, host_records)
    except:
        return http400("Host addition rejected")

    return httpjson(True)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
def get_info():
    # API endpoint metadata - export list of services
    info_obj = [
        {
            "name": "dns/1",
            "website": "https://github.com/jgarzik/playground21/tree/master/dns",
            "pricing-type": "per-rpc",
            "pricing": [
                {"rpc": "domains", "per-req": 0},
                {"rpc": "host.register", "per-day": int(USCENT / 50)},
                {"rpc": "simpleRegister", "per-day": int(USCENT / 50)},
                {"rpc": "records.update", "per-req": int(USCENT / 5)},
                {"rpc": "host.delete", "per-req": 0},
            ],
        }
    ]
    return httpjson(info_obj)