Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fsgmhoward committed Jun 2, 2016
1 parent 1d5923d commit 3db01de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 16 additions & 13 deletions shadowsocks/dbtransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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


Expand Down Expand Up @@ -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] :
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion shadowsocks/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3db01de

Please sign in to comment.