def create_auth_cookie(response, login_data): # 进场获取缓存cookie中的信息 auth_token = request.cookies.get('auth_token') refresh_time = request.cookies.get( 'refresh_time') # refresh_time = 1482222171524 cookie_info = request.cookies.get('cookie_info') # 设置cookie过期时间点, time.time() + 60 表示一分钟后 outdate = time.time() + 60 * 60 * 24 * 30 # 记录登录态三天 _redis = Redis() # login 如果是登录操作,cookie中所有信息重新生成 if not is_none(login_data) and not is_none(login_data.get('user_id')): user_id = login_data.get('user_id') sso_code = "vJjPtawUC8" # 如果当前版本不设置单点登录,则使用固定随机码 if get_version() in SSO_VERSION: # 如果版本设置单点登录,随机生成10位随机数,当做单机唯一登录码,存在redis中方便对比 # 只要不清除登录态,单点登录则不会触发 sso_code = get_randoms(10) _redis.set_hset("app_sso_code", user_id, sso_code) # 产生新的refresh_time 和新的auth_token refresh_time = str(int(round(time.time() * 1000))) sign = get_hashlib(AUTH_COOKIE_KEY + user_id + refresh_time + sso_code) auth_token = aes_encrypt(sign) login_data['sso_code'] = sso_code cookie_info = aes_encrypt(json.dumps(login_data)) # not login 如果不是登录操作,并且cookie中auth_token和refresh_time存在 if not is_none(auth_token) and not is_none(refresh_time): now_time = int(round(time.time() * 1000)) differ_minuts = (now_time - int(refresh_time)) / (60 * 1000) if differ_minuts >= 30 and is_none(login_data): user_id = get_cookie_info().get('user_id') if not is_none(user_id): refresh_time = str(int(round(time.time() * 1000))) sso_code = _redis.get_hget("app_sso_code", user_id) # 获取单点登录码 sign = get_hashlib(AUTH_COOKIE_KEY + user_id + refresh_time + sso_code) auth_token = aes_encrypt(sign) if not is_none(auth_token) and not is_none(refresh_time) and not is_none( cookie_info): response.set_cookie('auth_token', value=auth_token, domain='.mofanghr.com', expires=outdate, secure=True, httponly=True, samesite='Lax') response.set_cookie('refresh_time', value=str(refresh_time), domain='.mofanghr.com', expires=outdate) response.set_cookie('cookie_info', value=cookie_info, domain='.mofanghr.com', expires=outdate) return response
def main(): from core import clap from core import common from core import main try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Compare two files and replace different bytes.") p.set_epilog("Further information and usage examples can be found " "inside the documentation file for this script.") # Required arguments p.add_avalue("-i", "--input-file", "source file where to read the data " "from", "input_file", None, True) p.add_avalue("-o", "--output-file", "destination file where to write " "data into", "output_file", None, True) # Optional arguments p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch(None, "--no-hashes", "do not use file hash comparison", "no_hash", True, False) p.add_switch(None, "--no-progress", "do not display the process " "percentage", "no_progress", True, False) p.add_switch("-q", "--quiet", "disable output", "quiet", True, False) p.add_switch("-s", "--simulate", "do not change the output file", "simulate", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(common.get_version()) sys.exit(0) args = p.parse_args() try: hashes = not args.no_hash progress = not args.no_progress verbose = not args.quiet byteweiser = main.ByteWeiser() byteweiser.compare_and_replace(args.input_file, args.output_file, args.buffer_size, args.simulate, verbose, progress, hashes) except Exception as e: p.error(e)
def main(): from core import clap from core import common try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Delete remaining temporary files of the Erfr " \ "components.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define optional arguments p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print common.get_version() sys.exit(0) try: print "Started cleaning up temporary files." max_tasks = int(common.get_max_tasks()) for task in range(1, max_tasks + 1): common.delete_temp_files(task) print "Finished cleaning up temporary files." except Exception as e: print "cancelled cleaning up temporary files." p.error(e)
def main(): from core import clap from core import common from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Extract a user-defined byte range from an existing " \ "into a new file.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-i", "--input-file", "input file path", "input_file", None, True) p.add_avalue("-l", "--length", "number of bytes to read", "length", None, True) p.add_avalue("-o", "--output-file", "output file path", "output_file", None, True) p.add_avalue("-s", "--offset", "position where to start reading", "offset", None, True) # Define optional arguments p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--overwrite", "overwrite existing file", "overwrite", True, False) p.add_switch("-r", "--remove", "remove the extracted data from the " \ "input file", "remove_bytes", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(common.get_version()) sys.exit(0) args = p.parse_args() remove_bytes = None force_remove = \ bool(int(common.global_config(["Extractor"], ["force_remove"], "0"))) if force_remove: remove_bytes = True else: remove_bytes = args.remove_bytes try: timestamp = dt.now() common.extract_bytes(args.input_file, args.output_file, args.offset, args.length, args.buffer_size, args.overwrite, remove_bytes) print("Elapsed time: %s" % (dt.now() - timestamp)) except Exception as e: p.error(e)