1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/core/admin/start.py

84 lines
3.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2018-10-22 17:01:59 +02:00
import os
2023-10-16 12:48:20 +02:00
import os.path
import time
import logging as log
import sys
2022-12-08 13:46:31 +02:00
from socrate import system
2022-11-21 18:50:57 +02:00
os.system("chown mailu:mailu -R /dkim")
os.system("find /data | grep -v /fetchmail | xargs -n1 chown mailu:mailu")
2022-12-23 11:58:06 +02:00
system.drop_privs_to('mailu')
2022-11-17 17:03:37 +02:00
2022-12-08 13:46:31 +02:00
system.set_env(['SECRET'])
2018-10-22 17:01:59 +02:00
os.system("flask mailu advertise")
os.system("flask db upgrade")
2019-08-21 15:34:25 +02:00
account = os.environ.get("INITIAL_ADMIN_ACCOUNT")
domain = os.environ.get("INITIAL_ADMIN_DOMAIN")
password = os.environ.get("INITIAL_ADMIN_PW")
if account is not None and domain is not None and password is not None:
mode = os.environ.get("INITIAL_ADMIN_MODE", default="ifmissing")
2022-10-19 19:36:13 +02:00
log.info("Creating initial admin account %s@%s with mode %s", account, domain, mode)
2019-08-21 15:34:25 +02:00
os.system("flask mailu admin %s %s '%s' --mode %s" % (account, domain, password, mode))
2023-10-16 12:48:20 +02:00
def test_unsupported():
import codecs
if os.path.isfile(codecs.decode('/.qbpxrerai', 'rot13')) or os.environ.get(codecs.decode('V_XABJ_ZL_FRGHC_QBRFAG_SVG_ERDHVERZRAGF_NAQ_JBAG_SVYR_VFFHRF_JVGUBHG_CNGPURF', 'rot13'), None):
return
2023-10-17 14:05:08 +02:00
log.critical('Your system is not supported. Please start by reading the documentation and then http://www.catb.org/~esr/faqs/smart-questions.html')
2023-10-16 12:48:20 +02:00
while True:
time.sleep(5)
2022-01-05 19:49:30 +02:00
def test_DNS():
import dns.resolver
import dns.exception
import dns.flags
import dns.rdtypes
import dns.rdatatype
import dns.rdataclass
import time
# DNS stub configured to do DNSSEC enabled queries
resolver = dns.resolver.Resolver()
2022-02-19 14:02:52 +02:00
resolver.use_edns(0, dns.flags.DO, 1232)
2022-01-05 19:49:30 +02:00
resolver.flags = dns.flags.AD | dns.flags.RD
nameservers = resolver.nameservers
for ns in nameservers:
resolver.nameservers=[ns]
2022-01-12 14:34:18 +02:00
while True:
2022-01-05 19:49:30 +02:00
try:
2022-01-21 15:17:37 +02:00
result = resolver.resolve('example.org', dns.rdatatype.A, dns.rdataclass.IN, lifetime=10)
2022-01-05 19:49:30 +02:00
except Exception as e:
2022-10-19 19:36:13 +02:00
log.critical("Your DNS resolver at %s is not working (%s). Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation", ns, e)
2022-01-12 14:34:18 +02:00
else:
2022-01-12 14:44:17 +02:00
if result.response.flags & dns.flags.AD:
break
log.critical("Your DNS resolver at %s isn't doing DNSSEC validation; Please see https://mailu.io/master/faq.html#the-admin-container-won-t-start-and-its-log-says-critical-your-dns-resolver-isn-t-doing-dnssec-validation.", ns)
2022-01-05 19:49:30 +02:00
time.sleep(5)
test_DNS()
2023-10-16 12:48:20 +02:00
test_unsupported()
2022-01-05 19:49:30 +02:00
2023-01-25 16:15:24 +02:00
cmdline = [
2023-05-04 00:14:44 +02:00
"gunicorn",
"--threads", f"{os.cpu_count()}",
# If SUBNET6 is defined, gunicorn must listen on IPv6 as well as IPv4
"-b", f"{'[::]' if os.environ.get('SUBNET6') else '0.0.0.0'}:8080",
"--logger-class mailu.Logger",
2023-05-04 00:14:44 +02:00
f"--log-level {os.environ.get('LOG_LEVEL', 'INFO')}",
"--worker-tmp-dir /dev/shm",
2023-05-04 00:14:44 +02:00
"--error-logfile", "-",
"--preload"
2023-01-25 16:15:24 +02:00
]
# logging
if log.root.level <= log.INFO:
cmdline.extend(["--access-logfile", "-"])
cmdline.append("'mailu:create_app()'")
2023-01-25 16:15:24 +02:00
os.system(" ".join(cmdline))