update ACL format and action to add "ranges"
This commit is contained in:
parent
8d208db204
commit
6584ba7431
|
@ -98,10 +98,25 @@ def make_bridges(_hb_confbridge_bridges):
|
||||||
# are not yet implemented.
|
# are not yet implemented.
|
||||||
def build_acl(_sub_acl):
|
def build_acl(_sub_acl):
|
||||||
try:
|
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)
|
acl_file = import_module(_sub_acl)
|
||||||
for i, e in enumerate(acl_file.ACL):
|
sections = acl_file.ACL.split(':')
|
||||||
acl_file.ACL[i] = hex_str_3(acl_file.ACL[i])
|
ACL_ACTION = sections[0]
|
||||||
logger.info('ACL file found and ACL entries imported')
|
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:
|
except ImportError:
|
||||||
logger.info('ACL file not found or invalid - all subscriber IDs are valid')
|
logger.info('ACL file not found or invalid - all subscriber IDs are valid')
|
||||||
ACL_ACTION = 'NONE'
|
ACL_ACTION = 'NONE'
|
||||||
|
@ -109,13 +124,13 @@ def build_acl(_sub_acl):
|
||||||
# Depending on which type of ACL is used (PERMIT, DENY... or there isn't one)
|
# 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
|
# define a differnet function to be used to check the ACL
|
||||||
global allow_sub
|
global allow_sub
|
||||||
if acl_file.ACL_ACTION == 'PERMIT':
|
if ACL_ACTION == 'PERMIT':
|
||||||
def allow_sub(_sub):
|
def allow_sub(_sub):
|
||||||
if _sub in ACL:
|
if _sub in ACL:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif acl_file.ACL_ACTION == 'DENY':
|
elif ACL_ACTION == 'DENY':
|
||||||
def allow_sub(_sub):
|
def allow_sub(_sub):
|
||||||
if _sub not in ACL:
|
if _sub not in ACL:
|
||||||
return True
|
return True
|
||||||
|
@ -125,7 +140,7 @@ def build_acl(_sub_acl):
|
||||||
def allow_sub(_sub):
|
def allow_sub(_sub):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return acl_file.ACL
|
return ACL
|
||||||
|
|
||||||
|
|
||||||
# Run this every minute for rule timer updates
|
# Run this every minute for rule timer updates
|
||||||
|
|
27
hb_router.py
27
hb_router.py
|
@ -101,10 +101,25 @@ def make_rules(_hb_routing_rules):
|
||||||
# are not yet implemented.
|
# are not yet implemented.
|
||||||
def build_acl(_sub_acl):
|
def build_acl(_sub_acl):
|
||||||
try:
|
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)
|
acl_file = import_module(_sub_acl)
|
||||||
for i, e in enumerate(acl_file.ACL):
|
sections = acl_file.ACL.split(':')
|
||||||
acl_file.ACL[i] = hex_str_3(acl_file.ACL[i])
|
ACL_ACTION = sections[0]
|
||||||
logger.info('ACL file found and ACL entries imported')
|
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:
|
except ImportError:
|
||||||
logger.info('ACL file not found or invalid - all subscriber IDs are valid')
|
logger.info('ACL file not found or invalid - all subscriber IDs are valid')
|
||||||
ACL_ACTION = 'NONE'
|
ACL_ACTION = 'NONE'
|
||||||
|
@ -112,13 +127,13 @@ def build_acl(_sub_acl):
|
||||||
# Depending on which type of ACL is used (PERMIT, DENY... or there isn't one)
|
# 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
|
# define a differnet function to be used to check the ACL
|
||||||
global allow_sub
|
global allow_sub
|
||||||
if acl_file.ACL_ACTION == 'PERMIT':
|
if ACL_ACTION == 'PERMIT':
|
||||||
def allow_sub(_sub):
|
def allow_sub(_sub):
|
||||||
if _sub in ACL:
|
if _sub in ACL:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif acl_file.ACL_ACTION == 'DENY':
|
elif ACL_ACTION == 'DENY':
|
||||||
def allow_sub(_sub):
|
def allow_sub(_sub):
|
||||||
if _sub not in ACL:
|
if _sub not in ACL:
|
||||||
return True
|
return True
|
||||||
|
@ -128,7 +143,7 @@ def build_acl(_sub_acl):
|
||||||
def allow_sub(_sub):
|
def allow_sub(_sub):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return acl_file.ACL
|
return ACL
|
||||||
|
|
||||||
|
|
||||||
# Run this every minute for rule timer updates
|
# Run this every minute for rule timer updates
|
||||||
|
|
2269
peer_ids.csv
2269
peer_ids.csv
File diff suppressed because it is too large
Load Diff
17
sub_acl.py
17
sub_acl.py
|
@ -1,12 +1,5 @@
|
||||||
'''
|
# The 'action' May be PERMIT|DENY
|
||||||
This is the Access Control List (ACL) file for limiting call
|
# Each entry may be a single radio id, or a hypenated range (e.g. 1-2999)
|
||||||
routing/bridging in various hblink.py-based applications. It
|
# Format:
|
||||||
is a VERY simple format. The action may be to PERMIT or DENY
|
# ACL = 'action:id|start-end|,id|start-end,....'
|
||||||
and the ACL itself is a list of subscriber IDs that may be
|
ACL = 'DENY:0-2999,4000000-9999999'
|
||||||
permitted or denied.
|
|
||||||
'''
|
|
||||||
|
|
||||||
ACL_ACTION = "DENY" # May be PERMIT|DENY
|
|
||||||
ACL = [
|
|
||||||
1,2,3,4,5,6,7,8,9,10,100
|
|
||||||
]
|
|
113526
subscriber_ids.csv
113526
subscriber_ids.csv
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue