mirror of
https://github.com/ShaYmez/pYSFReflector.git
synced 2025-08-09 17:22:28 -04:00
Added "two way muted" mode
This commit is contained in:
parent
654402a008
commit
e94c6ed188
61
YSFReflector
61
YSFReflector
@ -239,11 +239,17 @@ def lista_invio(lista):
|
|||||||
def update_clients(cl):
|
def update_clients(cl):
|
||||||
global GW_BL
|
global GW_BL
|
||||||
global IP_BL
|
global IP_BL
|
||||||
|
global GW_LK
|
||||||
|
global IP_LK
|
||||||
for c in cl:
|
for c in cl:
|
||||||
if (inlist(GW_BL, c[2]) or inlist(IP_BL, ip2long(c[0]))):
|
if (inlist(GW_BL, c[2]) or inlist(IP_BL, ip2long(c[0])) or inlist(GW_LK, c[2]) or inlist(IP_LK, ip2long(c[0]))):
|
||||||
c[5] = 1
|
c[5] = 1
|
||||||
else:
|
else:
|
||||||
c[5] = 0
|
c[5] = 0
|
||||||
|
if (inlist(GW_LK, c[2]) or inlist(IP_LK, ip2long(c[0]))):
|
||||||
|
c[7] = 1
|
||||||
|
else:
|
||||||
|
c[7] = 0
|
||||||
|
|
||||||
|
|
||||||
def blacklist(f_bl, t_reload, cli):
|
def blacklist(f_bl, t_reload, cli):
|
||||||
@ -251,6 +257,9 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
global WHITE_LIST
|
global WHITE_LIST
|
||||||
global GW_BL
|
global GW_BL
|
||||||
global IP_BL
|
global IP_BL
|
||||||
|
global GW_LK
|
||||||
|
global IP_LK
|
||||||
|
|
||||||
f_time_old = 0
|
f_time_old = 0
|
||||||
try:
|
try:
|
||||||
f_time = os.stat(f_bl).st_mtime
|
f_time = os.stat(f_bl).st_mtime
|
||||||
@ -266,6 +275,8 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
GW_TMP = []
|
GW_TMP = []
|
||||||
IP_TMP = []
|
IP_TMP = []
|
||||||
WL_TMP = []
|
WL_TMP = []
|
||||||
|
GW_LK_TMP = []
|
||||||
|
IP_LK_TMP = []
|
||||||
printlog(1, 'Reload the Blacklist from File')
|
printlog(1, 'Reload the Blacklist from File')
|
||||||
for row in file:
|
for row in file:
|
||||||
content = row.strip()
|
content = row.strip()
|
||||||
@ -296,6 +307,11 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
if (not inlist(GW_TMP, c_split[1])):
|
if (not inlist(GW_TMP, c_split[1])):
|
||||||
bisect.insort(GW_TMP,c_split[1])
|
bisect.insort(GW_TMP,c_split[1])
|
||||||
|
|
||||||
|
# GWB
|
||||||
|
if (len(c_split) == 2 and c_split[0] == 'GWB'):
|
||||||
|
if (not inlist(GW_LK_TMP, c_split[1])):
|
||||||
|
bisect.insort(GW_LK_TMP,c_split[1])
|
||||||
|
|
||||||
# IP
|
# IP
|
||||||
if (len(c_split) == 2 and c_split[0] == 'IP'):
|
if (len(c_split) == 2 and c_split[0] == 'IP'):
|
||||||
try:
|
try:
|
||||||
@ -308,6 +324,18 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
if (not inlist(IP_TMP, ipl)):
|
if (not inlist(IP_TMP, ipl)):
|
||||||
bisect.insort(IP_TMP, ipl)
|
bisect.insort(IP_TMP, ipl)
|
||||||
|
|
||||||
|
# IPB
|
||||||
|
if (len(c_split) == 2 and c_split[0] == 'IPB'):
|
||||||
|
try:
|
||||||
|
ipa = socket.gethostbyname(c_split[1])
|
||||||
|
ipl = ip2long(ipa)
|
||||||
|
except:
|
||||||
|
ipl = 0
|
||||||
|
printlog(2, 'Invalid hostname ' + c_split[1])
|
||||||
|
if (ipl > 0):
|
||||||
|
if (not inlist(IP_LK_TMP, ipl)):
|
||||||
|
bisect.insort(IP_LK_TMP, ipl)
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
printlog(2, 'Failed to load Blacklist from File ' + str(ex) )
|
printlog(2, 'Failed to load Blacklist from File ' + str(ex) )
|
||||||
@ -315,7 +343,9 @@ def blacklist(f_bl, t_reload, cli):
|
|||||||
WHITE_LIST = WL_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()
|
||||||
printlog(1, 'Loaded ' + str(len(BLACK_LIST)) + '/CS ' + str(len(WHITE_LIST)) + '/AL ' + str(len(GW_BL)) + '/GW ' + str(len(IP_BL)) + '/IP')
|
GW_LK = GW_LK_TMP.copy()
|
||||||
|
IP_LK = IP_LK_TMP.copy()
|
||||||
|
printlog(1, 'Loaded ' + str(len(BLACK_LIST)) + '/CS ' + str(len(WHITE_LIST)) + '/AL ' + str(len(GW_BL)) + '/GW ' + str(len(IP_BL)) + '/IP ' + str(len(GW_LK)) + '/GWB ' + str(len(IP_LK)) + '/IPB')
|
||||||
f_time_old = f_time
|
f_time_old = f_time
|
||||||
update_clients(cli)
|
update_clients(cli)
|
||||||
else:
|
else:
|
||||||
@ -422,12 +452,14 @@ def RunServer(config):
|
|||||||
global BLACK_LIST
|
global BLACK_LIST
|
||||||
global GW_BL
|
global GW_BL
|
||||||
global IP_BL
|
global IP_BL
|
||||||
|
global GW_LK
|
||||||
|
global IP_LK
|
||||||
host = '0.0.0.0'
|
host = '0.0.0.0'
|
||||||
port = config[5]
|
port = config[5]
|
||||||
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||||
s.setblocking(1)
|
s.setblocking(1)
|
||||||
s.bind((host,port))
|
s.bind((host,port))
|
||||||
clients = [] # addr, port, gw, t_corr, ID, lonly, t_conn
|
clients = [] # addr, port, gw, t_corr, ID, lonly, t_conn, locked
|
||||||
c = []
|
c = []
|
||||||
rx_lock = []
|
rx_lock = []
|
||||||
rx_lock_tout = {}
|
rx_lock_tout = {}
|
||||||
@ -490,11 +522,19 @@ def RunServer(config):
|
|||||||
break
|
break
|
||||||
if not pres:
|
if not pres:
|
||||||
lonly = 0
|
lonly = 0
|
||||||
|
locked = 0
|
||||||
if inlist(GW_BL, (data[4:14]).decode().strip()):
|
if inlist(GW_BL, (data[4:14]).decode().strip()):
|
||||||
lonly = 1
|
lonly = 1
|
||||||
if inlist(IP_BL, ip2long(addr[0])):
|
if inlist(IP_BL, ip2long(addr[0])):
|
||||||
lonly = 1
|
lonly = 1
|
||||||
c=[addr[0], addr[1], (data[4:14]).decode().strip(), 0, id, lonly, time.time()]
|
if inlist(GW_LK, (data[4:14]).decode().strip()):
|
||||||
|
locked = 1
|
||||||
|
lonly = 1
|
||||||
|
if inlist(IP_LK, ip2long(addr[0])):
|
||||||
|
locked = 1
|
||||||
|
lonly = 1
|
||||||
|
|
||||||
|
c=[addr[0], addr[1], (data[4:14]).decode().strip(), 0, id, lonly, time.time(), locked]
|
||||||
id += 1
|
id += 1
|
||||||
clients.append(c)
|
clients.append(c)
|
||||||
printlog(1, 'Adding ' + c[2].ljust(10) + ' (' + c[0] + ':' + str(c[1]) + ')')
|
printlog(1, 'Adding ' + c[2].ljust(10) + ' (' + c[0] + ':' + str(c[1]) + ')')
|
||||||
@ -510,11 +550,11 @@ def RunServer(config):
|
|||||||
if ((cmd == b'YSFD') and (len(data) == 155)):
|
if ((cmd == b'YSFD') and (len(data) == 155)):
|
||||||
[id_corr, gw_corr] = getidgw(clients, addr)
|
[id_corr, gw_corr] = getidgw(clients, addr)
|
||||||
if (tx[0] == 0):
|
if (tx[0] == 0):
|
||||||
if inlist(GW_BL, gw_corr):
|
if (inlist(GW_BL, gw_corr) or inlist(GW_LK, gw_corr)):
|
||||||
tx_ok = False
|
tx_ok = False
|
||||||
block_r = 'GW'
|
block_r = 'GW'
|
||||||
else:
|
else:
|
||||||
if inlist(IP_BL, ip2long(addr[0])):
|
if (inlist(IP_BL, ip2long(addr[0])) or inlist(IP_LK, ip2long(addr[0]))):
|
||||||
tx_ok = False
|
tx_ok = False
|
||||||
block_r = 'IP'
|
block_r = 'IP'
|
||||||
else:
|
else:
|
||||||
@ -548,11 +588,10 @@ def RunServer(config):
|
|||||||
tx[1] = 0
|
tx[1] = 0
|
||||||
|
|
||||||
for c in clients:
|
for c in clients:
|
||||||
if (((c[0] != addr[0]) or (c[1] != addr[1])) and (id_corr == tx[0]) and (id_corr != 0) and (id_corr not in rx_lock)):
|
if (((c[0] != addr[0]) or (c[1] != addr[1])) and (id_corr == tx[0]) and (id_corr != 0) and (id_corr not in rx_lock) and (c[7] == 0)):
|
||||||
s.sendto(data,(c[0], c[1]))
|
s.sendto(data,(c[0], c[1]))
|
||||||
|
|
||||||
if ((data[34] & 0x01) == 0x01):
|
if (((data[34] & 0x01) == 0x01) and (tx[0] == id_corr) and (tx[0] !=0)):
|
||||||
if (tx[0] != 0):
|
|
||||||
printlog(1, 'Received end of transmission')
|
printlog(1, 'Received end of transmission')
|
||||||
inserisci_lista(LH, [check_string(tx[2]), check_string(tx[3]), check_string(tx[4]), tx[5], datetime.utcfromtimestamp(tx[6]).strftime("%d-%m-%Y %H-%M-%S"), round(time.time() - tx[6]) ], 20)
|
inserisci_lista(LH, [check_string(tx[2]), check_string(tx[3]), check_string(tx[4]), tx[5], datetime.utcfromtimestamp(tx[6]).strftime("%d-%m-%Y %H-%M-%S"), round(time.time() - tx[6]) ], 20)
|
||||||
inserisci_listaD(LHD, [check_string(tx[2]), check_string(tx[3]), check_string(tx[4]), tx[5], datetime.utcfromtimestamp(tx[6]).strftime("%d-%m-%Y %H-%M-%S"), round(time.time() - tx[6]) ], 20)
|
inserisci_listaD(LHD, [check_string(tx[2]), check_string(tx[3]), check_string(tx[4]), tx[5], datetime.utcfromtimestamp(tx[6]).strftime("%d-%m-%Y %H-%M-%S"), round(time.time() - tx[6]) ], 20)
|
||||||
@ -692,7 +731,7 @@ def printlog(log_level, mess):
|
|||||||
|
|
||||||
######## main ########
|
######## main ########
|
||||||
|
|
||||||
version = '20210411'
|
version = '20210417'
|
||||||
|
|
||||||
if (len(sys.argv) != 2):
|
if (len(sys.argv) != 2):
|
||||||
print('Invalid Number of Arguments')
|
print('Invalid Number of Arguments')
|
||||||
@ -733,6 +772,8 @@ BLACK_LIST = []
|
|||||||
WHITE_LIST = []
|
WHITE_LIST = []
|
||||||
GW_BL = []
|
GW_BL = []
|
||||||
IP_BL = []
|
IP_BL = []
|
||||||
|
GW_LK = []
|
||||||
|
IP_LK = []
|
||||||
|
|
||||||
RunServer(config)
|
RunServer(config)
|
||||||
|
|
||||||
|
6
deny.db
6
deny.db
@ -5,9 +5,15 @@
|
|||||||
# CS:IU5JAE
|
# CS:IU5JAE
|
||||||
# IU5JAE
|
# IU5JAE
|
||||||
## Block gateway
|
## Block gateway
|
||||||
|
## listen only
|
||||||
# GW:TESTBDG
|
# GW:TESTBDG
|
||||||
|
## Two way mute
|
||||||
|
# GWB:TESTBDG
|
||||||
## Block IP
|
## Block IP
|
||||||
|
## listen only
|
||||||
# IP:80.181.214.194
|
# IP:80.181.214.194
|
||||||
|
## Two way mute
|
||||||
|
# IPB:80.181.214.194
|
||||||
## Allowed callsign
|
## Allowed callsign
|
||||||
AL:N0CALL
|
AL:N0CALL
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user