diff --git a/shadowsocks/dbtransfer.py b/shadowsocks/dbtransfer.py index 569922f..aaf91ae 100644 --- a/shadowsocks/dbtransfer.py +++ b/shadowsocks/dbtransfer.py @@ -74,14 +74,14 @@ def push_db_all_user(self): dt_transfer = self.get_servers_transfer() if config.PANEL_VERSION == 'V2': - query_head = 'UPDATE user' + query_head = 'UPDATE `user`' query_sub_when = '' query_sub_when2 = '' query_sub_in = None last_time = time.time() for id in dt_transfer.keys(): - query_sub_when += ' WHEN %s THEN u+%s' % (id, 0) # all in d - query_sub_when2 += ' WHEN %s THEN d+%s' % (id, dt_transfer[id]) + query_sub_when += ' WHEN %s THEN `u`+%s' % (id, 0) # all in d + query_sub_when2 += ' WHEN %s THEN `d`+%s' % (id, dt_transfer[id]) if query_sub_in is not None: query_sub_in += ',%s' % id else: @@ -106,7 +106,7 @@ def push_db_all_user(self): if config.PANEL_VERSION == 'V3': i = 0 for id in dt_transfer.keys(): - string = ' where port = %s' % id + string = ' WHERE `port` = %s' % id conn = cymysql.connect(host=config.MYSQL_HOST, port=config.MYSQL_PORT, user=config.MYSQL_USER, passwd=config.MYSQL_PASS, db=config.MYSQL_DB, charset='utf8') cur = conn.cursor() @@ -118,7 +118,7 @@ def push_db_all_user(self): cur.close() conn.close() if config.SS_VERBOSE: - logging.info('port:%s ----> id:%s'%(id, rows[0][0])) + logging.info('port:%s ----> id:%s' % (id, rows[0][0])) tran = str(dt_transfer[id]) data = {'d': tran, 'node_id': config.NODE_ID, 'u': '0'} url = config.API_URL + '/users/' + str(rows[0][0]) + '/traffic?key=' + config.API_PASS @@ -127,9 +127,10 @@ def push_db_all_user(self): req = urllib2.Request(url, data) response = urllib2.urlopen(req) the_page = response.read() - logging.info('%s - %s - %s' % (url, data, the_page)) - i = i + 1 - #online user count + if config.SS_VERBOSE: + logging.info('%s - %s - %s' % (url, data, the_page)) + i += 1 + # online user count data = {'count': i} url = config.API_URL + '/nodes/' + config.NODE_ID + '/online_count?key=' + config.API_PASS data = urllib.urlencode(data) @@ -139,7 +140,7 @@ def push_db_all_user(self): the_page = response.read() logging.info('%s - %s - %s' % (url, data, the_page)) - #load info + # load info url = config.API_URL + '/nodes/' + config.NODE_ID + '/info?key=' + config.API_PASS f = open("/proc/loadavg") load = f.read().split() @@ -155,9 +156,11 @@ def push_db_all_user(self): req = urllib2.Request(url, data) response = urllib2.urlopen(req) the_page = response.read() - logging.info('%s - %s - %s' % (url, data, the_page)) + if config.SS_VERBOSE: + logging.info('%s - %s - %s' % (url, data, the_page)) else: - logging.warn('Not support panel version %s' % (config.PANEL_VERSION)) + if config.SS_VERBOSE: + logging.warn('Not support panel version: %s' % config.PANEL_VERSION) return @@ -185,7 +188,7 @@ def del_server_out_of_bound_safe(rows): 'db stop server at port [%d] reason: password changed' % row[0]) DbTransfer.send_command( 'remove: {"server_port":%d}' % row[0]) - else : + else: if not config.CUSTOM_METHOD: row[7] = config.SS_METHOD if server['method'] != row[7] : @@ -212,8 +215,8 @@ def thread_db(): rows = DbTransfer.pull_db_all_user() DbTransfer.del_server_out_of_bound_safe(rows) except Exception as e: - import traceback if config.SS_VERBOSE: + import traceback traceback.print_exc() logging.error('db thread except:%s' % e) finally: diff --git a/shadowsocks/servers.py b/shadowsocks/servers.py index 67aa34a..77a03d2 100755 --- a/shadowsocks/servers.py +++ b/shadowsocks/servers.py @@ -51,7 +51,8 @@ def main(): 'forbidden_ip': config.SS_FORBIDDEN_IP, 'banned_ports': config.SS_BAN_PORTS } - logging.info('\nMulti-User Shadowsocks Server Starting...') + logging.info('-----------------------------------------') + logging.info('Multi-User Shadowsocks Server Starting...') logging.info('Current Server Version: %s' % subprocess.check_output(["git", "describe"])) thread.start_new_thread(manager.run, (configer,)) time.sleep(1)