1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-12-25 07:47:05 +00:00

when adding/removing mail addresses also update nginx's config

This commit is contained in:
Joshua Tauberer 2014-07-06 12:16:50 +00:00
parent c8856f107d
commit 49d5561933
4 changed files with 34 additions and 17 deletions

View File

@ -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;

View File

@ -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"
########################################################################

View File

@ -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

View File

@ -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.