mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 07:33:27 -06:00
IPA-EPN: Add mail-test option for testing sending live email
To make testing easier for administrators the --mail-test option can be used to send live e-mail from ipa-epn. It sends mail to the smtp_admin user processing the template with dummy data. https://pagure.io/freeipa/issue/3687 Signed-off-by: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Francois Cami <fcami@redhat.com>
This commit is contained in:
parent
41e3d58a0b
commit
a2728c758e
@ -66,6 +66,10 @@ Specifies the number of seconds to wait for SMTP to respond. Default 60.
|
||||
.B smtp_security <security>
|
||||
Specifies the type of secure connection to make. Options are: none, starttls and ssl. The default is none.
|
||||
.TP
|
||||
.B smtp_admin <address>
|
||||
Specifies the From e-mail address value in the e-mails sent. The default is
|
||||
root@localhost. Bounces will be sent here.
|
||||
.TP
|
||||
.B mail_from <address>
|
||||
Specifies the From: e-mal address value in the e-mails sent. The default is
|
||||
noreply@ipadefaultemaildomain. This value can be found by running
|
||||
|
@ -51,6 +51,12 @@ See \fB\-\-to\-nbdays\fR for an explanation. This option must be used in conjonc
|
||||
The \fB\-\-dry\-run\fR CLI option is intented to test ipa\-epn's configuration.
|
||||
|
||||
For instance, if notify_ttls is set to 21, 14, 3, \fB\-\-dry-run\fR would display the list of users whose passwords would expire in 21, 14, and 3 days in the future.
|
||||
.TP
|
||||
\fB\-\-mail\-test\fR
|
||||
The \fB\-\-mail\-test\fR CLI option will send an e-mail to the configured
|
||||
smtp_admin value in /etc/ipa/epn.conf. Generic values for the substitution
|
||||
variables are set so this is also useful for testing and configuring the
|
||||
mail template.
|
||||
|
||||
.SH "TEMPLATE"
|
||||
The template for the e\-mail message is contained in /etc/ipa/epn/expire_msg.template. The following template variables are available.
|
||||
|
@ -226,6 +226,13 @@ class EPN(admintool.AdminTool):
|
||||
default=False,
|
||||
help="Dry run mode. JSON ouput only.",
|
||||
)
|
||||
parser.add_option(
|
||||
"--mail-test",
|
||||
dest="mailtest",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Send a test e-mail",
|
||||
)
|
||||
|
||||
def validate_options(self):
|
||||
super(EPN, self).validate_options(needs_root=True)
|
||||
@ -235,6 +242,10 @@ class EPN(admintool.AdminTool):
|
||||
self.option_parser.error(
|
||||
"You cannot specify --from-nbdays without --to-nbdays"
|
||||
)
|
||||
if self.options.mailtest and self.options.dry_run:
|
||||
self.option_parser.error(
|
||||
"You cannot specify --mail-test and --dry-run together"
|
||||
)
|
||||
|
||||
def setup_logging(self, log_file_mode="a"):
|
||||
super(EPN, self).setup_logging(log_file_mode="a")
|
||||
@ -254,11 +265,14 @@ class EPN(admintool.AdminTool):
|
||||
self._get_connection()
|
||||
self._read_ipa_configuration()
|
||||
drop_privileges()
|
||||
if self.options.to_nbdays:
|
||||
self._build_cli_date_ranges()
|
||||
for date_range in self._date_ranges:
|
||||
self._fetch_data_from_ldap(date_range)
|
||||
self._parse_ldap_data()
|
||||
if self.options.mailtest:
|
||||
self._gentestdata()
|
||||
else:
|
||||
if self.options.to_nbdays:
|
||||
self._build_cli_date_ranges()
|
||||
for date_range in self._date_ranges:
|
||||
self._fetch_data_from_ldap(date_range)
|
||||
self._parse_ldap_data()
|
||||
if self.options.dry_run:
|
||||
self._pretty_print_data()
|
||||
else:
|
||||
@ -499,6 +513,20 @@ class EPN(admintool.AdminTool):
|
||||
expdate)
|
||||
self._mailer.cleanup()
|
||||
|
||||
def _gentestdata(self):
|
||||
"""Generate a sample user to process through the template.
|
||||
"""
|
||||
expdate = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
|
||||
entry = dict(
|
||||
uid=["SAUSER"],
|
||||
cn=["SAMPLE USER"],
|
||||
givenname=["SAMPLE"],
|
||||
sn=["USER"],
|
||||
krbpasswordexpiration=[expdate],
|
||||
mail=[api.env.smtp_admin],
|
||||
)
|
||||
self._expiring_password_user_list.add(entry)
|
||||
|
||||
def _build_cli_date_ranges(self):
|
||||
"""When self.options.to_nbdays is set, override the date ranges read
|
||||
from the configuration file and build the date ranges from the CLI
|
||||
|
Loading…
Reference in New Issue
Block a user