'obfs', 'protocol', 'method' leave blank that use the config of config.json
This commit is contained in:
parent
825aece219
commit
8dac9faa28
2 changed files with 31 additions and 34 deletions
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import cymysql
|
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
from server_pool import ServerPool
|
from server_pool import ServerPool
|
||||||
|
@ -25,31 +24,8 @@ class DbTransfer(object):
|
||||||
DbTransfer.instance = DbTransfer()
|
DbTransfer.instance = DbTransfer()
|
||||||
return DbTransfer.instance
|
return DbTransfer.instance
|
||||||
|
|
||||||
def push_db_all_user(self):
|
def update_all_user(self, dt_transfer):
|
||||||
#更新用户流量到数据库
|
import cymysql
|
||||||
last_transfer = self.last_get_transfer
|
|
||||||
curr_transfer = ServerPool.get_instance().get_servers_transfer()
|
|
||||||
#上次和本次的增量
|
|
||||||
dt_transfer = {}
|
|
||||||
for id in curr_transfer.keys():
|
|
||||||
if id in last_transfer:
|
|
||||||
if last_transfer[id][0] == curr_transfer[id][0] and last_transfer[id][1] == curr_transfer[id][1]:
|
|
||||||
continue
|
|
||||||
elif curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
|
|
||||||
continue
|
|
||||||
elif last_transfer[id][0] <= curr_transfer[id][0] and \
|
|
||||||
last_transfer[id][1] <= curr_transfer[id][1]:
|
|
||||||
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * get_config().TRANSFER_MUL),
|
|
||||||
int((curr_transfer[id][1] - last_transfer[id][1]) * get_config().TRANSFER_MUL)]
|
|
||||||
else:
|
|
||||||
dt_transfer[id] = [int(curr_transfer[id][0] * get_config().TRANSFER_MUL),
|
|
||||||
int(curr_transfer[id][1] * get_config().TRANSFER_MUL)]
|
|
||||||
else:
|
|
||||||
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
|
|
||||||
continue
|
|
||||||
dt_transfer[id] = [int(curr_transfer[id][0] * get_config().TRANSFER_MUL),
|
|
||||||
int(curr_transfer[id][1] * get_config().TRANSFER_MUL)]
|
|
||||||
|
|
||||||
query_head = 'UPDATE user'
|
query_head = 'UPDATE user'
|
||||||
query_sub_when = ''
|
query_sub_when = ''
|
||||||
query_sub_when2 = ''
|
query_sub_when2 = ''
|
||||||
|
@ -78,10 +54,38 @@ class DbTransfer(object):
|
||||||
cur.close()
|
cur.close()
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
def push_db_all_user(self):
|
||||||
|
#更新用户流量到数据库
|
||||||
|
last_transfer = self.last_get_transfer
|
||||||
|
curr_transfer = ServerPool.get_instance().get_servers_transfer()
|
||||||
|
#上次和本次的增量
|
||||||
|
dt_transfer = {}
|
||||||
|
for id in curr_transfer.keys():
|
||||||
|
if id in last_transfer:
|
||||||
|
if last_transfer[id][0] == curr_transfer[id][0] and last_transfer[id][1] == curr_transfer[id][1]:
|
||||||
|
continue
|
||||||
|
elif curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
|
||||||
|
continue
|
||||||
|
elif last_transfer[id][0] <= curr_transfer[id][0] and \
|
||||||
|
last_transfer[id][1] <= curr_transfer[id][1]:
|
||||||
|
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * get_config().TRANSFER_MUL),
|
||||||
|
int((curr_transfer[id][1] - last_transfer[id][1]) * get_config().TRANSFER_MUL)]
|
||||||
|
else:
|
||||||
|
dt_transfer[id] = [int(curr_transfer[id][0] * get_config().TRANSFER_MUL),
|
||||||
|
int(curr_transfer[id][1] * get_config().TRANSFER_MUL)]
|
||||||
|
else:
|
||||||
|
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
|
||||||
|
continue
|
||||||
|
dt_transfer[id] = [int(curr_transfer[id][0] * get_config().TRANSFER_MUL),
|
||||||
|
int(curr_transfer[id][1] * get_config().TRANSFER_MUL)]
|
||||||
|
|
||||||
|
self.update_all_user(dt_transfer)
|
||||||
self.last_get_transfer = curr_transfer
|
self.last_get_transfer = curr_transfer
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pull_db_all_user():
|
def pull_db_all_user():
|
||||||
|
import cymysql
|
||||||
#数据库所有用户信息
|
#数据库所有用户信息
|
||||||
try:
|
try:
|
||||||
import switchrule
|
import switchrule
|
||||||
|
@ -89,7 +93,6 @@ class DbTransfer(object):
|
||||||
keys = switchrule.getKeys()
|
keys = switchrule.getKeys()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
keys = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable' ]
|
keys = ['port', 'u', 'd', 'transfer_enable', 'passwd', 'enable' ]
|
||||||
reload(cymysql)
|
|
||||||
conn = cymysql.connect(host=get_config().MYSQL_HOST, port=get_config().MYSQL_PORT, user=get_config().MYSQL_USER,
|
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')
|
passwd=get_config().MYSQL_PASS, db=get_config().MYSQL_DB, charset='utf8')
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
|
@ -126,7 +129,7 @@ class DbTransfer(object):
|
||||||
passwd = common.to_bytes(row['passwd'])
|
passwd = common.to_bytes(row['passwd'])
|
||||||
cfg = {'password': passwd}
|
cfg = {'password': passwd}
|
||||||
for name in ['method', 'obfs', 'protocol']:
|
for name in ['method', 'obfs', 'protocol']:
|
||||||
if name in row:
|
if name in row and row[name]:
|
||||||
cfg[name] = row[name]
|
cfg[name] = row[name]
|
||||||
|
|
||||||
for name in cfg.keys():
|
for name in cfg.keys():
|
||||||
|
|
|
@ -206,8 +206,6 @@ class auth_simple(verify_base):
|
||||||
self.server_info.data.set_max_client(max_client)
|
self.server_info.data.set_max_client(max_client)
|
||||||
|
|
||||||
def pack_data(self, buf):
|
def pack_data(self, buf):
|
||||||
if len(buf) == 0:
|
|
||||||
return b''
|
|
||||||
rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 16)
|
rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 16)
|
||||||
data = common.chr(len(rnd_data) + 1) + rnd_data + buf
|
data = common.chr(len(rnd_data) + 1) + rnd_data + buf
|
||||||
data = struct.pack('>H', len(data) + 6) + data
|
data = struct.pack('>H', len(data) + 6) + data
|
||||||
|
@ -364,8 +362,6 @@ class auth_sha1(verify_base):
|
||||||
self.server_info.data.set_max_client(max_client)
|
self.server_info.data.set_max_client(max_client)
|
||||||
|
|
||||||
def pack_data(self, buf):
|
def pack_data(self, buf):
|
||||||
if len(buf) == 0:
|
|
||||||
return b''
|
|
||||||
rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 16)
|
rnd_data = os.urandom(common.ord(os.urandom(1)[0]) % 16)
|
||||||
data = common.chr(len(rnd_data) + 1) + rnd_data + buf
|
data = common.chr(len(rnd_data) + 1) + rnd_data + buf
|
||||||
data = struct.pack('>H', len(data) + 6) + data
|
data = struct.pack('>H', len(data) + 6) + data
|
||||||
|
@ -606,8 +602,6 @@ class auth_sha1_v2(verify_base):
|
||||||
return common.chr(255) + struct.pack('>H', len(rnd_data) + 3) + rnd_data
|
return common.chr(255) + struct.pack('>H', len(rnd_data) + 3) + rnd_data
|
||||||
|
|
||||||
def pack_data(self, buf):
|
def pack_data(self, buf):
|
||||||
if len(buf) == 0:
|
|
||||||
return b''
|
|
||||||
data = self.rnd_data(len(buf)) + buf
|
data = self.rnd_data(len(buf)) + buf
|
||||||
data = struct.pack('>H', len(data) + 6) + data
|
data = struct.pack('>H', len(data) + 6) + data
|
||||||
adler32 = zlib.adler32(data) & 0xFFFFFFFF
|
adler32 = zlib.adler32(data) & 0xFFFFFFFF
|
||||||
|
|
Loading…
Add table
Reference in a new issue