def update_generic(sender, revert=False): """ overrites the contents of /etc/postfix/generic with the following mapping @<hostname> <sender-email-address> @<hostname>.localdomain <sender-email-address> Then sets the file permissions and runs "postmap generic" to create the db file and change it's permissions in turn. :param sender: email address entered as the sender email account :param revert: if True wipe the generic_file and db (defaults to 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)) # 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])
def _update_hostname(): a = Appliance.objects.get(current_appliance=True) cur_hostname = gethostname() if (cur_hostname != a.hostname): a.hostname = cur_hostname if (a.ipaddr != a.ip): a.ip = a.ipaddr a.save()
def _update_hostname(): a = Appliance.objects.get(current_appliance=True) cur_hostname = gethostname() if cur_hostname != a.hostname: a.hostname = cur_hostname if a.ipaddr != a.ip: a.ip = a.ipaddr a.save()
def email_root(subject, message): """ Simple wrapper to email root, which generally will be forwarded to admin personnel if email notifications are enabled hence acting as remote monitor / notification system :param subject: of the email :param message: body content of the email """ hostname = gethostname() msg = MIMEMultipart() msg["From"] = "notifications@%s" % hostname msg["To"] = "root@%s" % hostname msg["Date"] = formatdate(localtime=True) msg["Subject"] = subject msg.attach(MIMEText(message)) smtp = smtplib.SMTP("localhost") smtp.sendmail(msg["From"], msg["To"], msg.as_string()) smtp.close()
def email_root(subject, message): """ Simple wrapper to email root, which generally will be forwarded to admin personnel if email notifications are enabled hence acting as remote monitor / notification system :param subject: of the email :param message: body content of the email """ hostname = gethostname() msg = MIMEMultipart() msg['From'] = 'notifications@%s' % hostname msg['To'] = 'root@%s' % hostname msg['Date'] = formatdate(localtime=True) msg['Subject'] = subject msg.attach(MIMEText(message)) smtp = smtplib.SMTP('localhost') smtp.sendmail(msg['From'], msg['To'], msg.as_string()) smtp.close()
def update_generic(sender, revert=False): """ overrites the contents of /etc/postfix/generic with the following mapping @<hostname> <sender-email-address> @<hostname>.localdomain <sender-email-address> Then sets the file permissions and runs "postmap generic" to create the db file and change it's permissions in turn. :param sender: email address entered as the sender email account :param revert: if True wipe the generic_file and db (defaults to False) :return: """ generic_file = '/etc/postfix/generic' hostname = gethostname() with open(generic_file, 'w') as fo: if (not revert): fo.write('@%s %s\n' % (hostname, sender)) fo.write('@%s.localdomain %s\n' % (hostname, sender)) # todo need an entry here to add @<hostname>.<domain> os.chmod(generic_file, 400) run_command([POSTMAP, generic_file]) os.chmod('%s.db' % generic_file, 600)
def update_generic(sender, revert=False): """ overrites the contents of /etc/postfix/generic with the following mapping @<hostname> <sender-email-address> @<hostname>.localdomain <sender-email-address> Then sets the file permissions and runs "postmap generic" to create the db file and change it's permissions in turn. :param sender: email address entered as the sender email account :param revert: if True wipe the generic_file and db (defaults to False) :return: """ generic_file = '/etc/postfix/generic' hostname = gethostname() with open(generic_file, 'w') as fo: if (not revert): fo.write('@%s %s\n' % (hostname, sender)) fo.write('@%s.localdomain %s\n' %(hostname, sender)) # todo need an entry here to add @<hostname>.<domain> os.chmod(generic_file, 0400) run_command([POSTMAP, generic_file]) os.chmod('%s.db' % generic_file, 0600)
def update_generic(sender, revert=False): """ overrites the contents of /etc/postfix/generic with the following mapping @<hostname> <sender-email-address> @<hostname>.localdomain <sender-email-address> Then sets the file permissions and runs "postmap generic" to create the db file and change it's permissions in turn. :param sender: email address entered as the sender email account :param revert: if True wipe the generic_file and db (defaults to False) :return: """ hostname = gethostname() 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> # Set file to r-- --- --- (400) via stat constants. os.chmod(GENERIC, stat.S_IRUSR) run_command([POSTMAP, GENERIC]) # Set file to rw- --- --- (600) via stat constants. os.chmod("{}.db".format(GENERIC), stat.S_IRUSR | stat.S_IWUSR)
def _update_hostname(): a = Appliance.objects.get(current_appliance=True) cur_hostname = gethostname() if (cur_hostname != a.hostname): a.hostname = cur_hostname a.save()