Exemple #1
0
def dumpPacket(pkt, filePath, pktType = None):
	"""Dump packet into file
		Input: (packet or dict) packet, must contain __str__ method
			(string) path to file
		Output: none
	"""
	# check directory
	dirPath = dirname(filePath)
	if not misc.checkDir(dirPath):
		error('Directory %s not available for logging' % dirPath)
		return
		
	# dump packet to file
	try:
		debug ('Dumping packet to file:\n', filePath)
		file = open(filePath, 'a+')
		if pktType == PACKET_TYPE_ACCT:
			pktStr = acctPacketToStr(pkt)
		elif pktType == PACKET_TYPE_AUTH:
			pktStr = authPacketToStr(pkt)
		else:
			pktStr = packetToStr(pkt)
		file.write(pktStr)
		file.close()
	except:
		error('Can not dump packet to file "%s"' % filePath)
		misc.printExceptionError()
Exemple #2
0
# open log file
if main_config['PATHS']['server_log_file'] and main_config['SERVER'][
        'log_to_file']:
    logDirPath = main_config['PATHS']['log_dir']
    logFilePath = main_config['PATHS']['server_log_file']
    info('--- Opening log file ---')
    # check and/or create log directory
    if not misc.checkDir(logDirPath, user=user, group=group):
        misc.quit("Checking %s directory failed" % logDirPath, 1)
    # open file
    try:
        logging.logFile = open(logFilePath, 'a+')
        misc.setOwner(logFilePath, user, group)
    except:
        misc.printExceptionError()
        quit('Can not open logfile')

# parse dictionaries
info('--- Parsing dictionary files ---')
dict = dictionary.Dictionary('dictionaries/dictionary')

# connect to database
if main_config['DATABASE']['enable']:
    info('--- Connecting to database ---')
    # set driver name
    if main_config['DATABASE']['type'] == 'postgresql':
        DatabaseConnection.dbadapterName = 'psycopg'
    else:
        DatabaseConnection.dbadapterName = 'MySQLdb'
Exemple #3
0
misc.makePidfile()

# open log file
if main_config['PATHS']['server_log_file'] and main_config['SERVER']['log_to_file']:
	logDirPath = main_config['PATHS']['log_dir']
	logFilePath = main_config['PATHS']['server_log_file']
	info ('--- Opening log file ---')
	# check and/or create log directory
	if not misc.checkDir(logDirPath, user = user, group = group):
		misc.quit("Checking %s directory failed" % logDirPath, 1)
	# open file
	try:
		logging.logFile = open(logFilePath, 'a+')
		misc.setOwner(logFilePath, user, group)
	except:
		misc.printExceptionError()
		quit('Can not open logfile')

# parse dictionaries
info ('--- Parsing dictionary files ---')
dict = dictionary.Dictionary('dictionaries/dictionary')

# connect to database
if main_config['DATABASE']['enable']:
	info ('--- Connecting to database ---')
	# set driver name
	if main_config['DATABASE']['type'] == 'postgresql':
		DatabaseConnection.dbadapterName = 'psycopg'
	else:
		DatabaseConnection.dbadapterName = 'MySQLdb'