This commit is contained in:
Cort Buffington 2017-05-15 14:55:06 -05:00
parent a8703e058c
commit 04ce07dc24
13 changed files with 44 additions and 64538 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ sub_acl.py
*.config *.config
*.json *.json
*.pickle *.pickle
*.csv

View File

@ -418,10 +418,10 @@ class confReportFactory(reportFactory):
if __name__ == '__main__': if __name__ == '__main__':
import argparse #import argparse
import os #import os
import signal #import signal
from dmr_utils.utils import try_download, mk_id_dict #from dmr_utils.utils import try_download, mk_id_dict
import dmrlink_log import dmrlink_log
import dmrlink_config import dmrlink_config

View File

@ -25,17 +25,11 @@
from __future__ import print_function from __future__ import print_function
import ConfigParser # Full imports
import argparse
import sys
import csv
import os
import logging import logging
import signal
import cPickle as pickle import cPickle as pickle
from logging.config import dictConfig # Function Imports
from hmac import new as hmac_new from hmac import new as hmac_new
from binascii import b2a_hex as ahex from binascii import b2a_hex as ahex
from binascii import a2b_hex as bhex from binascii import a2b_hex as bhex
@ -44,15 +38,18 @@ from socket import inet_ntoa as IPAddr
from socket import inet_aton as IPHexStr from socket import inet_aton as IPHexStr
from time import time from time import time
# Twisted Imports
from twisted.internet.protocol import DatagramProtocol, Factory, Protocol from twisted.internet.protocol import DatagramProtocol, Factory, Protocol
from twisted.protocols.basic import NetstringReceiver from twisted.protocols.basic import NetstringReceiver
from twisted.internet import reactor, task from twisted.internet import reactor, task
from ipsc.ipsc_const import * # Imports from our static file directory
from ipsc.ipsc_mask import * from dmrlink.ipsc_const import *
from ipsc.reporting_const import * from dmrlink.ipsc_mask import *
from dmrlink_config import build_config from dmrlink.reporting_const import *
from dmrlink_log import config_logging from dmrlink.dmrlink_config import build_config
from dmrlink.dmrlink_log import config_logging
from dmr_utils.utils import hex_str_2, hex_str_3, hex_str_4, int_id from dmr_utils.utils import hex_str_2, hex_str_3, hex_str_4, int_id
@ -67,21 +64,24 @@ __email__ = 'n0mjs@me.com'
# Global variables used whether we are a module or __main__ # Global variables used whether we are a module or __main__
systems = {} systems = {}
# Shut ourselves down gracefully with the IPSC peers.
#
def sig_handler(_signal, _frame):
logger.info('*** DMRLINK IS TERMINATING WITH SIGNAL %s ***', str(_signal))
for system in systems:
this_ipsc = systems[system]
logger.info('De-Registering from IPSC %s', system)
de_reg_req_pkt = this_ipsc.hashed_packet(this_ipsc._local['AUTH_KEY'], this_ipsc.DE_REG_REQ_PKT)
this_ipsc.send_to_ipsc(de_reg_req_pkt)
reactor.stop()
# Timed loop used for reporting IPSC status # Timed loop used for reporting IPSC status
# #
# REPORT BASED ON THE TYPE SELECTED IN THE MAIN CONFIG FILE # REPORT BASED ON THE TYPE SELECTED IN THE MAIN CONFIG FILE
def config_reports(_config): def config_reports(_config):
if _config['REPORTS']['REPORT_NETWORKS'] == 'PICKLE': if _config['REPORTS']['REPORT_NETWORKS'] == 'PRINT':
def reporting_loop(_logger):
_logger.debug('Periodic Reporting Loop Started (PICKLE)')
try:
with open(_config['REPORTS']['REPORT_PATH']+'dmrlink_stats.pickle', 'wb') as file:
pickle.dump(_config['SYSTEMS'], file, 2)
file.close()
except IOError as detail:
_logger.error('I/O Error: %s', detail)
elif _config['REPORTS']['REPORT_NETWORKS'] == 'PRINT':
def reporting_loop(_logger): def reporting_loop(_logger):
_logger.debug('Periodic Reporting Loop Started (PRINT)') _logger.debug('Periodic Reporting Loop Started (PRINT)')
for system in _config['SYSTEMS']: for system in _config['SYSTEMS']:
@ -1003,6 +1003,10 @@ class reportFactory(Factory):
#************************************************ #************************************************
if __name__ == '__main__': if __name__ == '__main__':
import argparse
import sys
import os
import signal
# Change the current directory to the location of the application # Change the current directory to the location of the application
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
@ -1017,44 +1021,29 @@ if __name__ == '__main__':
if not cli_args.CFG_FILE: if not cli_args.CFG_FILE:
cli_args.CFG_FILE = os.path.dirname(os.path.abspath(__file__))+'/dmrlink.cfg' cli_args.CFG_FILE = os.path.dirname(os.path.abspath(__file__))+'/dmrlink.cfg'
# Call the external routine to build the configuration dictionary # Call the external routine to build the configuration dictionary
CONFIG = build_config(cli_args.CFG_FILE) CONFIG = build_config(cli_args.CFG_FILE)
# Call the external routing to start the system logger # Call the external routing to start the system logger
if cli_args.LOG_LEVEL: if cli_args.LOG_LEVEL:
CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL
if cli_args.LOG_HANDLERS: if cli_args.LOG_HANDLERS:
CONFIG['LOGGER']['LOG_HANDLERS'] = cli_args.LOG_HANDLERS CONFIG['LOGGER']['LOG_HANDLERS'] = cli_args.LOG_HANDLERS
logger = config_logging(CONFIG['LOGGER']) logger = config_logging(CONFIG['LOGGER'])
config_reports(CONFIG)
logger.info('DMRlink \'dmrlink.py\' (c) 2013 - 2015 N0MJS & the K0USY Group - SYSTEM STARTING...') logger.info('DMRlink \'dmrlink.py\' (c) 2013 - 2015 N0MJS & the K0USY Group - SYSTEM STARTING...')
# Shut ourselves down gracefully with the IPSC peers.
def sig_handler(_signal, _frame):
logger.info('*** DMRLINK IS TERMINATING WITH SIGNAL %s ***', str(_signal))
for system in systems: # INITIALIZE THE REPORTING LOOP
this_ipsc = systems[system] config_reports(CONFIG)
logger.info('De-Registering from IPSC %s', system)
de_reg_req_pkt = this_ipsc.hashed_packet(this_ipsc._local['AUTH_KEY'], this_ipsc.DE_REG_REQ_PKT) if CONFIG['REPORTS']['REPORT_NETWORKS'] == 'PRINT':
this_ipsc.send_to_ipsc(de_reg_req_pkt)
reactor.stop()
# Set signal handers so that we can gracefully exit if need be
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
signal.signal(sig, sig_handler)
# INITIALIZE THE REPORTING LOOP IF CONFIGURED
if CONFIG['REPORTS']['REPORT_NETWORKS'] == 'PRINT' or CONFIG['REPORTS']['REPORT_NETWORKS'] == 'PICKLE':
reporting_loop = config_reports(CONFIG) reporting_loop = config_reports(CONFIG)
reporting = task.LoopingCall(reporting_loop, logger) reporting = task.LoopingCall(reporting_loop, logger)
reporting.start(CONFIG['REPORTS']['REPORT_INTERVAL']) reporting.start(CONFIG['REPORTS']['REPORT_INTERVAL'])
report_server = False report_server = False
# INITIALIZE THE NETWORK-BASED REPORTING SERVER
elif CONFIG['REPORTS']['REPORT_NETWORKS'] == 'NETWORK': elif CONFIG['REPORTS']['REPORT_NETWORKS'] == 'NETWORK':
logger.info('(confbridge.py) TCP reporting server starting') logger.info('(confbridge.py) TCP reporting server starting')
@ -1072,4 +1061,8 @@ if __name__ == '__main__':
systems[system] = IPSC(system, CONFIG, logger, report_server) systems[system] = IPSC(system, CONFIG, logger, report_server)
reactor.listenUDP(CONFIG['SYSTEMS'][system]['LOCAL']['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['LOCAL']['IP']) reactor.listenUDP(CONFIG['SYSTEMS'][system]['LOCAL']['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['LOCAL']['IP'])
# Set signal handers so that we can gracefully exit if need be
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
signal.signal(sig, sig_handler)
reactor.run() reactor.run()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
1,Worldwide 2,Local 3,North America 9,BrandMeister 13,Worldwide English 310,TAC 310 3100,DCI Bridge 2 3160,DCI 1 3169,Midwest 3172,Northeast 3174,Southeast 3112,Flordia 3120,Kansas Statewide 3125,Massachussetts 3129,Missouri 31201,BYRG KC 3777215,DCI Comm 1 9998,Echo Server
1 1 Worldwide 2 Local 3 North America 9 BrandMeister 13 Worldwide English 310 TAC 310 3100 DCI Bridge 2 3160 DCI 1 3169 Midwest 3172 Northeast 3174 Southeast 3112 Flordia 3120 Kansas Statewide 3125 Massachussetts 3129 Missouri 31201 BYRG KC 3777215 DCI Comm 1 9998 Echo Server