예제 #1
0
class CertChecker( object ):

   def __init__( self ):
      self.ssh  = SSHConnector( )
      self.conf = Configurator( '/etc//cfg/cert-checker.cfg', 'cert-checker' )
      mailto    = self.conf.getValue('MAILTO').split(',')
      self.mail = Mailer( self.conf.getValue('MAILFROM'), mailto, self.conf.getValue('SMTPRELAY') )

   def __processDays( self ):
      files    = self.conf.getValue('REMOTE_FILES')
      files    = files.split(',')
      server   = self.conf.getValue('SERVER')
      server   = server.split(',')
      server   = Server( server[0], server[1], server[2], server[3], server[4] )
      tmp      = self.conf.getValue('TMP')
      contents = list()

      for file in files:
         self.ssh.getFile( server, file, "%s/" % tmp )
         cont_tmp = open("%s" % file, 'r' )
         expiring = list()

         for line in cont_tmp:
            line = line.strip()
            line = line.split( '|' )
            if int( line[1] ) < int( self.conf.getValue('DAYS') ):
               expiring.append( {'name':line[0], 'days':line[1]} )

         contents.append( { '%s' % (file): expiring } ) 

      return contents

   def startCheck( self ):
      expiring = self.__processDays()
      subject  = "Certificates expiration report"
      body     = "This is an automatic report of certificates that are about to expire\n\n"

      for exp in expiring:
         if len( exp[ exp.keys()[0] ] ) > 0:
            title = exp.keys()[0].split('-')[3].split('.')[0]
            body += "%s\n" % title
            for cert in exp[ exp.keys()[0] ]:
               if int( cert['days'] ) < 0:
                  body += " !! CERTIFICATE EXPIRED %s\n\n" % cert['name']
               else:
                  body += " W CERTIFICATE %s EXPIRES IN %s DAYS\n\n" % ( cert['name'], cert['days'] )

      body += "\n\n\n\nThis email will be sent every Monday at morning\n\n"
      body += "Recipients: %s\n" % self.conf.getValue('MAILTO')

      self.mail.sendMail( subject, body )
예제 #2
0
class LoroReceiver( object ):

   def __init__(self):
      self.c = Configurator('/etc/core/cfg/lororeceiver.cfg', 'lororeceiver')
      self.l = Logger(self.c.getValue('FILELOG'), self.c.getValue('SYSTEM'), self.c.getValue('DEBUG'))

   def __searchKeyword(self, standardinput):
      self.l.addInfoLine("El cuerpo del email es el correcto?")
      process = standardinput.split(' ')

      for line in process:
         if re.search('Good_Auto_Response', line):
            return True

      return False

   def __isFromGranted(self, standardinput):
      self.l.addInfoLine('Es de un sender permitido?')
      process = standardinput.split('|')
      FROM    = None

      for line in process:
         if re.search('From ', line):
            FROM = line.split('From ')[1]
            FROM = FROM.split('  ')[0]
            break

      accepted_from = self.c.getValue('ACCEPTEDFROM').split('|')

      for user_from in accepted_from:
         if FROM == user_from:
            self.l.addInfoLine('Si lo es')
            return True

      self.l.addInfoLine('No lo es')
      return False

   def __storeValue(self, value):
      file_pointer = open(self.c.getValue('STATEFILE'),'w')
      self.l.addInfoLine('Valor storeado: %s' % value)
      file_pointer.write(value)
      file_pointer.close()

   def main(self):
      self.l.addInfoLine('--------------')
      self.__storeValue("0")
      EMAIL_buffer = sys.stdin.read()
      self.l.addInfoLine('Email Received')

      self.addInfoLine(EMAIL_buffer)

      if self.__isFromGranted(EMAIL_buffer):
         self.l.addInfoLine("Sender accepted")
         if self.__searchKeyword(EMAIL_buffer):
            self.l.addInfoLine("El cuerpo es correcto")
            self.__storeValue("1")
         else:
            self.l.addWarningLine("El cuerpo incorrecto")
            self.__storeValue("0")

      self.l.addInfoLine('--------------')
예제 #3
0
파일: ack.py 프로젝트: gaccardo/stuff
class ACK( object ):

   def __init__(self):
      self.c = Configurator('/etc//cfg/ack.conf', 'ack')
      self.l = Logger(self.c.getValue('FILE_LOG'), self.c.getValue('NAME'), self.c.getValue('DEBUG'))
      self.z = ZabbixDB(self.l, self.c.getValue('DB_HOST'), self.c.getValue('DB_USER'), self.c.getValue('DB_PASS'), self.c.getValue('DB_NAME'))

   def __checkUserPIN(self, pin, ffrom):
      users_raw = self.c.getValue('USERS')
      users_lines = users_raw.split(',')

      for user in users_lines:
         self.l.addInfoLine("%s :: %s" % ( user.split('|')[0], user.split('|')[1] ))
         if user.split('|')[0] == ffrom and user.split('|')[1] == pin:
             return True

      return False

   def __clearSubject(self, subject, pipes):
      if pipes:
          self.l.addInfoLine(subject)

          try:
             filtered = subject.split('|')
             self.l.addInfoLine(filtered[0])

             return filtered[1]
          except:
             self.l.addWarningLine('El subject esta mal formado')
         
          return "Mal formed subject"
      else:
          return subject

   def __sendEmail(self, user, subject, type):
      self.m = Mailer('[email protected]', self.c.getValue('MAIL_TO'), self.c.getValue('RELAY'))
      self.m.sendMail("ACK: %s" % self.__clearSubject(subject, type), "ACK Message: %s" % self.__clearSubject(subject, type))
      self.l.addInfoLine('Email Sended to itnetworking')

      self.m = Mailer('[email protected]', user, self.c.getValue('RELAY'))
      self.m.sendMail("ACK: %s" % self.__clearSubject(subject, type), "ACK Message: %s" % self.__clearSubject(subject, type))
      self.l.addInfoLine('Email Sended to %s' % user)

   def __isException(self, e_from):
      filtered = e_from.split('|')

      for email in filtered:
         if email == e_from:
            return True

      return False
      
   def main(self):
      stdin_raw   = sys.stdin.read()
      stdin_lines = stdin_raw.split('\n')
      KEY         = None
      PIN         = ""
      FROM        = ""
      ACK         = False

      self.l.addInfoLine('---------------------------------')
      for line in stdin_lines:

         if re.search('From ', line):
             FROM = line.split('From ')[1]
             FROM = FROM.split('  ')[0]
             self.l.addInfoLine("From: %s" % FROM)

         if re.search('Subject: ', line):
             SUBJECT = line.split('Subject: ')[1]
             self.l.addInfoLine("Subject: %s" % SUBJECT)
             ack_key = SUBJECT.split(' ')[0]

             if ack_key == 'ACK':
                PIN = SUBJECT.split(' ')[1]
                self.l.addInfoLine("ACK PIN: %s" % PIN)
                ACK = True

         if re.search('KEY: ', line):
             if KEY is None:
                 KEY = line.split('KEY: ')[1]
                 self.l.addInfoLine('KEY: %s' % KEY)

      if ACK:
         if not self.__checkUserPIN(PIN, FROM):
            self.l.addWarningLine('Invalid PIN/USER combination')
            self.l.addWarningLine('User %s has given an incorrect PIN %s' % (FROM, PIN))
            self.__sendEmail(FROM, "USER %s has given an incorrect PIN %s" % (FROM, PIN), False)
         else:
            self.l.addInfoLine('PIN/USER ACCEPTED')

            if self.z.ACK( KEY ):
               self.l.addInfoLine('ACK OK')
               self.__sendEmail(FROM, "ACK! %s" % SUBJECT, True)
            else:
               self.l.addErrorLine('ACK ERROR')

      else:
            if not self.__isException(FROM):
               self.__sendEmail(FROM, "WARNING USER %s MALFORMED EMAIL" % FROM, False)
         
      self.l.addInfoLine('---------------------------------')