1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-03-24 19:07:23 +01:00

Mailpile: an installation script and a multiplexer daemon that proxies Mailpile behind an authorization step and multiplexes Mailpile instances per logged in user

This commit is contained in:
Joshua Tauberer
2014-07-02 11:42:20 +00:00
parent d11ce688ca
commit 4f57c62681
7 changed files with 406 additions and 12 deletions

View File

@@ -8,6 +8,8 @@ from mailconfig import get_mail_user_privileges
DEFAULT_KEY_PATH = '/var/lib/mailinabox/api.key'
DEFAULT_AUTH_REALM = 'Mail-in-a-Box Management Server'
from utils import create_file_with_mode
class KeyAuthService:
"""Generate an API key for authenticating clients
@@ -27,13 +29,6 @@ class KeyAuthService:
authorized to access the API by granting group/ACL read permissions on
the key file.
"""
def create_file_with_mode(path, mode):
# Based on answer by A-B-B: http://stackoverflow.com/a/15015748
old_umask = os.umask(0)
try:
return os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, mode), 'w')
finally:
os.umask(old_umask)
os.makedirs(os.path.dirname(self.key_path), exist_ok=True)

View File

@@ -1,4 +1,4 @@
import os.path
import os, os.path, subprocess
CONF_DIR = os.path.join(os.path.dirname(__file__), "../conf")
@@ -136,11 +136,12 @@ def is_pid_valid(pid):
else:
return True
def shell(method, cmd_args, env={}, capture_stderr=False, return_bytes=False, trap=False, input=None):
# A safe way to execute processes.
# Some processes like apt-get require being given a sane PATH.
import subprocess
def shell(method, cmd_args, env={}, capture_stderr=False, return_bytes=False, trap=False,
input=None, stdin=subprocess.DEVNULL):
# A safe way to execute processes.
# Some processes like apt-get require being given a sane PATH.
env.update({ "PATH": "/sbin:/bin:/usr/sbin:/usr/bin" })
kwargs = {
'env': env,
@@ -148,6 +149,10 @@ def shell(method, cmd_args, env={}, capture_stderr=False, return_bytes=False, tr
}
if method == "check_output" and input is not None:
kwargs['input'] = input
else:
kwargs['stdin'] = stdin
#print(method, "".join(("%s=%s " % kv) for kv in env.items()) + " ".join(cmd_args))
if not trap:
ret = getattr(subprocess, method)(cmd_args, **kwargs)
@@ -169,3 +174,11 @@ def create_syslog_handler():
handler = logging.handlers.SysLogHandler(address='/dev/log')
handler.setLevel(logging.WARNING)
return handler
def create_file_with_mode(path, mode):
# Based on answer by A-B-B: http://stackoverflow.com/a/15015748
old_umask = os.umask(0)
try:
return os.fdopen(os.open(path, os.O_WRONLY | os.O_CREAT, mode), 'w')
finally:
os.umask(old_umask)