Skip to content

Commit

Permalink
Merge pull request rockstor#2341 from phillxnet/2339_Sender_issues_re…
Browse files Browse the repository at this point in the history
…_notification_emails

Sender issues re notification emails rockstor#2339
  • Loading branch information
phillxnet authored Jan 6, 2022
2 parents 7236dc1 + 08863cb commit 66fc998
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</div>
</form>
<div class="alert alert-success auth-results" id="auth_success" style="display: none;">
<strong>SMTP Authentication was successful</strong> Save your settings
<strong>SMTP Authentication was successful</strong> Submit your settings
</div>
<div class="alert alert-danger auth-results" id="auth_failed" style="display: none;">
<strong>SMTP Authentication failed!</strong> Please update your settings before saving.
Expand Down
15 changes: 12 additions & 3 deletions src/rockstor/storageadmin/views/email_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from storageadmin.serializers import EmailClientSerializer
from storageadmin.util import handle_exception
import rest_framework_custom as rfc
from system.osi import run_command, gethostname, replace_line_if_found
from system.osi import run_command, gethostname, replace_line_if_found, getdnsdomain
from shutil import move
from tempfile import mkstemp
from system.services import systemctl
Expand Down Expand Up @@ -81,6 +81,7 @@ def rockstor_postfix_config(fo, smtp_server, port, revert):
fo.write("smtp_sasl_tls_security_options = noanonymous\n")
fo.write("smtp_generic_maps = lmdb:/etc/postfix/generic\n")
fo.write("{}\n".format(FOOTER))
logger.info("master.cf: adding new configuration")


def update_master():
Expand Down Expand Up @@ -157,11 +158,18 @@ def update_generic(sender, revert=False):
:return:
"""
hostname = gethostname()
dnsdomain = getdnsdomain()
with open(GENERIC, "w") as fo:
if not revert:
fo.write("@{} {}\n".format(hostname, sender))
fo.write("@{}.localdomain {}\n".format(hostname, sender))
# todo need an entry here to add @<hostname>.<domain>
# add @<hostname>.<domain> if we can get a dnsdomain:
if dnsdomain != "":
fo.write("@{}.{} {}\n".format(hostname, dnsdomain, sender))
# Add fall through entries for when the sending agent uses localhost.
# This avoids some bounce scenarios when sender/from is root@localhost
fo.write("@localhost {}\n".format(sender))
fo.write("@localhost.localdomain {}\n".format(sender))
# Set file to r-- --- --- (400) via stat constants.
os.chmod(GENERIC, stat.S_IRUSR)
run_command([POSTMAP, GENERIC])
Expand Down Expand Up @@ -194,6 +202,7 @@ def update_postfix(smtp_server, port, revert=False):
# "inet_protocols = ipv4" as our NetworkManager is ipv4 only.
# Or if we find duplicates of our to-be-installed settings;
if len(line) > 0 and line[0] is not "#":
# TODO: Revert ipv4 only once network config is ipv6 aware.
if re.match("inet_protocols = all", line) is not None:
tfo.write("inet_protocols = ipv4\n")
continue
Expand Down Expand Up @@ -299,7 +308,7 @@ def delete(self, request):
update_postfix("", "", revert=True)
disable_sysconfig_mail()
update_master() # Not needed as no revert but preserves consistency
# Restart ensures sevice is running, even if not running previously.
# Restart ensures service is running, even if not running previously.
systemctl("postfix", "restart")
EmailClient.objects.all().delete()
return Response()
11 changes: 11 additions & 0 deletions src/rockstor/system/osi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
CHATTR = "/usr/bin/chattr"
DD = "/usr/bin/dd"
DEFAULT_MNT_DIR = "/mnt2/"
DNSDOMAIN = "/usr/bin/dnsdomainname"
EXPORTFS = "/usr/sbin/exportfs"
GRUBBY = "/usr/sbin/grubby"
HDPARM = "/usr/sbin/hdparm"
Expand Down Expand Up @@ -880,6 +881,16 @@ def gethostname():
return o[0]


def getdnsdomain():
o, e, rc = run_command([DNSDOMAIN], throw=False, log=True)
if rc != 0:
logger.info(
"Check your network domain configuration. See above error for details."
)
return ""
return o[0]


def is_share_mounted(sname, mnt_prefix=DEFAULT_MNT_DIR):
mnt_pt = mnt_prefix + sname
return mount_status(mnt_pt, RETURN_BOOLEAN)
Expand Down

0 comments on commit 66fc998

Please sign in to comment.