Exemplo n.º 1
0
def create_static_bin():
    print("before_first_request")
    try:
        db.lookup_bin("callback")
        print("callback bin exists")
    except KeyError:
        db.create_bin(False, "callback")
        print("created callback bin")
        update_recent_bins("callback")
        print("updated recent bins")
    finally:
        sys.stdout.flush()
Exemplo n.º 2
0
def requests(bin):
    try:
        bin = db.lookup_bin(bin)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)

    return _response([r.to_dict() for r in bin.requests])
Exemplo n.º 3
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)

    return _response(bin.to_dict())
Exemplo n.º 4
0
def expand_recent_bins():
    if 'recent' not in session:
        session['recent'] = []
    recent = []
    try:
        all_keys = db.get_all_keys()
        print "db.get_all_keys() is working! :)"
        print str(all_keys)
    except Exception:
        print "stops at db.get_all_keys() in expand_recent_bins()"
    else:
        print "What??? I'm in else block???"

    # for name in session['recent']:
    print "looping 'all_keys'..."
    for name in all_keys:
        print "................................................................."
        try:
            gotBin = db.lookup_bin(name)
            print "[view.py] gotBin: " + str(gotBin)
            recent.append(gotBin)
            print "[view.py] recent:" + str(recent)
        except KeyError:
            print "[view.py] Oh no, it's a key error in db.lookup_bin(name)"
            session['recent'].remove(name)
            session.modified = True

    print "[view.py] recent will be returned as:" + str(recent)
    return recent
Exemplo n.º 5
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)

    return _response(bin.to_dict())
Exemplo n.º 6
0
def requests(bin):
    try:
        bin = db.lookup_bin(bin)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)

    return _response([r.to_dict() for r in bin.requests])
Exemplo n.º 7
0
def bin(name):
    if request.query_string == 'inspect':
        try:
            bin = db.lookup_bin(name)
        except KeyError:
            return "Not found\n", 404

        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403

        update_recent_bins(name)
        return render_template('bin.html',
                               responseText=bin.responseText,
                               url=bin.url,
                               bin=bin,
                               base_url=request.scheme + '://' + request.host,
                               max_requests=config.MAX_REQUESTS,
                               bin_ttl=config.BIN_TTL // 3600,
                               bin_max_size=config.MAX_RAW_SIZE // 1048576)
    else:
        try:
            bin = db.lookup_bin_by_url(name)
        except KeyError:
            return "Not found\n", 404
        db.create_request(bin, request)
        resp = make_response(bin.responseText)
        resp.headers['Content-Type'] = bin.responseMIME
        return resp
Exemplo n.º 8
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404

    db.create_request(bin, request)
    resp = make_response("ok\n")
    resp.headers['Sponsored-By'] = "https://www.runscope.com"
    return resp
Exemplo n.º 9
0
def request_(bin, name):
    try:
        bin = db.lookup_bin(bin)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)

    for req in bin.requests:
        if req.id == name:
            return _response(req.to_dict())

    return _response({'error': "Request not found"}, 404)
Exemplo n.º 10
0
def config(bin):
    try:
        bin = db.lookup_bin(bin)
    except KeyError:
        return _response({'result': 1, 'error': "Bin not found"}, 404)

    db.set_response_text(bin, request.form.get('responseText',
                                               bin.responseText))
    db.set_bin_url(bin, request.form.get('url', bin.name))
    db.set_response_mime(bin, request.form.get('mimetype', bin.responseMIME))
    return _response({'result': 0}, 200)
Exemplo n.º 11
0
def request_(bin, name):
    try:
        bin = db.lookup_bin(bin)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)

    for req in bin.requests:
        if req.id == name:
            return _response(req.to_dict())

    return _response({'error': "Request not found"}, 404)
Exemplo n.º 12
0
def expand_recent_bins():
    if 'recent' not in session:
        session['recent'] = []
    recent = []
    for name in session['recent']:
        try:
            recent.append(db.lookup_bin(name))
        except KeyError:
            session['recent'].remove(name)
            session.modified = True
    return recent
Exemplo n.º 13
0
def expand_recent_bins():
    if 'recent' not in session:
        session['recent'] = []
    recent = []
    for name in session['recent']:
        try:
            recent.append(db.lookup_bin(name))
        except KeyError:
            session['recent'].remove(name)
            session.modified = True
    return recent
Exemplo n.º 14
0
def requests(name):
    import os
    file_name = name
    FILE = os.path.join(app.config['UPLOAD_FOLDER'], file_name)
    f = open(FILE, 'r')
    try:
        bin = db.lookup_bin(name=name)
    except KeyError:
        print' key already there'
        bin = db.create_bin(name=name)
    db.create_request(bin, request)
    return Response(f.read(), content_type='application/xml')
Exemplo n.º 15
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html', bin=bin, host=request.host)
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        return resp
Exemplo n.º 16
0
def requests(bin):
    try:
        bin = db.lookup_bin(bin)
    except KeyError:
        return _response({'error': "Bin not found"}, 404)
    inspect_query = request.args.get('inspect')
    if inspect_query == 'headers':
        return _response([r.headers for r in bin.requests])
    elif inspect_query == 'form':
        return _response([dict(r.form_data) for r in bin.requests])
    elif inspect_query == 'query':
        return _response([r.query_string for r in bin.requests])
    elif inspect_query in ('raw', 'body'):
        return _response([r.raw for r in bin.requests])
    else:
        return _response([r.to_dict() for r in bin.requests])
Exemplo n.º 17
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404

    if bin.private and session.get(bin.name) != bin.secret_key:
        return "Private bin\n", 403
    update_recent_bins(name)
    scheme=request.headers['X-Forwarded-Proto']
    if scheme == None:
      scheme='http'
    return render_template('bin.html',
        bin=bin,
        scheme=scheme,
        host=request.headers['Host'])
Exemplo n.º 18
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
                               bin=bin,
                               base_url=request.scheme + '://' + request.host)
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        resp.headers['Sponsored-By'] = "https://www.runscope.com"
        return resp
Exemplo n.º 19
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
            bin=bin,
            base_url=request.scheme+'://'+request.host)
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        resp.headers['Sponsored-By'] = "https://www.runscope.com"
        return resp
Exemplo n.º 20
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        # just make the bin if it doesn't exist - in the spirit of mongodb :)
        bin = db.create_bin(name, private=False)
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
                               bin=bin,
                               base_url=request.scheme + '://' + request.host)
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        resp.headers['Sponsored-By'] = "https://www.runscope.com"
        return resp
Exemplo n.º 21
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        # Generate an externally valid URL
        exturl = url_for('.bin', name=name, _external=True, _scheme=app.config.PREFERRED_URL_SCHEME)
        return render_template('bin.html',
                               bin=bin,
                               exturl=exturl
        )
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        return resp
Exemplo n.º 22
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
                               bin=bin,
                               base_url=request.scheme + '://' + request.host)
    else:
        db.create_request(bin, request)
        resp.headers['Content-Type'] = 'application/json'
        resp.headers['Access-Control-Allow-Origin'] = '*'
        resp.headers['Sponsored-By'] = "https://www.runscope.com"
        resp = make_response(json.dumps(request))
        return resp
Exemplo n.º 23
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
            bin=bin,
            base_url=request.scheme+'://'+request.host)
    else:
        db.create_request(bin, request)
        #resp = make_response("ok\n")
        if 'Cf-Connecting-Ip' in request.headers:
            resp = make_response("ip:" + request.headers['Cf-Connecting-Ip'] + "\n")
        else:
            resp = make_response("ip:" + request.remote_addr + "\n")
        resp.headers['Sponsored-By'] = "http://freighttrust.net"
        return resp
Exemplo n.º 24
0
def bin(name):
    try:
        bin = db.lookup_bin(name)
    except KeyError:
        return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
                               bin=bin,
                               base_url=request.scheme + '://' + request.host)
    elif request.query_string == 'results':
        obj = [r.to_dict() for r in bin.requests]
        resp = make_response(json.dumps(obj), 200)
        resp.headers['Content-Type'] = 'application/json'
        resp.headers['Access-Control-Allow-Origin'] = '*'
        return resp
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        return resp
Exemplo n.º 25
0
def bin_redirect(name, redirect_to):
    regexMerchant = re.compile(r'^m([a-zA-Z0-9]{19})')

    try:
        bin = db.lookup_bin(name)
    except KeyError:
        if regexMerchant.match(name):
            bin = db.create_bin_with_name("", name)
        else:
            return "Not found\n", 404
    if request.query_string == 'inspect':
        if bin.private and session.get(bin.name) != bin.secret_key:
            return "Private bin\n", 403
        update_recent_bins(name)
        return render_template('bin.html',
                               bin=bin,
                               base_url=request.scheme + '://' + request.host)
    else:
        db.create_request(bin, request)
        resp = make_response("ok\n")
        resp.headers['Sponsored-By'] = "https://www.runscope.com"
        return redirect(redirect_to, code=302, Response=None)