diff --git a/conf/nginx.conf b/conf/nginx.conf index 3ba20276..24dd0c34 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,3 +1,7 @@ +## NOTE: This file is automatically generated by Mail-in-a-Box. +## Do not edit this file. It will be replaced each time +## Mail-in-a-Box needs up update the web configuration. + # Redirect all HTTP to HTTPS. server { listen 80; @@ -9,7 +13,6 @@ server { } # The secure HTTPS server. - server { listen 443 ssl; diff --git a/management/dns_update.py b/management/dns_update.py index 43c63c10..abba5bc1 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -118,10 +118,10 @@ def do_dns_update(env): shell('check_call', ["/usr/sbin/service", "opendkim", "restart"]) if len(updated_domains) == 0: - # if nothing was updated (except maybe DKIM), don't show any output + # if nothing was updated (except maybe OpenDKIM's files), don't show any output return "" else: - return "updated: " + ",".join(updated_domains) + "\n" + return "updated DNS: " + ",".join(updated_domains) + "\n" ######################################################################## diff --git a/management/mailconfig.py b/management/mailconfig.py index bc5df48d..e2562bdc 100755 --- a/management/mailconfig.py +++ b/management/mailconfig.py @@ -91,9 +91,8 @@ def add_mail_user(email, pw, env): shutil.copyfile(utils.CONF_DIR + "/dovecot_sieve.txt", user_mail_dir + "/.dovecot.sieve") os.chown(user_mail_dir + "/.dovecot.sieve", maildirstat.st_uid, maildirstat.st_gid) - # Update DNS in case any new domains are added. - from dns_update import do_dns_update - return do_dns_update(env) + # Update DNS/web in case any new domains are added. + return kick(env, "mail user added") def set_mail_password(email, pw, env): # hash the password @@ -114,9 +113,8 @@ def remove_mail_user(email, env): return ("That's not a user (%s)." % email, 400) conn.commit() - # Update DNS in case any domains are removed. - from dns_update import do_dns_update - return do_dns_update(env) + # Update DNS/web in case any domains are removed. + return kick(env, "mail user removed") def add_mail_alias(source, destination, env): if not validate_email(source, False): @@ -129,9 +127,8 @@ def add_mail_alias(source, destination, env): return ("Alias already exists (%s)." % source, 400) conn.commit() - # Update DNS in case any new domains are added. - from dns_update import do_dns_update - return do_dns_update(env) + # Update DNS/web in case any new domains are added. + return kick(env, "alias added") def remove_mail_alias(source, env): conn, c = open_database(env, with_connection=True) @@ -140,9 +137,19 @@ def remove_mail_alias(source, env): return ("That's not an alias (%s)." % source, 400) conn.commit() - # Update DNS in case any domains are removed. + # Update DNS and nginx in case any domains are removed. + return kick(env, "alias removed") + +def kick(env, mail_result): + # Update DNS and nginx in case any domains are added/removed. from dns_update import do_dns_update - return do_dns_update(env) + from web_update import do_web_update + results = [ + do_dns_update(env), + mail_result + "\n", + do_web_update(env), + ] + return "".join(s for s in results if s != "") if __name__ == "__main__": import sys diff --git a/management/web_update.py b/management/web_update.py index d68a279a..e85e0d02 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -31,14 +31,21 @@ def do_web_update(env): for domain in get_web_domains(env): nginx_conf += make_domain_config(domain, template, env) + # Did the file change? If not, don't bother writing & restarting nginx. + nginx_conf_fn = "/etc/nginx/conf.d/local.conf" + if os.path.exists(nginx_conf_fn): + with open(nginx_conf_fn) as f: + if f.read() == nginx_conf: + return "" + # Save the file. - with open("/etc/nginx/conf.d/local.conf", "w") as f: + with open(nginx_conf_fn, "w") as f: f.write(nginx_conf) - # Nick nginx. + # Kick nginx. shell('check_call', ["/usr/sbin/service", "nginx", "restart"]) - return "OK" + return "web updated\n" def make_domain_config(domain, template, env): # How will we configure this domain.