Exemple #1
0
	def run(self):
		try:
			self.log.clear()

			packet = self.recv()

			self.hosts, self.udp = packet['hosts'], UDP()

			Thread(target=self.loop).start()

			while True:
				if len(self.queue) == 0:
					continue

				packet, targets = self.queue.pop(0), []

				for host in sorted(self.hosts):
					d = {'host': host}

					self.send(d)

					_packet = self.recv()

					if not _packet['allow']:
						continue

					if 'mac' not in self.hosts[host]:
						try:
							mac = ZenTrap.mac(self.hosts[host]['ip'])

							self.hosts[host]['mac'] = mac
						except MacException:
							continue

					packet['dst_mac'] = self.hosts[host]['mac']
					packet['dst_ip'] = self.hosts[host]['ip']

					self.udp.send(packet)

					targets.append(host)

				if len(targets) == 0:
					self.log.info('Trap dropped')
				else:
					to = ', '.join(map(Util.repr, targets))

					if len(targets) > 1:
						to = '(%s)' % to

					self.log.info('Trap sent (%s: %s)' % (Util.repr('To'), to))
		except KeyboardInterrupt:
			pass
Exemple #2
0
	def process_message(self, peer, mailfrom, rcpttos, data):
		ip, _ = peer

		host = Util.hostname(ip)

		fr = '(%s, %s)' % (Util.repr(host), Util.repr(mailfrom))

		fr = '%s: %s' % (Util.repr('From'), fr)

		to = ', '.join(map(Util.repr, rcpttos))

		if len(rcpttos) > 1:
			to = '(%s)' % to

		to = '%s: %s' % (Util.repr('To'), to)

		msg = message_from_string(data)

		subject = Util.repr(msg['Subject'])

		subject = '%s: %s' % (Util.repr('Subject'), subject)

		debug = '(%s, %s, %s)' % (fr, to, subject)

		d = {'host': host}

		self.send(d)

		packet = self.recv()

		if packet['allow']:
			if Mail.send(mailfrom, rcpttos, data):
				self.log.info('Mail sent %s' % debug)
			else:
				self.log.critical('Mail not sent %s' % debug)
		else:
			self.log.info('Mail dropped %s' % debug)