예제 #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 = misc.acctPacketToStr(pkt)
        elif pktType == PACKET_TYPE_AUTH:
            pktStr = misc.authPacketToStr(pkt)
        else:
            pktStr = misc.packetToStr(pkt)
        file.write(pktStr)
        file.close()
    except:
        error('Can not dump packet to file "%s"' % filePath)
        misc.printExceptionError()
예제 #2
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 = misc.acctPacketToStr(pkt)
		elif pktType == PACKET_TYPE_AUTH:
			pktStr = misc.authPacketToStr(pkt)
		else:
			pktStr = misc.packetToStr(pkt)
		file.write(pktStr)
		file.close()
	except:
		error('Can not dump packet to file "%s"' % filePath)
		misc.printExceptionError()
예제 #3
0
    def ProcessAcctPacket(self, pkt):
        #debug (pkt)
        received = dict(pkt)
        debug(misc.acctPacketToStr(received))

        # wait for accounting modules to process the request
        acctModulesResult = modules.execAccountingModules(received)
        if acctModulesResult == modules.MODULE_OK:
            info('===\n')
            info('Accounting successful')
        else:
            info('===\n')
            info('Accounting failed')
            dumpPacket.dumpFailedAcctPacket(received)
예제 #4
0
	def ProcessAcctPacket(self, pkt):
		#debug (pkt)
		received = dict(pkt)
		debug (misc.acctPacketToStr(received))
		
		# wait for accounting modules to process the request
		acctModulesResult = modules.execAccountingModules(received)
		if acctModulesResult == modules.MODULE_OK:
			info ('===\n')
			info ('Accounting successful')
		else:
			info ('===\n')
			info ('Accounting failed')
			dumpPacket.dumpFailedAcctPacket(received)
예제 #5
0
	def testAcctPacketToStr(self):
		output = misc.acctPacketToStr(self.acct_pkt)
		self.failUnless(isinstance(output, types.StringTypes))
		self.failUnless(output != '')
예제 #6
0
	def testAcctPacketToStr(self):
		output = misc.acctPacketToStr(self.acct_pkt)
		self.failUnless(isinstance(output, types.StringTypes))
		self.failUnless(output != '')