custom 'forbidden_port' for each user
This commit is contained in:
parent
72aab7701f
commit
8cbca008c6
2 changed files with 20 additions and 3 deletions
|
@ -119,10 +119,13 @@ class DbTransfer(object):
|
||||||
port = row['port']
|
port = row['port']
|
||||||
passwd = common.to_bytes(row['passwd'])
|
passwd = common.to_bytes(row['passwd'])
|
||||||
cfg = {'password': passwd}
|
cfg = {'password': passwd}
|
||||||
for name in ['method', 'obfs', 'protocol']:
|
|
||||||
|
read_config_keys = ['method', 'obfs', 'protocol', 'forbidden_port']
|
||||||
|
for name in read_config_keys:
|
||||||
if name in row and row[name]:
|
if name in row and row[name]:
|
||||||
cfg[name] = row[name]
|
cfg[name] = row[name]
|
||||||
|
|
||||||
|
merge_config_keys = ['password'] + read_config_keys
|
||||||
for name in cfg.keys():
|
for name in cfg.keys():
|
||||||
if hasattr(cfg[name], 'encode'):
|
if hasattr(cfg[name], 'encode'):
|
||||||
cfg[name] = cfg[name].encode('utf-8')
|
cfg[name] = cfg[name].encode('utf-8')
|
||||||
|
@ -141,13 +144,13 @@ class DbTransfer(object):
|
||||||
cfgchange = False
|
cfgchange = False
|
||||||
if port in ServerPool.get_instance().tcp_servers_pool:
|
if port in ServerPool.get_instance().tcp_servers_pool:
|
||||||
relay = ServerPool.get_instance().tcp_servers_pool[port]
|
relay = ServerPool.get_instance().tcp_servers_pool[port]
|
||||||
for name in ['password', 'method', 'obfs', 'protocol']:
|
for name in merge_config_keys:
|
||||||
if name in cfg and cfg[name] != relay._config[name]:
|
if name in cfg and cfg[name] != relay._config[name]:
|
||||||
cfgchange = True
|
cfgchange = True
|
||||||
break;
|
break;
|
||||||
if not cfgchange and port in ServerPool.get_instance().tcp_ipv6_servers_pool:
|
if not cfgchange and port in ServerPool.get_instance().tcp_ipv6_servers_pool:
|
||||||
relay = ServerPool.get_instance().tcp_ipv6_servers_pool[port]
|
relay = ServerPool.get_instance().tcp_ipv6_servers_pool[port]
|
||||||
for name in ['password', 'method', 'obfs', 'protocol']:
|
for name in merge_config_keys:
|
||||||
if name in cfg and cfg[name] != relay._config[name]:
|
if name in cfg and cfg[name] != relay._config[name]:
|
||||||
cfgchange = True
|
cfgchange = True
|
||||||
break;
|
break;
|
||||||
|
@ -249,6 +252,17 @@ class MuJsonTransfer(DbTransfer):
|
||||||
config_path = "mudb.json"
|
config_path = "mudb.json"
|
||||||
with open(config_path, 'r+') as f:
|
with open(config_path, 'r+') as f:
|
||||||
rows = shell.parse_json_in_str(f.read().decode('utf8'))
|
rows = shell.parse_json_in_str(f.read().decode('utf8'))
|
||||||
|
for row in rows:
|
||||||
|
try:
|
||||||
|
if 'forbidden_ip' in row:
|
||||||
|
row['forbidden_ip'] = common.IPNetwork(row['forbidden_ip'])
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
try:
|
||||||
|
if 'forbidden_port' in row:
|
||||||
|
row['forbidden_port'] = common.PortRange(row['forbidden_port'])
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,9 @@ class PortRange(object):
|
||||||
def __contains__(self, val):
|
def __contains__(self, val):
|
||||||
return val in self.range
|
return val in self.range
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.range == other.range
|
||||||
|
|
||||||
def test_inet_conv():
|
def test_inet_conv():
|
||||||
ipv4 = b'8.8.4.4'
|
ipv4 = b'8.8.4.4'
|
||||||
b = inet_pton(socket.AF_INET, ipv4)
|
b = inet_pton(socket.AF_INET, ipv4)
|
||||||
|
|
Loading…
Add table
Reference in a new issue