diff --git a/management/daemon.py b/management/daemon.py index b267dbdb..d0dc2819 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -523,18 +523,31 @@ def privacy_status_set(): @app.route('/system/smtp/relay', methods=["GET"]) @authorized_personnel_only def smtp_relay_get(): - # Just return something for now. return { - "enabled": False, - "host": "", - "auth_enabled": True, - "user": "" + "enabled": (env["SMTP_RELAY_ENABLED"] == "true"), + "host": env["SMTP_RELAY_HOST"], + "auth_enabled": (env["SMTP_RELAY_AUTH"] == "true"), + "user": env["SMTP_RELAY_USER"] } @app.route('/system/smtp/relay', methods=["POST"]) @authorized_personnel_only def smtp_relay_set(): - pass + config = utils.load_settings(env) + newconf = request.form + try + # Write on Postfix config + # Write on daemon env + config["SMTP_RELAY_ENABLED"] = "true" if newconf.get("enabled") else "false" + config["SMTP_RELAY_HOST"] = newconf.get("host") + config["SMTP_RELAY_AUTH"] = "true" if newconf.get("auth_enabled") else "false" + config["SMTP_RELAY_USER"] = newconf.get("user") + utils.write_settings(config, env) + # Restart Postfix + return "OK" + except Exception e: + return (str(e), 500) + # MUNIN diff --git a/management/templates/index.html b/management/templates/index.html index 5aa8442a..1bbd0378 100644 --- a/management/templates/index.html +++ b/management/templates/index.html @@ -341,7 +341,7 @@ return output; } - function default_error(text, xhr) { + function default_error(_, xhr) { if (xhr.status != 403) // else handled below show_modal_error("Error", "Something went wrong, sorry.") } @@ -371,7 +371,8 @@ // Credentials are no longer valid. Try to login again. var p = current_panel; show_panel('login'); - switch_back_to_panel = p; + // No use of going back + switch_back_to_panel = current_panel; } } }) diff --git a/management/templates/smtp-relays.html b/management/templates/smtp-relays.html index d87ea363..50286cd7 100644 --- a/management/templates/smtp-relays.html +++ b/management/templates/smtp-relays.html @@ -129,6 +129,11 @@ show_modal_error("Done!", "The configuration has been updated and Postfix was restarted successfully. Please make sure everything is functioning as intended.", () => { return false }) + }, + (text, xhr) => { + if (xhr.status != 403) { + show_modal_error("Error", `
${xhr}

${text}

Welp, oof`) + } } ) }