diff --git a/app/main.py b/app/main.py index ed4e11acffafffbb2e210e4143eb7c0912e29967..4a36ebc7f1920a2958c6824078cbb31f13f2a67b 100644 --- a/app/main.py +++ b/app/main.py @@ -62,7 +62,8 @@ class MyHandler(BaseHTTPRequestHandler): stdin, stdout, stderr = ssh.exec_command( f'/postfixadmin/scripts/postfixadmin-cli mailbox add {shlex.quote(target_email)} ' + f'--password {shlex.quote(password)} --password2 {shlex.quote(password_confirm)} ' + - f'--name {shlex.quote(displayname)} --quota {shlex.quote(email_quota)} --active 1 --welcome-mail 0') + f'--name {shlex.quote(displayname)} --quota {shlex.quote(email_quota)} --active 1 ' + + f'--welcome-mail 0 --email-other {shlex.quote(fallback_email)}') print(stdout.read()) print(stderr.read()) except (ssh.SSHException, ssh.AuthenticationException, ssh.socket.error, ssh.BadHostKeyException) as e: @@ -71,10 +72,16 @@ class MyHandler(BaseHTTPRequestHandler): self.respond(500, data) return + # Nextcloud only creates external accounts after the first login. We login through the API + # to trigger the account creation. + headers = {'OCS-APIRequest': 'true'} + auth = HTTPBasicAuth(target_email, password) + url = f'https://{os.environ["DOMAIN"]}/ocs/v1.php/cloud/users/' + target_email + r1 = requests.put(url, headers=headers, auth=auth) + # Edit nextcloud account, set quota and email auth = HTTPBasicAuth(os.environ['NEXTCLOUD_ADMIN_USER'], os.environ['NEXTCLOUD_ADMIN_PASSWORD']) url = f'https://{os.environ["DOMAIN"]}/ocs/v1.php/cloud/users/{target_email.lower()}' - headers = {'OCS-APIRequest': 'true'} r1 = requests.put(url, data={'key': 'email', 'value': fallback_email}, headers=headers, auth=auth) r2 = requests.put(url, data={'key': 'quota', 'value': nextcloud_quota}, headers=headers, auth=auth) print(r1.text)