def requests(bin): try: bin = db.lookup_bin(bin) except KeyError: return _response({'error': "Inspector not found"}, 206) return _response([r.to_dict() for r in bin.requests])
def bin(name): if name in blocked_bin_names: return "Not found\n", 404 handle_automation_names(name) try: bin = db.lookup_bin(name) except KeyError: add_into_blocked_bin_names(name) return "Not found\n", 404 if request.query_string == 'inspect': if (bin.private and session.get(bin.name) != bin.secret_key ) and session['user_role'] != 'super_user': return "Private inspector\n", 403 update_recent_bins(name) return render_template('bin.html', bin=bin, base_url=request.scheme + '://' + request.host) elif request.query_string.startswith('redirect'): db.create_request(bin, request) if bin.private and session.get(bin.name) != bin.secret_key: return "Private inspector\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) # handel config here resp = make_response(bin.response_msg, bin.response_code) resp.headers['Provided-By'] = "https://www.payfort.com" time.sleep(bin.response_delay) return resp
def bin(name): block = ['listOfBlockedNames'] if name in block: return _response({'error': "Forbidden inspector due to block"}, 403) else: try: bin = db.lookup_bin(name) except KeyError: return _response({'error': "Inspector not found"}, 206) return _response(bin.to_dict())
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
def bin_config(): name = request.form['name'] try: db.lookup_bin(name) except KeyError: return "Not found\n", 404 org_bin = db.get_bin(name) org_private = org_bin.private org_requests = org_bin.requests org_color = org_bin.color org_secret_key = org_bin.secret_key updated_bin = db.update_bin(org_private, name, request.form['response_msg'], int(float(request.form['response_code'])), int(float(request.form['response_delay'])), org_requests, org_color, org_secret_key) return render_template('bin.html', bin=updated_bin, base_url=request.scheme + '://' + request.host)
def setResponseMsg(bin, response_code, response_delay, msg): try: db.lookup_bin(bin) except KeyError: msg = { 'msg_status': "failed", } resp = make_response(json.dumps(msg), 200) resp.headers['Content-Type'] = 'application/json' return resp org_bin = db.get_bin(bin) org_private = org_bin.private org_requests = org_bin.requests org_color = org_bin.color org_secret_key = org_bin.secret_key db.update_bin(org_private, bin, msg, int(float(response_code)), int(float(response_delay)), org_requests, org_color, org_secret_key) msg = { 'msg_status': "updated", } resp = make_response(json.dumps(msg), 200) resp.headers['Content-Type'] = 'application/json' return resp
def request_(bin, ref): try: bin = db.lookup_bin(bin) except KeyError: return _response({'error': "Inspector not found"}, 206) for req in bin.requests: if ref in req.body: json_body = req.body return _safe_json_response(json_body) elif req.form_data != [] and 'application/x-www-form-urlencoded' in req.content_type: if ref in req.raw: json_raw = req.raw return _safe_form_response(json_raw) else: for k in req.query_string: if ref in req.query_string[k]: json_query = req.query_string return _safe_query_response(json_query) return _response({'error': "Request not found"}, 206)
def request_(bin): try: bin = db.lookup_bin(bin) except KeyError: return _response({'error': "Inspector not found"}, 206) return _response([convert_to_json(req) for req in bin.requests])