Loading README.md 0 → 100644 +37 −0 Original line number Diff line number Diff line Utility for creating a new user account in postfixadmin, and setting account values via Nextcloud. ## Usage Send a `PUT` request to `example.com:9000/create-account`. Required parameters: ``` target_email password password_confirm displayname email_quota fallback_email nextcloud_quota ``` You can use the following command to make a request: ``` curl -X PUT https://example.com:9000/create-account \ -d target_email=user@example.com -d password=pw -d password_confirm=pw \ -d displayname=name -d email_quota=quota -d fallback_email=user@otherdomain.com \ -d nextcloud_quota=-1 ``` ## Response values: On success, status code will be 200 and response body: ``` '{"success": true}' ``` On failure, status code will be 4xx or 5xx and response body one of the following: ``` '{"success": false, "message": "username_forbidden"}' '{"success": false, "message": "username_taken"}' '{"success": false, "message": "internal_error"}' ``` app/main.py +8 −5 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ PORT_NUMBER = 9000 class MyHandler(BaseHTTPRequestHandler): def do_PUT(self): if self.path == '/create-account': if self.path == '/create-account' or self.path == '/create-account/': # TODO: require a password length = int(self.headers['Content-Length']) postvars = urllib.parse.parse_qs(self.rfile.read(length)) postvars = {k.decode(): v[0].decode() for k, v in postvars.items()} print(f'Received request PUT /create-account, parameters {postvars}') self.create_account(postvars['target_email'], postvars['password'], postvars['password_confirm'], postvars['displayname'], postvars['email_quota'], postvars['fallback_email'], Loading @@ -51,10 +53,11 @@ class MyHandler(BaseHTTPRequestHandler): self.respond(403, data) return stdin, stdout, stderr = ssh.exec_command( f'/postfixadmin/scripts/postfixadmin-cli mailbox add "{target_email}" ' + f'--password "{password}" --password2 {password_confirm} --name "{displayname}" ' + f'--quota {email_quota} --active 1 --welcome-mail 0') command = f'/postfixadmin/scripts/postfixadmin-cli mailbox add "{target_email}" ' + \ f'--password "{password}" --password2 {password_confirm} --name "{displayname}" ' + \ f'--quota {email_quota} --active 1 --welcome-mail 0' print(f'command=command') stdin, stdout, stderr = ssh.exec_command(command) print(stdout.read()) print(stderr.read()) Loading Loading
README.md 0 → 100644 +37 −0 Original line number Diff line number Diff line Utility for creating a new user account in postfixadmin, and setting account values via Nextcloud. ## Usage Send a `PUT` request to `example.com:9000/create-account`. Required parameters: ``` target_email password password_confirm displayname email_quota fallback_email nextcloud_quota ``` You can use the following command to make a request: ``` curl -X PUT https://example.com:9000/create-account \ -d target_email=user@example.com -d password=pw -d password_confirm=pw \ -d displayname=name -d email_quota=quota -d fallback_email=user@otherdomain.com \ -d nextcloud_quota=-1 ``` ## Response values: On success, status code will be 200 and response body: ``` '{"success": true}' ``` On failure, status code will be 4xx or 5xx and response body one of the following: ``` '{"success": false, "message": "username_forbidden"}' '{"success": false, "message": "username_taken"}' '{"success": false, "message": "internal_error"}' ```
app/main.py +8 −5 Original line number Diff line number Diff line Loading @@ -22,10 +22,12 @@ PORT_NUMBER = 9000 class MyHandler(BaseHTTPRequestHandler): def do_PUT(self): if self.path == '/create-account': if self.path == '/create-account' or self.path == '/create-account/': # TODO: require a password length = int(self.headers['Content-Length']) postvars = urllib.parse.parse_qs(self.rfile.read(length)) postvars = {k.decode(): v[0].decode() for k, v in postvars.items()} print(f'Received request PUT /create-account, parameters {postvars}') self.create_account(postvars['target_email'], postvars['password'], postvars['password_confirm'], postvars['displayname'], postvars['email_quota'], postvars['fallback_email'], Loading @@ -51,10 +53,11 @@ class MyHandler(BaseHTTPRequestHandler): self.respond(403, data) return stdin, stdout, stderr = ssh.exec_command( f'/postfixadmin/scripts/postfixadmin-cli mailbox add "{target_email}" ' + f'--password "{password}" --password2 {password_confirm} --name "{displayname}" ' + f'--quota {email_quota} --active 1 --welcome-mail 0') command = f'/postfixadmin/scripts/postfixadmin-cli mailbox add "{target_email}" ' + \ f'--password "{password}" --password2 {password_confirm} --name "{displayname}" ' + \ f'--quota {email_quota} --active 1 --welcome-mail 0' print(f'command=command') stdin, stdout, stderr = ssh.exec_command(command) print(stdout.read()) print(stderr.read()) Loading