def start(): gl.set_v("serverlogger", LoggerUtils("niuniu")) gl.set_v("message-handle-queue", TestQueue()) gl.set_v("rebate-handle-queue", TestQueue()) gl.set_v("update_currency", TestQueue()) gl.set_v("game_details", TestQueue()) gl.set_v("play-handle", {}) uuid = StringUtils.randomStr(32) gl.set_v("uuid", uuid) gl.set_v("redis", RedisUtils()) gl.get_v("redis").startSubscribe([uuid], [message_handle]) gl.set_v("match_info", json.loads(config.get("niuniu", "match"))) threading.Thread(target=game_handle.handle, args=(game_handle(), gl.get_v("message-handle-queue"),), name='message-handle-queue').start() threading.Thread(target=rebate_handle.handle, args=(rebate_handle(), gl.get_v("rebate-handle-queue"),), name='rebate-handle-queue').start() threading.Thread(target=GameDetailsHandle.handle, args=(GameDetailsHandle(), gl.get_v("game_details"),), name='game_details').start() threading.Thread(target=UpdateCurrencyHandle.handle, args=(UpdateCurrencyHandle(), gl.get_v("update_currency"),), name='update_currency').start() Server.initCommand() Server.register()
def lambda_handler(event, context): """This is main lambda function""" bucketName = event['detail']['requestParameters']['bucketName'] subscriberAccountId = event['account'] sessionName = context.function_name cbcapMgmtRoleName = os.environ['mgmt_role_common_name'] s3 = get_aws_resource('s3', subscriberAccountId, cbcapMgmtRoleName, sessionName) if not encryption_enabled(bucketName, s3, subscriberAccountId): encryption_status = enable_encryption(bucketName, s3, subscriberAccountId) if encryption_status: logger.logDebug( f'Lambda {sessionName} executed and {bucketName} in {subscriberAccountId} successfully encrypted' ) else: logger.logError(f'Lambda Execution Failed.')
def get_aws_resource(resourceType, accountId, roleName, sessionName): """ This function Assumes role based on the resource""" stsClient = boto3.client('sts') try: role = stsClient.assume_role( RoleArn=f'arn:aws:iam::{accountId}:role/{roleName}', RoleSessionName=sessionName) accessKey = role['Credentials']['AccessKeyId'] secretKey = role['Credentials']['SecretAccessKey'] sessionToken = role['Credentials']['SessionToken'] return boto3.client(resourceType, aws_access_key_id=accessKey, aws_secret_access_key=secretKey, aws_session_token=sessionToken) except Exception as error: logger.logError( f'There is no proper permission to assume role in subscriber Account: {accountId}' ) exit()
def start(): try: gl.set_v("serverlogger", LoggerUtils("robot")) gl.set_v("redis", RedisUtils()) accounts = [] for i in range(0, 20): accounts.append("138000" + StringUtils.randomNum(4)) for a in accounts: threading.Thread(target=Client.execute, args=(Client(a, 7), ), name='robot').start() except: print traceback.print_exc() os._exit(0)
def enable_encryption(bucketName, s3, subscriberAccountId): """ This function enables the encryption on bucket """ try: s3.put_bucket_encryption( Bucket=bucketName, ServerSideEncryptionConfiguration={ 'Rules': [ { 'ApplyServerSideEncryptionByDefault': { 'SSEAlgorithm': 'AES256' } }, ] }) logger.logInfo(f'Encrypted successfully and sent mail') message = f'{bucketName} in account number: {subscriberAccountId} successfully encrypted.' notify_email(toEmail, fromEmail, message) return True except botocore.exceptions.ClientError as error: message = f'Bucket {bucketName} in {subscriberAccountId} is not encrypted successfully due to following \n {error}' logger.logError( f'Bucket {bucketName} in {subscriberAccountId} is not encrypted successfully due to following \n {error}' ) notify_email(toEmail, fromEmail, message)
def start(): gl.set_v("serverlogger", LoggerUtils("coordinate")) gl.set_v("from-gateway-queue", TestQueue()) gl.set_v("from-game-queue", TestQueue()) gl.set_v("games", []) gl.set_v("redis", RedisUtils()) gl.get_v("redis").startSubscribe( ["gateway-coordinate", "game-coordinate"], [from_gateway_handle, from_game_handle]) threading.Thread(target=gateway_handle.handle, args=( gateway_handle(), gl.get_v("from-gateway-queue"), ), name='from-gateway-queue').start() threading.Thread(target=game_handle.handle, args=( game_handle(), gl.get_v("from-game-queue"), ), name='from-game-queue').start() server.start_server()
def start(): gl.set_v("serverlogger", LoggerUtils("wuziqi")) gl.set_v("message-handle-queue", TestQueue()) gl.set_v("update_currency", TestQueue()) gl.set_v("game_details", TestQueue()) uuid = StringUtils.randomStr(32) gl.set_v("uuid", uuid) gl.set_v("redis", RedisUtils()) gl.get_v("redis").startSubscribe([uuid], [message_handle]) threading.Thread(target=game_handle.handle, args=(game_handle(), gl.get_v("message-handle-queue"),), name='message-handle-queue').start() threading.Thread(target=GameDetailsHandle.handle, args=(GameDetailsHandle(), gl.get_v("game_details"),), name='game_details').start() threading.Thread(target=UpdateCurrencyHandle.handle, args=(UpdateCurrencyHandle(), gl.get_v("update_currency"),), name='update_currency').start() Server.initCommand() Server.register()
def encryption_enabled(bucketName, s3, subscriberAccountId): """This function will return whether the Bucket is encrypted or not.""" try: s3.get_bucket_encryption(Bucket=bucketName) logger.logInfo( f'S3 bucket: {bucketName} is already encrypted in Account number:{subscriberAccountId}' ) return True except botocore.exceptions.ClientError as error: if 'ServerSideEncryptionConfigurationNotFoundError' in str(error): return False else: logger.logError( f'Bucket {bucketName} in {subscriberAccountId} not encrypted due to following error: \n {error}' ) message = f'S3 Bucket {bucketName} in {subscriberAccountId} not encrypted due to following error: \n {error}' logger.logDebug(f'sent error email') notify_email(toEmail, fromEmail, message) return True
#!/usr/bin/python # coding=utf-8 import Cookie import os import traceback import core.globalvar as gl from core import config config.init("./conf/pyg.conf") gl.init() from data.database import data_withdrawal from utils.redis_utils import RedisUtils from utils.logger_utils import LoggerUtils logger = LoggerUtils('customer_service.index').logger result = '<script>window.setTimeout(\"location.href = \'/customer_service/error\'\", 0);</script>\n' try: redis = RedisUtils() if 'HTTP_COOKIE' in os.environ: cookie_string = os.environ.get('HTTP_COOKIE') logger.info('session:' + cookie_string) if cookie_string != '': c = Cookie.SimpleCookie() c.load(cookie_string) if 'session' in c: sessionid = c['session'].value if redis.exists(sessionid): withdrawal_count = data_withdrawal.query_withdrawal_count_by_state( ) stateall = 0
#!/usr/bin/python # coding=utf-8 import traceback import core.globalvar as gl from core import config config.init("./conf/pyg.conf") gl.init() from utils.logger_utils import LoggerUtils logger = LoggerUtils('customer_service.login').logger result = '<script>window.setTimeout(\"location.href = \'/customer_service/error\'\", 0);</script>\n' try: result = ''' <!DOCTYPE html> <html> <head> <title>酒店管理系统</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Fonts --> <link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:300,400' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Lato:300,400,700,900' rel='stylesheet' type='text/css'> <!-- CSS Libs --> <link rel="stylesheet" type="text/css" href="/resources/lib/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="/resources/lib/css/font-awesome.min.css"> <link rel="stylesheet" type="text/css" href="/resources/lib/css/animate.min.css"> <link rel="stylesheet" type="text/css" href="/resources/lib/css/bootstrap-switch.min.css"> <link rel="stylesheet" type="text/css" href="/resources/lib/css/checkbox3.min.css">
import Cookie import cgi import os import traceback import core.globalvar as gl from core import config config.init("./conf/pyg.conf") gl.init() from data.database import data_withdrawal from utils.redis_utils import RedisUtils from utils.logger_utils import LoggerUtils logger = LoggerUtils('customer_service.do_withdrawal_deal').logger result = '3' try: redis = RedisUtils() if 'HTTP_COOKIE' in os.environ: cookie_string = os.environ.get('HTTP_COOKIE') logger.info('session:' + cookie_string) if cookie_string != '': c = Cookie.SimpleCookie() c.load(cookie_string) if 'session' in c: sessionid = c['session'].value if redis.exists(sessionid): form = cgi.FieldStorage() if 'id' in form: id = int(form.getvalue('id'))
def log_message(self, format, *args): logger = LoggerUtils('access').logger logger.info( "%s - - [%s] %s\n" % (self.client_address[0], self.log_date_time_string(), format % args))