From 3fd0fbf1d0206536a545012717e5d4a88de2e3ef Mon Sep 17 00:00:00 2001 From: BreakWa11 Date: Tue, 19 Jul 2016 15:26:17 +0800 Subject: [PATCH] mysql SSL connect mujson_mgr add obfs & protocol mapping --- apiconfig.py | 5 +++++ db_transfer.py | 33 +++++++++++++++++++++++++++------ mujson_mgr.py | 24 ++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/apiconfig.py b/apiconfig.py index b69c50e..6576e7e 100644 --- a/apiconfig.py +++ b/apiconfig.py @@ -15,6 +15,11 @@ MYSQL_PASS = 'ss' MYSQL_DB = 'shadowsocks' MYSQL_UPDATE_TIME = 60 +MYSQL_SSL_ENABLE = 0 +MYSQL_SSL_CA = '' +MYSQL_SSL_CERT = '' +MYSQL_SSL_KEY = '' + # API API_HOST = '127.0.0.1' API_PORT = 80 diff --git a/db_transfer.py b/db_transfer.py index ad531ed..743f88e 100644 --- a/db_transfer.py +++ b/db_transfer.py @@ -54,8 +54,15 @@ class DbTransfer(object): ' END, d = CASE port' + query_sub_when2 + \ ' END, t = ' + str(int(last_time)) + \ ' WHERE port IN (%s)' % query_sub_in - conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, user=get_config().MYSQL_USER, - passwd=get_config().MYSQL_PASS, db=get_config().MYSQL_DB, charset='utf8') + if get_config().MYSQL_SSL_ENABLE == 1: + conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, + user=get_config().MYSQL_USER, passwd=get_config().MYSQL_PASS, + db=get_config().MYSQL_DB, charset='utf8', + ssl={'ca':get_config().MYSQL_SSL_CA,'cert':get_config().MYSQL_SSL_CERT,'key':get_config().MYSQL_SSL_KEY}) + else: + conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, + user=get_config().MYSQL_USER, passwd=get_config().MYSQL_PASS, + db=get_config().MYSQL_DB, charset='utf8') cur = conn.cursor() cur.execute(query_sql) cur.close() @@ -97,8 +104,15 @@ class DbTransfer(object): keys = switchrule.getKeys() except Exception as e: keys = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable' ] - conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, user=get_config().MYSQL_USER, - passwd=get_config().MYSQL_PASS, db=get_config().MYSQL_DB, charset='utf8') + if get_config().MYSQL_SSL_ENABLE == 1: + conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, + user=get_config().MYSQL_USER, passwd=get_config().MYSQL_PASS, + db=get_config().MYSQL_DB, charset='utf8', + ssl={'ca':get_config().MYSQL_SSL_CA,'cert':get_config().MYSQL_SSL_CERT,'key':get_config().MYSQL_SSL_KEY}) + else: + conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, + user=get_config().MYSQL_USER, passwd=get_config().MYSQL_PASS, + db=get_config().MYSQL_DB, charset='utf8') cur = conn.cursor() cur.execute("SELECT " + ','.join(keys) + " FROM user") rows = [] @@ -262,8 +276,15 @@ class Dbv3Transfer(DbTransfer): alive_user_count = 0 bandwidth_thistime = 0 - conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, user=get_config().MYSQL_USER, - passwd=get_config().MYSQL_PASS, db=get_config().MYSQL_DB, charset='utf8') + if get_config().MYSQL_SSL_ENABLE == 1: + conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, + user=get_config().MYSQL_USER, passwd=get_config().MYSQL_PASS, + db=get_config().MYSQL_DB, charset='utf8', + ssl={'ca':get_config().MYSQL_SSL_CA,'cert':get_config().MYSQL_SSL_CERT,'key':get_config().MYSQL_SSL_KEY}) + else: + conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, + user=get_config().MYSQL_USER, passwd=get_config().MYSQL_PASS, + db=get_config().MYSQL_DB, charset='utf8') conn.autocommit(True) for id in dt_transfer.keys(): diff --git a/mujson_mgr.py b/mujson_mgr.py index 268961c..a9cf0f5 100644 --- a/mujson_mgr.py +++ b/mujson_mgr.py @@ -203,6 +203,20 @@ def main(): longopts = ['help'] action = None user = {} + fast_set_obfs = {'0': 'plain', + '1': 'http_simple_compatible', + '-1': 'http_simple', + '2': 'http_post_compatible', + '-2': 'http_post', + '3': 'tls1.2_ticket_auth_compatible', + '-3': 'tls1.2_ticket_auth'} + fast_set_protocol = {'0': 'origin', + '1': 'verify_sha1_compatible', + '-1': 'verify_sha1', + '2': 'auth_sha1_compatible', + '-2': 'auth_sha1', + '3': 'auth_sha1_v2_compatible', + '-3': 'auth_sha1_v2'} try: optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts) for key, value in optlist: @@ -223,9 +237,15 @@ def main(): elif key == '-k': user['passwd'] = value elif key == '-o': - user['obfs'] = value + if value in fast_set_obfs: + user['obfs'] = fast_set_obfs[value] + else: + user['obfs'] = value elif key == '-O': - user['protocol'] = value + if value in fast_set_protocol: + user['protocol'] = fast_set_protocol[value] + else: + user['protocol'] = value elif key == '-g': user['obfs_param'] = value elif key == '-G':