@ -62,6 +62,8 @@ import ssl
from os . path import isfile , getmtime
from os . path import isfile , getmtime
from urllib . request import urlopen
from urllib . request import urlopen
import csv
logging . TRACE = 5
logging . TRACE = 5
logging . addLevelName ( logging . TRACE , ' TRACE ' )
logging . addLevelName ( logging . TRACE , ' TRACE ' )
@ -455,6 +457,12 @@ class OPENBRIDGE(DatagramProtocol):
self . send_bcsq ( _dst_id , _stream_id )
self . send_bcsq ( _dst_id , _stream_id )
self . _laststrid . append ( _stream_id )
self . _laststrid . append ( _stream_id )
return
return
elif ( len ( str ( int . from_bytes ( _source_server , ' big ' ) ) ) == 4 or ( len ( str ( int . from_bytes ( _source_server , ' big ' ) ) ) == 5 ) ) and ( ( str ( int . from_bytes ( _source_server , ' big ' ) ) [ : 4 ] ) not in self . _CONFIG [ ' _SERVER_IDS ' ] ) :
if _stream_id not in self . _laststrid :
logger . warning ( ' ( %s ) Source Server ID is 4 or 5 digits but not in list: %s ' , self . _system , int . from_bytes ( _source_server , ' big ' ) )
self . send_bcsq ( _dst_id , _stream_id )
self . _laststrid . append ( _stream_id )
return
elif len ( str ( int . from_bytes ( _source_server , ' big ' ) ) ) > 5 and not self . validate_id ( _source_server ) :
elif len ( str ( int . from_bytes ( _source_server , ' big ' ) ) ) > 5 and not self . validate_id ( _source_server ) :
if _stream_id not in self . _laststrid :
if _stream_id not in self . _laststrid :
logger . warning ( ' ( %s ) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s ' , self . _system , int . from_bytes ( _source_server , ' big ' ) )
logger . warning ( ' ( %s ) Source Server 6 or 7 digits but not a valid DMR ID, discarding Src: %s ' , self . _system , int . from_bytes ( _source_server , ' big ' ) )
@ -1384,6 +1392,19 @@ def try_download(_path, _file, _url, _stale,):
return result
return result
#Read list of listed servers from CSV (actually TSV) file
def mk_server_dict ( path , filename ) :
server_ids = { }
try :
with open ( path + filename , newline = ' ' ) as csvfile :
reader = csv . DictReader ( csvfile , dialect = ' excel-tab ' )
for _row in reader :
server_ids [ _row [ ' OPB Net ID ' ] ] = _row [ ' Country ' ]
return ( server_ids )
except IOError as err :
logger . warning ( ' ID ALIAS MAPPER: %s could not be read due to IOError: %s ' , file , err )
return ( False )
# ID ALIAS CREATION
# ID ALIAS CREATION
# Download
# Download
@ -1398,6 +1419,10 @@ def mk_aliases(_config):
#Try updating tgid aliases file
#Try updating tgid aliases file
result = try_download ( _config [ ' ALIASES ' ] [ ' PATH ' ] , _config [ ' ALIASES ' ] [ ' TGID_FILE ' ] , _config [ ' ALIASES ' ] [ ' TGID_URL ' ] , _config [ ' ALIASES ' ] [ ' STALE_TIME ' ] )
result = try_download ( _config [ ' ALIASES ' ] [ ' PATH ' ] , _config [ ' ALIASES ' ] [ ' TGID_FILE ' ] , _config [ ' ALIASES ' ] [ ' TGID_URL ' ] , _config [ ' ALIASES ' ] [ ' STALE_TIME ' ] )
logger . info ( ' (ALIAS) %s ' , result )
logger . info ( ' (ALIAS) %s ' , result )
#Try updating server ids file
result = try_download ( _config [ ' ALIASES ' ] [ ' PATH ' ] , _config [ ' ALIASES ' ] [ ' SERVER_ID_FILE ' ] , _config [ ' ALIASES ' ] [ ' SERVER_ID_URL ' ] , _config [ ' ALIASES ' ] [ ' STALE_TIME ' ] )
logger . info ( ' (ALIAS) %s ' , result )
# Make Dictionaries
# Make Dictionaries
@ -1420,10 +1445,13 @@ def mk_aliases(_config):
local_subscriber_ids = mk_id_dict ( _config [ ' ALIASES ' ] [ ' PATH ' ] , _config [ ' ALIASES ' ] [ ' LOCAL_SUBSCRIBER_FILE ' ] )
local_subscriber_ids = mk_id_dict ( _config [ ' ALIASES ' ] [ ' PATH ' ] , _config [ ' ALIASES ' ] [ ' LOCAL_SUBSCRIBER_FILE ' ] )
if subscriber_ids :
if subscriber_ids :
logger . info ( ' (ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available ' )
logger . info ( ' (ALIAS) ID ALIAS MAPPER: local_subscriber_ids dictionary is available ' )
server_ids = mk_server_dict ( _config [ ' ALIASES ' ] [ ' PATH ' ] , _config [ ' ALIASES ' ] [ ' SERVER_ID_FILE ' ] )
if server_ids :
logger . info ( ' (ALIAS) ID ALIAS MAPPER: server_ids dictionary is available ' )
return peer_ids , subscriber_ids , talkgroup_ids , local_subscriber_ids
return peer_ids , subscriber_ids , talkgroup_ids , local_subscriber_ids , server_ids
#************************************************
#************************************************