ail-framework/bin/Mail.py

92 lines
2.7 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python
# -*-coding:UTF-8 -*
"""
The CreditCards Module
======================
This module is consuming the Redis-list created by the Categ module.
It apply mail regexes on paste content and warn if above a threshold.
"""
2014-08-14 15:55:18 +00:00
import redis
import pprint
import time
2014-08-11 07:27:50 +00:00
import dns.exception
2014-08-20 13:14:57 +00:00
from packages import Paste
from packages import lib_refine
from pubsublogger import publisher
from Helper import Process
2014-08-20 13:14:57 +00:00
if __name__ == "__main__":
publisher.port = 6380
2014-08-20 13:14:57 +00:00
publisher.channel = "Script"
2014-08-14 15:55:18 +00:00
config_section = 'Mail'
p = Process(config_section)
2014-08-20 13:14:57 +00:00
# REDIS #
r_serv2 = redis.StrictRedis(
host=p.config.get("Redis_Cache", "host"),
port=p.config.getint("Redis_Cache", "port"),
db=p.config.getint("Redis_Cache", "db"))
# FUNCTIONS #
publisher.info("Suscribed to channel mails_categ")
# FIXME For retro compatibility
channel = 'mails_categ'
message = p.get_from_set()
prec_filename = None
2014-08-20 13:14:57 +00:00
# Log as critical if there are more that that amout of valid emails
is_critical = 10
email_regex = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}"
2014-09-04 09:46:07 +00:00
MX_values = None
while True:
2014-09-04 09:46:07 +00:00
if message is not None:
2014-09-05 15:05:45 +00:00
filename, score = message.split()
2014-09-04 09:46:07 +00:00
if prec_filename is None or filename != prec_filename:
PST = Paste.Paste(filename)
MX_values = lib_refine.checking_MX_record(
r_serv2, PST.get_regex(email_regex))
if MX_values[0] >= 1:
PST.__setattr__(channel, MX_values)
PST.save_attribute_redis(channel, (MX_values[0],
list(MX_values[1])))
pprint.pprint(MX_values)
to_print = 'Mails;{};{};{};Checked {} e-mail(s);{}'.\
2014-09-04 09:46:07 +00:00
format(PST.p_source, PST.p_date, PST.p_name,
MX_values[0], PST.p_path)
2014-09-04 09:46:07 +00:00
if MX_values[0] > is_critical:
publisher.warning(to_print)
#Send to duplicate
p.populate_set_out(filename, 'Duplicate')
p.populate_set_out('mail;{}'.format(filename), 'alertHandler')
2014-09-04 09:46:07 +00:00
else:
publisher.info(to_print)
#Send to ModuleStats
for mail in MX_values[1]:
print 'mail;{};{};{}'.format(1, mail, PST.p_date)
p.populate_set_out('mail;{};{};{}'.format(1, mail, PST.p_date), 'ModuleStats')
2014-09-04 09:46:07 +00:00
prec_filename = filename
else:
publisher.debug("Script Mails is Idling 10s")
print 'Sleeping'
time.sleep(10)
message = p.get_from_set()