diff --git a/bridge.py b/bridge.py index d99f436..b0846e7 100755 --- a/bridge.py +++ b/bridge.py @@ -127,17 +127,29 @@ def build_bridges(_known_bridges): # are not yet implemented. def build_acl(_sub_acl): try: + logger.info('ACL file found, importing entries. This will take about 1.5 seconds per 1 million IDs') acl_file = import_module(_sub_acl) - for i, e in enumerate(acl_file.ACL): - acl_file.ACL[i] = hex_str_3(acl_file.ACL[i]) - logger.info('ACL file found and ACL entries imported') - ACL_ACTION = acl_file.ACL_ACTION - ACL = acl_file.ACL + sections = acl_file.ACL.split(':') + ACL_ACTION = sections[0] + entries_str = sections[1] + ACL = set() + + for entry in entries_str.split(','): + if '-' in entry: + start,end = entry.split('-') + start,end = int(start), int(end) + for id in range(start, end+1): + ACL.add(hex_str_3(id)) + else: + id = int(entry) + ACL.add(hex_str_3(id)) + + logger.info('ACL loaded: action "{}" for {:,} radio IDs'.format(ACL_ACTION, len(ACL))) + except ImportError: logger.info('ACL file not found or invalid - all subscriber IDs are valid') ACL_ACTION = 'NONE' - ACL = [] - + # Depending on which type of ACL is used (PERMIT, DENY... or there isn't one) # define a differnet function to be used to check the ACL global allow_sub diff --git a/confbridge.py b/confbridge.py index 4c5f9fb..44c9037 100755 --- a/confbridge.py +++ b/confbridge.py @@ -149,16 +149,28 @@ def make_bridge_config(_confbridge_rules): # are not yet implemented. def build_acl(_sub_acl): try: + logger.info('ACL file found, importing entries. This will take about 1.5 seconds per 1 million IDs') acl_file = import_module(_sub_acl) - for i, e in enumerate(acl_file.ACL): - acl_file.ACL[i] = hex_str_3(acl_file.ACL[i]) - logger.info('ACL file found and ACL entries imported') - ACL_ACTION = acl_file.ACL_ACTION - ACL = acl_file.ACL_ACTION + sections = acl_file.ACL.split(':') + ACL_ACTION = sections[0] + entries_str = sections[1] + ACL = set() + + for entry in entries_str.split(','): + if '-' in entry: + start,end = entry.split('-') + start,end = int(start), int(end) + for id in range(start, end+1): + ACL.add(hex_str_3(id)) + else: + id = int(entry) + ACL.add(hex_str_3(id)) + + logger.info('ACL loaded: action "{}" for {:,} radio IDs'.format(ACL_ACTION, len(ACL))) + except ImportError: logger.info('ACL file not found or invalid - all subscriber IDs are valid') ACL_ACTION = 'NONE' - ACL = [] # Depending on which type of ACL is used (PERMIT, DENY... or there isn't one) # define a differnet function to be used to check the ACL diff --git a/proxy.py b/proxy.py index 69d10db..2a9eae6 100755 --- a/proxy.py +++ b/proxy.py @@ -72,16 +72,28 @@ __email__ = 'n0mjs@me.com' # are not yet implemented. def build_acl(_sub_acl): try: + logger.info('ACL file found, importing entries. This will take about 1.5 seconds per 1 million IDs') acl_file = import_module(_sub_acl) - for i, e in enumerate(acl_file.ACL): - acl_file.ACL[i] = hex_str_3(acl_file.ACL[i]) - logger.info('ACL file found and ACL entries imported') - ACL_ACTION = acl_file.ACL_ACTION - ACL = acl_file.ACL_ACTION + sections = acl_file.ACL.split(':') + ACL_ACTION = sections[0] + entries_str = sections[1] + ACL = set() + + for entry in entries_str.split(','): + if '-' in entry: + start,end = entry.split('-') + start,end = int(start), int(end) + for id in range(start, end+1): + ACL.add(hex_str_3(id)) + else: + id = int(entry) + ACL.add(hex_str_3(id)) + + logger.info('ACL loaded: action "{}" for {:,} radio IDs'.format(ACL_ACTION, len(ACL))) + except ImportError: logger.info('ACL file not found or invalid - all subscriber IDs are valid') ACL_ACTION = 'NONE' - ACL = [] # Depending on which type of ACL is used (PERMIT, DENY... or there isn't one) # define a differnet function to be used to check the ACL diff --git a/sub_acl_SAMPLE.py b/sub_acl_SAMPLE.py index a60fa60..78cedf8 100644 --- a/sub_acl_SAMPLE.py +++ b/sub_acl_SAMPLE.py @@ -1,6 +1,6 @@ -ACL_ACTION = "DENY" # May be PERMIT|DENY -ACL = [ - 1234001, - 1234002, - 1234003 - ] \ No newline at end of file +# The 'action' May be PERMIT|DENY +# Each entry may be a single radio id, or a hypenated range (e.g. 1-2999) +# Format: +# ACL = 'action:id|start-end|,id|start-end,....' + +ACL = 'DENY:1-2999,16777215' \ No newline at end of file