Add MailIgnore option support

This commit is contained in:
Gilles Grandou 2019-10-10 10:52:12 +02:00
parent 7599ec2684
commit 2609ce5f6d
2 changed files with 20 additions and 13 deletions

View File

@ -20,7 +20,7 @@ def load_conf():
global zone_filename, log_filename
global wan_hostname, zone_domain, zone_subdomain
global hosts_list, hosts_ipv4_nat_list, hosts_alias_list
global mail_from, mail_to
global mail_from, mail_to, mail_ignore_list
conf = configparser.ConfigParser(allow_no_value=True)
conf.read('home.conf')
@ -33,6 +33,7 @@ def load_conf():
zone_subdomain = conf['Zone']['subdomain']
mail_from = conf['Mail']['from']
mail_to = conf['Mail']['to']
mail_ignore_list = [ host for host in conf['MailIgnore'] ]
hosts_list = [ host for host in conf['Hosts'] ]
hosts_ipv4_nat_list = [ host for host in conf['NatHosts'] ]
@ -176,7 +177,7 @@ def ovh_update_zone(domain, update_zone_list, delete_zone_list):
return True
def send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_zone_list, wan):
def send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_zone_list, mail_ignore_list, wan):
#print('Send email to %s' % mail_to)
msg = EmailMessage()
@ -190,21 +191,25 @@ def send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_z
txt = txt + "\nZone %s has been updated:\n" % zone_domain
for host,tp,addr in update_zone_list:
txt = txt + " %-20s %-4s %s\n" % (host,tp,addr)
filtered_update_list = [ h for h in update_zone_list if not h[0] in mail_ignore_list ]
filtered_delete_list = [ h for h in delete_zone_list if not h[0] in mail_ignore_list ]
txt = txt + "\nRemoved entries:\n"
if len(filtered_update_list) or len(filtered_delete_list):
for host,tp,addr in update_zone_list:
txt = txt + " %-20s %-4s %s\n" % (host,tp,addr)
for host,tp,addr in delete_zone_list:
txt = txt + " %-20s %-4s %s\n" % (host,tp,addr)
txt = txt + "\nRemoved entries:\n"
txt = txt + '\n'
for host,tp,addr in delete_zone_list:
txt = txt + " %-20s %-4s %s\n" % (host,tp,addr)
msg.set_content(txt)
txt = txt + '\n'
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
msg.set_content(txt)
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
load_conf()
@ -242,6 +247,6 @@ sucess = ovh_update_zone(zone_domain, update_zone_list, delete_zone_list)
if sucess:
new_zone_list = write_zone_list_to_file(zone_filename, zone_list)
send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_zone_list, wan)
send_update_mail(mail_to, mail_from, zone_domain, update_zone_list, delete_zone_list, mail_ignore_list, wan)

View File

@ -28,3 +28,5 @@ subdomain = home
from = me@example.com
to = you@example.com
[MailIgnore]
mypc2.home