예제 #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()
예제 #2
0
# print config
main_config = Config.main_config
debug(main_config)

# fork and run as daemon
if not main_config['SERVER']['foreground']:
    info('Daemonizing...')
    childProcId = os.fork()
    if childProcId != 0:
        sys.exit(0)

# store pid in file
user = main_config['SERVER']['user']
group = main_config['SERVER']['group']
runDirPath = main_config['PATHS']['run_dir']
if not misc.checkDir(runDirPath, user=user, group=group):
    misc.quit("Checking %s directory failed" % runDirPath, 1)
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+')
예제 #3
0
# print config
main_config = Config.main_config
debug (main_config)

# fork and run as daemon
if not main_config['SERVER']['foreground']:
	info ('Daemonizing...')
	childProcId = os.fork()
	if childProcId != 0:
		sys.exit(0)

# store pid in file
user = main_config['SERVER']['user']
group = main_config['SERVER']['group']
runDirPath = main_config['PATHS']['run_dir']
if not misc.checkDir(runDirPath, user = user, group = group):
	misc.quit("Checking %s directory failed" % runDirPath, 1)
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)