You've already forked Mailu
mirror of
https://github.com/Mailu/Mailu.git
synced 2025-08-10 22:31:47 +02:00
Handle the case where PROXY_PROTOCOL_25 is set
(cherry picked from commit 0ff18c6079
)
This commit is contained in:
committed by
Mergify
parent
79e6957be3
commit
b36018e0c1
@@ -108,8 +108,39 @@ def set_env(required_secrets=[], log_filters=[]):
|
||||
}
|
||||
|
||||
def clean_env():
|
||||
""" remove all secret keys """
|
||||
""" remove all secret keys, normalize PROXY_PROTOCOL """
|
||||
[os.environ.pop(key, None) for key in os.environ.keys() if key.endswith("_KEY")]
|
||||
# Configure PROXY_PROTOCOL
|
||||
PROTO_MAIL=['25', '110', '995', '143', '993', '587', '465', '4190']
|
||||
PROTO_ALL_BUT_HTTP=PROTO_MAIL.copy()
|
||||
PROTO_ALL_BUT_HTTP.extend(['443'])
|
||||
PROTO_ALL=PROTO_ALL_BUT_HTTP.copy()
|
||||
PROTO_ALL.extend(['80'])
|
||||
for item in os.environ.get('PROXY_PROTOCOL', '').split(','):
|
||||
if item.isdigit():
|
||||
os.environ[f'PROXY_PROTOCOL_{item}']=True
|
||||
elif item == 'mail':
|
||||
for p in PROTO_MAIL: os.environ[f'PROXY_PROTOCOL_{p}']=True
|
||||
elif item == 'all-but-http':
|
||||
for p in PROTO_ALL_BUT_HTTP: os.environ[f'PROXY_PROTOCOL_{p}']=True
|
||||
elif item == 'all':
|
||||
for p in PROTO_ALL: os.environ[f'PROXY_PROTOCOL_{p}']=True
|
||||
elif item == '':
|
||||
pass
|
||||
else:
|
||||
log.error(f'Not sure what to do with {item} in PROXY_PROTOCOL ({args.get("PROXY_PROTOCOL")})')
|
||||
|
||||
PORTS_REQUIRING_TLS=['443', '465', '993', '995']
|
||||
ALL_PORTS='25,80,443,465,993,995,4190'
|
||||
for item in os.environ.get('PORTS', ALL_PORTS).split(','):
|
||||
if item in PORTS_REQUIRING_TLS and os.environ['TLS_FLAVOR'] == 'notls':
|
||||
continue
|
||||
os.environ[f'PORT_{item}']=True
|
||||
|
||||
if os.environ['TLS_FLAVOR'] != 'notls':
|
||||
for item in os.environ.get('TLS', ALL_PORTS).split(','):
|
||||
if item in PORTS_REQUIRING_TLS:
|
||||
os.environ[f'TLS_{item}']=True
|
||||
|
||||
def drop_privs_to(username='mailu'):
|
||||
pwnam = getpwnam(username)
|
||||
|
@@ -70,38 +70,6 @@ with open("/etc/resolv.conf") as handle:
|
||||
resolver = content[content.index("nameserver") + 1]
|
||||
args["RESOLVER"] = f"[{resolver}]" if ":" in resolver else resolver
|
||||
|
||||
# Configure PROXY_PROTOCOL
|
||||
PROTO_MAIL=['25', '110', '995', '143', '993', '587', '465', '4190']
|
||||
PROTO_ALL_BUT_HTTP=PROTO_MAIL.copy()
|
||||
PROTO_ALL_BUT_HTTP.extend(['443'])
|
||||
PROTO_ALL=PROTO_ALL_BUT_HTTP.copy()
|
||||
PROTO_ALL.extend(['80'])
|
||||
for item in args.get('PROXY_PROTOCOL', '').split(','):
|
||||
if item.isdigit():
|
||||
args[f'PROXY_PROTOCOL_{item}']=True
|
||||
elif item == 'mail':
|
||||
for p in PROTO_MAIL: args[f'PROXY_PROTOCOL_{p}']=True
|
||||
elif item == 'all-but-http':
|
||||
for p in PROTO_ALL_BUT_HTTP: args[f'PROXY_PROTOCOL_{p}']=True
|
||||
elif item == 'all':
|
||||
for p in PROTO_ALL: args[f'PROXY_PROTOCOL_{p}']=True
|
||||
elif item == '':
|
||||
pass
|
||||
else:
|
||||
log.error(f'Not sure what to do with {item} in PROXY_PROTOCOL ({args.get("PROXY_PROTOCOL")})')
|
||||
|
||||
PORTS_REQUIRING_TLS=['443', '465', '993', '995']
|
||||
ALL_PORTS='25,80,443,465,993,995,4190'
|
||||
for item in args.get('PORTS', ALL_PORTS).split(','):
|
||||
if item in PORTS_REQUIRING_TLS and args['TLS_FLAVOR'] == 'notls':
|
||||
continue
|
||||
args[f'PORT_{item}']=True
|
||||
|
||||
if args['TLS_FLAVOR'] != 'notls':
|
||||
for item in args.get('TLS', ALL_PORTS).split(','):
|
||||
if item in PORTS_REQUIRING_TLS:
|
||||
args[f'TLS_{item}']=True
|
||||
|
||||
# TLS configuration
|
||||
cert_name = args.get("TLS_CERT_FILENAME", "cert.pem")
|
||||
keypair_name = args.get("TLS_KEYPAIR_FILENAME", "key.pem")
|
||||
|
Reference in New Issue
Block a user