Browse Source

custom 'forbidden_ip' for each user

fix cmp for IPNetwork & PortRange
dev
BreakWa11 9 years ago
parent
commit
5c1b90b774
  1. 2
      db_transfer.py
  2. 9
      shadowsocks/common.py
  3. 2
      shadowsocks/shell.py

2
db_transfer.py

@ -120,7 +120,7 @@ class DbTransfer(object):
passwd = common.to_bytes(row['passwd']) passwd = common.to_bytes(row['passwd'])
cfg = {'password': passwd} cfg = {'password': passwd}
read_config_keys = ['method', 'obfs', 'protocol', 'forbidden_port'] read_config_keys = ['method', 'obfs', 'protocol', 'forbidden_ip', 'forbidden_port']
for name in read_config_keys: 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]

9
shadowsocks/common.py

@ -233,6 +233,7 @@ class IPNetwork(object):
ADDRLENGTH = {socket.AF_INET: 32, socket.AF_INET6: 128, False: 0} ADDRLENGTH = {socket.AF_INET: 32, socket.AF_INET6: 128, False: 0}
def __init__(self, addrs): def __init__(self, addrs):
self.addrs_str = addrs
self._network_list_v4 = [] self._network_list_v4 = []
self._network_list_v6 = [] self._network_list_v6 = []
if type(addrs) == str: if type(addrs) == str:
@ -283,8 +284,12 @@ class IPNetwork(object):
else: else:
return False return False
def __cmp__(self, other):
return cmp(self.addrs_str, other.addrs_str)
class PortRange(object): class PortRange(object):
def __init__(self, range_str): def __init__(self, range_str):
self.range_str = range_str
self.range = set() self.range = set()
if type(range_str) == str: if type(range_str) == str:
range_str = range_str.split(',') range_str = range_str.split(',')
@ -310,8 +315,8 @@ 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): def __cmp__(self, other):
return self.range == other.range return cmp(self.range_str, other.range_str)
def test_inet_conv(): def test_inet_conv():
ipv4 = b'8.8.4.4' ipv4 = b'8.8.4.4'

2
shadowsocks/shell.py

@ -199,7 +199,7 @@ def get_config(is_local):
elif key == '--user': elif key == '--user':
config['user'] = to_str(value) config['user'] = to_str(value)
elif key == '--forbidden-ip': elif key == '--forbidden-ip':
config['forbidden_ip'] = to_str(value).split(',') config['forbidden_ip'] = to_str(value)
elif key in ('-h', '--help'): elif key in ('-h', '--help'):
if is_local: if is_local:
print_local_help() print_local_help()

Loading…
Cancel
Save