mirror of
https://github.com/ShaYmez/pYSFReflector.git
synced 2025-09-07 15:37:53 -04:00
Black list management update
added CheckRE flag in .ini file to enable / disable checking of names by regular expression added suffix AL: to file for callsign in withelist other corrections / optimizations
This commit is contained in:
parent
bd4f972a70
commit
fc26f0ac9b
42
YSFReflector
42
YSFReflector
@ -168,20 +168,25 @@ def TimeoutTX(t, t_lock, r_lock, lista_lh):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
def canTrasmit(cs):
|
def canTrasmit(cs, re_en):
|
||||||
global BLACK_LIST
|
global BLACK_LIST
|
||||||
|
global WHITE_LIST
|
||||||
call_sp = re.split(r'[-/]', cs)
|
call_sp = re.split(r'[-/]', cs)
|
||||||
call = call_sp[0]
|
call = call_sp[0]
|
||||||
|
if inlist(WHITE_LIST, call):
|
||||||
|
return True
|
||||||
if inlist(BLACK_LIST, call):
|
if inlist(BLACK_LIST, call):
|
||||||
return False
|
return False
|
||||||
if (len(call_sp) > 1):
|
if (len(call_sp) > 1):
|
||||||
if (call_sp[1] == 'RPT'):
|
if (call_sp[1] == 'RPT'):
|
||||||
return False
|
return False
|
||||||
if (re.match(r'^\d?[A-Z]{1,2}\d{1,4}[A-Z]{1,3}$',call,re.IGNORECASE) and (len(call) <= 8)):
|
if re_en:
|
||||||
return True
|
if (re.match(r'^\d?[A-Z]{1,2}\d{1,4}[A-Z]{1,3}$',call,re.IGNORECASE) and (len(call) <= 8)):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
pass
|
return True
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def lista_gw(cl):
|
def lista_gw(cl):
|
||||||
@ -210,6 +215,7 @@ def update_clients(cl):
|
|||||||
|
|
||||||
def blacklist(f_bl, t_reload, cli):
|
def blacklist(f_bl, t_reload, cli):
|
||||||
global BLACK_LIST
|
global BLACK_LIST
|
||||||
|
global WHITE_LIST
|
||||||
global GW_BL
|
global GW_BL
|
||||||
global IP_BL
|
global IP_BL
|
||||||
f_time_old = 0
|
f_time_old = 0
|
||||||
@ -226,6 +232,7 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
BL_TMP = []
|
BL_TMP = []
|
||||||
GW_TMP = []
|
GW_TMP = []
|
||||||
IP_TMP = []
|
IP_TMP = []
|
||||||
|
WL_TMP = []
|
||||||
printlog('Reload the Blacklist from File')
|
printlog('Reload the Blacklist from File')
|
||||||
for row in file:
|
for row in file:
|
||||||
content = row.strip()
|
content = row.strip()
|
||||||
@ -242,6 +249,11 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
if ((len(cont) <= 8) and (len(cont) >= 3)):
|
if ((len(cont) <= 8) and (len(cont) >= 3)):
|
||||||
if (not inlist(BL_TMP, cont)):
|
if (not inlist(BL_TMP, cont)):
|
||||||
bisect.insort(BL_TMP,cont)
|
bisect.insort(BL_TMP,cont)
|
||||||
|
|
||||||
|
# WL
|
||||||
|
if (len(c_split) == 2 and c_split[0] == 'AL'):
|
||||||
|
if (not inlist(WL_TMP, c_split[1])):
|
||||||
|
bisect.insort(WL_TMP,c_split[1])
|
||||||
|
|
||||||
# GW
|
# GW
|
||||||
if (len(c_split) == 2 and c_split[0] == 'GW'):
|
if (len(c_split) == 2 and c_split[0] == 'GW'):
|
||||||
@ -264,6 +276,7 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
printlog('Failed to load Blacklist from File ')
|
printlog('Failed to load Blacklist from File ')
|
||||||
BLACK_LIST = BL_TMP.copy()
|
BLACK_LIST = BL_TMP.copy()
|
||||||
|
WHITE_LIST = WL_TMP.copy()
|
||||||
GW_BL = GW_TMP.copy()
|
GW_BL = GW_TMP.copy()
|
||||||
IP_BL = IP_TMP.copy()
|
IP_BL = IP_TMP.copy()
|
||||||
f_time_old = f_time
|
f_time_old = f_time
|
||||||
@ -300,6 +313,11 @@ def ReadConfig(f,p):
|
|||||||
file_blacklist = config['Block List']['File']
|
file_blacklist = config['Block List']['File']
|
||||||
except:
|
except:
|
||||||
file_blacklist = ''
|
file_blacklist = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
CheckRE = int(config['Block List']['CheckRE'])
|
||||||
|
except:
|
||||||
|
CheckRE = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t_reload_blacklist = float(config['Block List']['Time'])
|
t_reload_blacklist = float(config['Block List']['Time'])
|
||||||
@ -317,17 +335,18 @@ def ReadConfig(f,p):
|
|||||||
p.append(file_blacklist) # 6
|
p.append(file_blacklist) # 6
|
||||||
p.append(t_reload_blacklist) # 7
|
p.append(t_reload_blacklist) # 7
|
||||||
p.append(file_rotate) # 8
|
p.append(file_rotate) # 8
|
||||||
|
p.append(CheckRE) # 9
|
||||||
|
|
||||||
|
|
||||||
def sanitize_msg(data):
|
def sanitize_msg(data):
|
||||||
bya_msg = bytearray(data)
|
bya_msg = bytearray(data)
|
||||||
|
|
||||||
if (data[0:4] == b"YSFP"):
|
if ((data[0:4] == b"YSFP") and (len(data) == 14)):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
if (bya_msg[i+4] == 0):
|
if (bya_msg[i+4] == 0):
|
||||||
bya_msg[i+4] = 32
|
bya_msg[i+4] = 32
|
||||||
|
|
||||||
if (data[0:4] == b"YSFD"):
|
if ((data[0:4] == b"YSFD") and (len(data) == 155)):
|
||||||
for i in range(30):
|
for i in range(30):
|
||||||
if (bya_msg[i+4] == 0):
|
if (bya_msg[i+4] == 0):
|
||||||
bya_msg[i+4] = 32
|
bya_msg[i+4] = 32
|
||||||
@ -371,6 +390,8 @@ def RunServer(config):
|
|||||||
f_blacklist = config[6]
|
f_blacklist = config[6]
|
||||||
tr_blacklist = config[7] * 60.0
|
tr_blacklist = config[7] * 60.0
|
||||||
|
|
||||||
|
CheckRE = config[9]
|
||||||
|
|
||||||
recvPackets = queue.Queue()
|
recvPackets = queue.Queue()
|
||||||
|
|
||||||
print('Starting YSFReflector-' + version)
|
print('Starting YSFReflector-' + version)
|
||||||
@ -426,7 +447,7 @@ def RunServer(config):
|
|||||||
tx_ok = False
|
tx_ok = False
|
||||||
block_r = 'IP'
|
block_r = 'IP'
|
||||||
else:
|
else:
|
||||||
tx_ok = canTrasmit(data[14:24].decode().strip())
|
tx_ok = canTrasmit(data[14:24].decode().strip(), CheckRE)
|
||||||
block_r = 'CS'
|
block_r = 'CS'
|
||||||
if tx_ok:
|
if tx_ok:
|
||||||
if ((tx[0] == 0) and (id_corr != 0)):
|
if ((tx[0] == 0) and (id_corr != 0)):
|
||||||
@ -545,7 +566,7 @@ def printlog(mess):
|
|||||||
|
|
||||||
######## main ########
|
######## main ########
|
||||||
|
|
||||||
version = '20210317'
|
version = '20210322'
|
||||||
|
|
||||||
if (len(sys.argv) != 2):
|
if (len(sys.argv) != 2):
|
||||||
print('Invalid Number of Arguments')
|
print('Invalid Number of Arguments')
|
||||||
@ -580,7 +601,8 @@ except:
|
|||||||
print('Unable to Open Log File')
|
print('Unable to Open Log File')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
BLACK_LIST = []
|
BLACK_LIST = []
|
||||||
|
WHITE_LIST = []
|
||||||
GW_BL = []
|
GW_BL = []
|
||||||
IP_BL = []
|
IP_BL = []
|
||||||
|
|
||||||
|
@ -28,3 +28,6 @@ Debug=0
|
|||||||
[Block List]
|
[Block List]
|
||||||
File=/usr/local/etc/deny.db
|
File=/usr/local/etc/deny.db
|
||||||
Time=5
|
Time=5
|
||||||
|
# enable (1) or disable (0) regular expression checking [^\d?[A-Z]{1,2}\d{1,4}[A-Z]{1,3}$]
|
||||||
|
CheckRE=1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user