Exemple #1
0
    def execute(self):
        try:
            self.backup_resources()
        except Exception:
            # Replace mysqldump password if existed
            stack = re.sub('\-\-password=.*\-\-default\-character\-set=',
                           '--password=?????\', \'--default-charcter-set=',
                           traceback.format_exc(),
                           flags=re.MULTILINE)
            print(stack)

            # Send mail if some error occured
            if 'mail_recipient_address' in self.config:
                mail = Mail(self.config)
                mail.send(
                    os.path.basename(__file__) + " encountered an error\n",
                    stack)
        finally:
            # Restore LocalSettings if succeeded
            if not self.backup_local_settings_file == None:
                print("Restoreing LocalSettings file")
                shutil.copyfile(self.backup_local_settings_file,
                                self.current_local_settings_file)
                os.remove(self.backup_local_settings_file)
    def execute(self):
        try:
            self.backup_resources()
        except Exception:
            # Replace mysqldump password if existed
            stack = re.sub('\-\-password=.*\-\-default\-character\-set='
                    , '--password=?????\', \'--default-charcter-set='
                    , traceback.format_exc()
                    , flags=re.MULTILINE)
            print(stack)

            # Send mail if some error occured
            if 'mail_recipient_address' in self.config:
                mail = Mail(self.config)
                mail.send(
                    os.path.basename(__file__) + " encountered an error\n"
                    , stack)
        finally:
            # Restore LocalSettings if succeeded
            if not self.backup_local_settings_file == None:
                print("Restoreing LocalSettings file")
                shutil.copyfile(
                        self.backup_local_settings_file, self.current_local_settings_file)
                os.remove(self.backup_local_settings_file)
Exemple #3
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)
Exemple #4
0
    # read config
    configObj = Config(BASE_PATH)
    logObj = Log(configObj)
    logger = logObj.get_logger()

    #debug print
    logger.debug('MAIL_ENABLE {}'.format(configObj.MAIL_ENABLE))
    logger.debug('MAIL_TO {}'.format(configObj.MAIL_TO))
    logger.debug('MAIL_USER {}'.format(configObj.MAIL_USER))
    logger.debug('MAIL_HOST {}'.format(configObj.MAIL_HOST))
    logger.debug('MAIL_PORT {}'.format(configObj.MAIL_PORT))
    logger.debug('LOG_PATH {}'.format(configObj.LOG_PATH))
    logger.debug('LOG_FILE {}'.format(configObj.LOG_FILE))
    logger.debug('LOG_MAX_SIZE {}'.format(configObj.LOG_MAX_SIZE))
    logger.debug('LOG_BACKUP_COUNT {}'.format(configObj.LOG_BACKUP_COUNT))

    # argc check
    if len(sys.argv) != 2:
        logger.error('Need User')
        sys.exit(configObj.ERROR_PROC_EXIST)

    sysuser = sys.argv[1]

    # initial ddnsObj
    mailObj = Mail(configObj, logger, sysuser)
    mailObj.send()

    # success exit
    sys.exit(configObj.SUCCESS_EXIT)