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

Commit

Permalink
support sendya/shadowsocks-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Acris committed Apr 20, 2016
1 parent 974d0aa commit 405de9a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions shadowsocks/dbtransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ def get_servers_transfer():

def push_db_all_user(self):
dt_transfer = self.get_servers_transfer()
query_head = 'UPDATE user'
query_head = 'UPDATE member'
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 flow_up+%s' % (id, 0) # all in d
query_sub_when2 += ' WHEN %s THEN flow_down+%s' % (id, dt_transfer[id])
if query_sub_in is not None:
query_sub_in += ',%s' % id
else:
query_sub_in = '%s' % id
if query_sub_when == '':
return
query_sql = query_head + ' SET u = CASE port' + query_sub_when + \
' END, d = CASE port' + query_sub_when2 + \
' END, t = ' + str(int(last_time)) + \
query_sql = query_head + ' SET flow_up = CASE port' + query_sub_when + \
' END, flow_down = CASE port' + query_sub_when2 + \
' END, lastConnTime = ' + str(int(last_time)) + \
' WHERE port IN (%s)' % query_sub_in
# print query_sql
conn = cymysql.connect(host=config.MYSQL_HOST, port=config.MYSQL_PORT, user=config.MYSQL_USER,
Expand All @@ -90,7 +90,7 @@ def pull_db_all_user():
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()
cur.execute("SELECT port, u, d, transfer_enable, passwd, switch, enable FROM user")
cur.execute("SELECT port, flow_up, flow_down, transfer, sspwd, enable FROM member")
rows = []
for r in cur.fetchall():
rows.append(list(r))
Expand All @@ -103,7 +103,7 @@ def del_server_out_of_bound_safe(rows):
for row in rows:
server = json.loads(DbTransfer.get_instance().send_command('stat: {"server_port":%s}' % row[0]))
if server['stat'] != 'ko':
if row[5] == 0 or row[6] == 0:
if row[5] == 0:
#stop disable or switch off user
logging.info('db stop server at port [%s] reason: disable' % (row[0]))
DbTransfer.send_command('remove: {"server_port":%s}' % row[0])
Expand All @@ -116,7 +116,7 @@ def del_server_out_of_bound_safe(rows):
logging.info('db stop server at port [%s] reason: password changed' % (row[0]))
DbTransfer.send_command('remove: {"server_port":%s}' % row[0])
else:
if row[5] == 1 and row[6] == 1 and row[1] + row[2] < row[3]:
if row[5] == 1 and row[1] + row[2] < row[3]:
logging.info('db start server at port [%s] pass [%s]' % (row[0], row[4]))
DbTransfer.send_command('add: {"server_port": %s, "password":"%s"}'% (row[0], row[4]))
print('add: {"server_port": %s, "password":"%s"}'% (row[0], row[4]))
Expand Down

0 comments on commit 405de9a

Please sign in to comment.