Add initial madmail installer step

This commit is contained in:
Ana Custura 2026-03-30 15:15:22 +01:00
parent 441031a4ac
commit 48abccbbd6
3 changed files with 72 additions and 2 deletions

View file

@ -17,6 +17,7 @@ import glob
import time import time
import qrcode import qrcode
from flask_babel import lazy_gettext as _l from flask_babel import lazy_gettext as _l
from install_madmail import run_madmail_installer
CHANGES_REQUIRING_RESTART = ['wifi_password', 'ssid', 'enable_access_point', 'enable_chat', 'enable_delta_chat', 'butterbox_hostname', 'ssh_access_settings', 'root_account_settings', 'root_password'] CHANGES_REQUIRING_RESTART = ['wifi_password', 'ssid', 'enable_access_point', 'enable_chat', 'enable_delta_chat', 'butterbox_hostname', 'ssh_access_settings', 'root_account_settings', 'root_password']
RASPAP_INSTALLED = os.path.exists("/var/www/html/raspap") RASPAP_INSTALLED = os.path.exists("/var/www/html/raspap")
@ -231,7 +232,6 @@ def step3():
return render_template('step3.html', raspap_installed=RASPAP_INSTALLED, form=form, get_setting=get_setting) return render_template('step3.html', raspap_installed=RASPAP_INSTALLED, form=form, get_setting=get_setting)
return redirect(url_for('admin')) return redirect(url_for('admin'))
@app.route('/step4', methods=['GET', 'POST']) @app.route('/step4', methods=['GET', 'POST'])
def step4(): def step4():
form = Step4Form() form = Step4Form()
@ -252,6 +252,7 @@ def step4():
setting_value = getattr(form, s).data setting_value = getattr(form, s).data
set_setting(s, setting_value) set_setting(s, setting_value)
set_setting('first_setup', "false") set_setting('first_setup', "false")
run_madmail_installer()
db.session.commit() db.session.commit()
return redirect(url_for('setup_complete')) return redirect(url_for('setup_complete'))
if get_setting("first_setup") == "true": if get_setting("first_setup") == "true":

View file

@ -157,7 +157,7 @@ def check_settings(raspap_installed: bool):
if s == "enable_access_point" and raspap_installed: if s == "enable_access_point" and raspap_installed:
needs_restart = change_service_status("enable_access_point", "raspapd") or needs_restart needs_restart = change_service_status("enable_access_point", "raspapd") or needs_restart
if s == "enable_deltachat": if s == "enable_deltachat":
needs_restart = change_service_status("enable_deltachat", "madmail") or needs_restart needs_restart = change_service_status("enable_deltachat", "maddy") or needs_restart
if s == "butterbox_hostname": if s == "butterbox_hostname":
# change in /etc/hostname # change in /etc/hostname
print("Writing new hostname to /etc/hostname") print("Writing new hostname to /etc/hostname")

69
install_madmail.py Normal file
View file

@ -0,0 +1,69 @@
import pexpect
import json
def run_madmail_installer():
with open("./settings.txt", "r") as f:
settings = json.load(f)
butterbox_hostname = settings["butterbox_hostname"]
cmd = f"sudo ../madmail/madmail install"
child = pexpect.spawn(cmd, encoding = "utf-8")#
child.logfile = open("install_log.txt", "w")
child.expect("Customize every setting")
child.sendline("2")
child.expect("Primary domain")
child.sendline(butterbox_hostname)
child.expect("MX record")
child.sendline(butterbox_hostname)
child.expect("Public IP address")
child.sendline("127.0.0.1")
child.expect("Additional domains")
child.sendline("")
child.expect("State directory")
child.sendline("")
child.expect("Configuration directory")
child.sendline("")
child.expect("TLS certificate path")
child.sendline("")
child.expect("TLS private key path")
child.sendline("")
child.expect("SMTP port")
child.sendline("")
child.expect("Submission port")
child.sendline("")
child.expect("Submission TLS port")
child.sendline("")
child.expect("IMAP port")
child.sendline("")
child.expect("IMAP TLS port")
child.sendline("")
child.expect("Allow insecure")
child.sendline("n")
child.expect("Enable chatmail endpoint for user registration")
child.sendline("y")
child.expect("Chatmail HTTP port")
child.sendline("8081")
child.expect("Chatmail HTTPS port")
child.sendline("8443")
child.expect("Chatmail username length")
child.sendline("")
child.expect("Chatmail password length")
child.sendline("")
child.expect("Enable Shadowsocks proxy for faster messaging")
child.sendline("n")
child.expect("Enable TURN server")
child.sendline("n")
child.expect("Require PGP encryption for outgoing messages")
child.sendline("y")
child.expect("Allow secure join requests without encryption")
child.sendline("n")
child.expect("Passthrough senders")
child.sendline("")
child.expect("Passthrough recipients")
child.sendline("")
child.expect("Maximum message size")
child.sendline("")
child.expect("Add Cloudflare proxy disable tags to DNS records")
child.sendline("n")
child.expect("Enable logging for the server")
child.sendline("y")
child.expect(pexpect.EOF)