def soardownload(): arg = request.values.to_dict() if 'data' not in arg or 'key' not in arg: return json.dumps({"result": 'data or key is None', "status": False}) try: args = json.loads(decrypt(arg['data'], arg['key'])) except Exception as e: return json.dumps({"result": str(e), "status": False}) if DEBUG: print(args) check = soar_args_check(args) if check: return check result = soar_result(args) map = json.loads(result) resp = make_response(map['result']) # 设置时间戳 nowTime = time.time() timeArray = time.localtime(nowTime) otherStyleTime = time.strftime("%Y%m%d%H%M%S", timeArray) # 后缀名 suffixMap = {'html': 'html', 'json': 'json', 'markdown': 'md'} suffix = 'html' # 设置 http 头 resp.headers['Content-Type'] = 'application/force-download' if 'report-type' in args and args['report-type'] in suffixMap: suffix = suffixMap[args['report-type']] resp.headers['Content-Disposition'] = 'filename=soar_%s.%s' % ( otherStyleTime, suffix) return resp
def testconnect(): arg = request.json if 'data' not in arg or 'key' not in arg: return json.dumps({ "result": 'data or key is None', "status": False }) try: dsn = json.loads(decrypt(arg['data'],arg['key']))['dsn'] except Exception as e: return json.dumps({ "result": str(e), "status": False }) try: res = parse_dsn(dsn) pymysql.connect( host = res['host'], port = int(res['port']), user = res['user'], passwd = res['pwd'], db = res['db'], ) status = True result = '连接成功' except Exception as e: status = False result = str(e) return json.dumps({'result':result, 'status':status})
def soar(): arg = request.json if 'data' not in arg or 'key' not in arg: return json.dumps({"result": 'data or key is None', "status": False}) try: args = json.loads(decrypt(arg['data'], arg['key'])) except Exception as e: return json.dumps({"result": str(e), "status": False}) if DEBUG: print(args) check = soar_args_check(args) if check: return check result = soar_result(args) return result