import grp
import glob
import logging
+import email.utils
from LogRotateCommon import split_parts, email_valid, period2days, human2bytes
from LogRotateScript import LogRotateScript
'compressext',
'rotate',
'maxage',
+ 'mailfrom',
+ 'smtphost',
+ 'smtpport',
+ 'smtptls',
+ 'smtpuser',
+ 'smtppasswd',
)
boolean_options = (
global_options = (
'statusfile',
'pidfile',
+ 'mailfrom',
+ 'smtphost',
+ 'smtpport',
+ 'smtptls',
+ 'smtpuser',
+ 'smtppasswd',
)
path_options = (
@ivar: all global options
@type: dict
'''
+ self.global_option['smtphost'] = 'localhost'
#############################################
# the rest of instance variables:
self.default['ifempty'] = True
self.default['mailaddress'] = None
self.default['mailfirst'] = None
+ self.default['mailfrom'] = None
self.default['maxage'] = None
self.default['missingok'] = False
self.default['olddir'] = {
% {'value': val, 'option': key} )
)
return False
+ if key == 'mailfrom':
+ pair = email.utils.parseaddr(val)
+ if not email_valid(pair[1]):
+ msg = _("Invalid mail address for 'mailfrom' given: '%s'.") % (val)
+ self.logger.warning(msg)
+ return False
+ val = pair
+ elif key == 'smtpport':
+ port = 25
+ try:
+ port = int(val)
+ except ValueError, e:
+ msg = _("Invalid SMTP port '%s' given.") % (val)
+ self.logger.warning(msg)
+ return False
+ if port < 1 or port >= 2**15:
+ msg = _("Invalid SMTP port '%s' given.") % (val)
+ self.logger.warning(msg)
+ return False
+ val = port
+ elif key == 'smtptls':
+ use_tls = False
+ match = re.search(r'^\s*(?:0+|false|no?)\s*$', val, re.IGNORECASE)
+ if not match:
+ match = re.search(r'^\s*(?:1|true|y(?:es)?)\s*$', val, re.IGNORECASE)
+ if match:
+ use_tls = True
+ else:
+ use_tls = bool(val)
+ val = use_tls
if self.verbose > 4:
self.logger.debug(
( _("Setting global option '%(option)s' to '%(value)s'. (file '%(file)s', line %(lnr)s)")
self.new_log['ifempty'] = self.default['ifempty']
self.new_log['mailaddress'] = self.default['mailaddress']
self.new_log['mailfirst'] = self.default['mailfirst']
+ self.new_log['mailfrom'] = self.default['mailfrom']
self.new_log['maxage'] = self.default['maxage']
self.new_log['missingok'] = self.default['missingok']
self.new_log['olddir'] = {
)
if self.verbose > 2:
- self.logger.debug( _("Configuration reader object structure")
- + ':\n' + str(config_reader) )
+ msg = _("Configuration reader object structure") + ':\n' + str(config_reader)
+ self.logger.debug(msg)
try:
self.config = config_reader.get_config()
self.logger.error( str(e) )
sys.exit(10)
+ if self.verbose > 2:
+ pp = pprint.PrettyPrinter(indent=4)
+ msg = _("Found global options:") + "\n" + pp.pformat(config_reader.global_option)
+ self.logger.debug(msg)
+
+ # Get and set mailer options
+ if 'mailfrom' in config_reader.global_option and \
+ config_reader.global_option['mailfrom']:
+ self.mailer.from_address = config_reader.global_option['mailfrom']
+ if config_reader.global_option['smtphost'] and \
+ config_reader.global_option['smtphost'] != 'localhost':
+ self.mailer.smtp_host = config_reader.global_option['smtphost']
+ if 'smtpport' in config_reader.global_option:
+ self.mailer.smtp_port = config_reader.global_option['smtpport']
+ if 'smtptls' in config_reader.global_option:
+ self.mailer.smtp_tls = config_reader.global_option['smtptls']
+ if 'smtpuser' in config_reader.global_option:
+ self.mailer.smtp_user = config_reader.global_option['smtpuser']
+ if 'smtppasswd' in config_reader.global_option:
+ self.mailer.smtp_passwd = config_reader.global_option['smtppasswd']
+
if self.state_file_name is None:
if 'statusfile' in config_reader.global_option and \
config_reader.global_option['statusfile'] is not None:
'''
self._init_from_address()
+ self._smtp_host = 'localhost'
+ '''
+ @ivar: the hostname to use for SMTP (smarthost), if no
+ sendmail binary was found
+ @type: str
+ '''
+
+ self._smtp_port = 25
+ '''
+ @ivar: the port to use for SMTP to the smarthost
+ @type: int
+ '''
+
+ self._smtp_tls = False
+ '''
+ @ivar: use TLS for sending via SMTP to smarthost
+ @type: bool
+ '''
+
+ self.smtp_user = None
+ '''
+ @ivar: Authentication username for SMTP
+ @type: str or None
+ '''
+
+ self.smtp_passwd = None
+ '''
+ @ivar: Authentication password for SMTP
+ @type: str or None
+ '''
+
#------------------------------------------------------------
# Defintion of some properties
sendmail = property(_get_sendmail, _set_sendmail, _del_sendmail, "The sendmail executable for sending mails local")
+ #------------------------------------------------------------
+ # Property 'smtp_host'
+ def _get_smtp_host(self):
+ '''
+ Getter method for property 'smtp_host'
+ '''
+ return self._smtp_host
+
+ def _set_smtp_host(self, value):
+ '''
+ Setter method for property 'smtp_host'
+ '''
+ _ = self.t.lgettext
+ if value:
+ self._smtp_host = value
+
+ smtp_host = property(_get_smtp_host, _set_smtp_host, None, "The hostname to use for sending mails via SMTP (smarthost)")
+
+ #------------------------------------------------------------
+ # Property 'smtp_port'
+ def _get_smtp_port(self):
+ '''
+ Getter method for property 'smtp_port'
+ '''
+ return self._smtp_port
+
+ def _set_smtp_port(self, value):
+ '''
+ Setter method for property 'smtp_port'
+ '''
+ _ = self.t.lgettext
+ if value:
+ port = 25
+ try:
+ port = int(value)
+ except ValueError, e:
+ return
+ if port < 1 or port >= 2**15:
+ return
+ self._smtp_port = port
+
+ smtp_port = property(_get_smtp_port, _set_smtp_port, None, "The port to use for sending mails via SMTP")
+
+ #------------------------------------------------------------
+ # Property 'smtp_tls'
+ def _get_smtp_tls(self):
+ '''
+ Getter method for property 'smtp_tls'
+ '''
+ return self._smtp_tls
+
+ def _set_smtp_tls(self, value):
+ '''
+ Setter method for property 'smtp_tls'
+ '''
+ self._smtp_tls = bool(value)
+
+ smtp_tls = property(_get_smtp_tls, _set_smtp_tls, None, "Use TLS for sending mails via SMTP (smarthost)")
+
#------------------------------------------------------------
# Other Methods
_ = self.t.lgettext
if self.verbose > 2:
- msg = _("Mailer script object will destroyed.")
+ msg = _("Mailer object will destroyed.")
self.logger.debug(msg)
#------------------------------------------------------------
'''
res = {}
- res['t'] = self.t
- res['verbose'] = self.verbose
- res['test_mode'] = self.test_mode
- res['logger'] = self.logger
- res['sendmail'] = self.sendmail
- res['from'] = self.from_address
+ res['t'] = self.t
+ res['verbose'] = self.verbose
+ res['test_mode'] = self.test_mode
+ res['logger'] = self.logger
+ res['sendmail'] = self.sendmail
+ res['from'] = self.from_address
+ res['smtp_host'] = self.smtp_host
+ res['smtp_port'] = self.smtp_port
+ res['smtp_tls'] = self.smtp_tls
+ res['smtp_user'] = self.smtp_user
+ res['smtp_passwd'] = self.smtp_passwd
return res
msgid "Value '%(value)s' for option '%(option)s' is not an absolute path."
msgstr "Der Wert »%(value)s« für die Option »%(option)s« ist keine absolute Pfadangabe."
+#: LogRotateConfig.py:1175
+#, python-format
+msgid "Invalid mail address for 'mailfrom' given: '%s'."
+msgstr "Ungültige Mailadresse »%s« für »mailfrom« angegeben."
+
+#: LogRotateConfig.py:1184 LogRotateConfig.py:1188
+#, python-format
+msgid "Invalid SMTP port '%s' given."
+msgstr "Ungültiger SMTP-Port »%s« angegeben."
+
#: LogRotateConfig.py:1083
msgid "Setting global option '%(option)s' to '%(value)s'. (file '%(file)s', line %(lnr)s)"
msgstr ""
msgid "Value '%(value)s' for option '%(option)s' is not an absolute path."
msgstr ""
+#: LogRotateConfig.py:1175
+#, python-format
+msgid "Invalid mail address for 'mailfrom' given: '%s'."
+msgstr ""
+
+#: LogRotateConfig.py:1184 LogRotateConfig.py:1188
+#, python-format
+msgid "Invalid SMTP port '%s' given."
+msgstr ""
+
#: LogRotateConfig.py:1083
#, python-format
msgid "Setting global option '%(option)s' to '%(value)s'. (file '%(file)s', line %(lnr)s)"
msgid "Configuration reader object structure"
msgstr "Objektstruktur des Konfigurtionslesers"
+#: LogRotateHandler.py:459
+msgid "Found global options:"
+msgstr "Gefundene globale Optionen:"
+
#: LogRotateHandler.py:452
#, python-format
msgid "Name of state file: '%s'"
msgid "Configuration reader object structure"
msgstr ""
+#: LogRotateHandler.py:459
+msgid "Found global options:"
+msgstr ""
+
#: LogRotateHandler.py:452
#, python-format
msgid "Name of state file: '%s'"
pidfile /home/frank/Development/Python/PyLogrotate/logrotate.pid
statusfile /home/frank/Development/Python/PyLogrotate/logrotate.status
+mailfrom ich <info@uhu-banane.de>
+smtphost mail.brehm-online.com
+smtpport 25
+smtpuser vmail
+smtppasswd bla
+smtptls true
script apache_restart
echo "/etc/init.d/apache2 reload > /dev/null 2>&1 || true"