From 3d0786fb9a7fccb607e81c454ecbc00380b3fcfc Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 13 May 2019 14:05:17 +0200 Subject: [PATCH 1/2] Trigger Nextcloud external account creation --- app/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index ed4e11a..0ed6454 100644 --- a/app/main.py +++ b/app/main.py @@ -71,10 +71,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) -- GitLab From 1fcad8e142383d6f9a15a783707e7cc6cad77b14 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 13 May 2019 14:19:22 +0200 Subject: [PATCH 2/2] Add fallback email to postfixadmin --- app/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 0ed6454..4a36ebc 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: -- GitLab