mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-23 02:27:05 +00:00
fixing cli commands
This commit is contained in:
parent
1cb67f545e
commit
c01a1d5493
@ -9,13 +9,13 @@
|
|||||||
import sys, getpass, urllib.request, urllib.error, json, csv
|
import sys, getpass, urllib.request, urllib.error, json, csv
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
def mgmt(cmd, data=None, is_json=False):
|
def mgmt(cmd, data=None, is_json=False, method='GET'):
|
||||||
# The base URL for the management daemon. (Listens on IPv4 only.)
|
# The base URL for the management daemon. (Listens on IPv4 only.)
|
||||||
mgmt_uri = 'http://127.0.0.1:10222'
|
mgmt_uri = 'http://127.0.0.1:10222'
|
||||||
|
|
||||||
setup_key_auth(mgmt_uri)
|
setup_key_auth(mgmt_uri)
|
||||||
|
|
||||||
req = urllib.request.Request(mgmt_uri + cmd, urllib.parse.urlencode(data).encode("utf8") if data else None)
|
req = urllib.request.Request(mgmt_uri + cmd, urllib.parse.urlencode(data).encode("utf8") if data else None, method=method)
|
||||||
try:
|
try:
|
||||||
response = urllib.request.urlopen(req)
|
response = urllib.request.urlopen(req)
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
@ -66,7 +66,7 @@ if len(sys.argv) < 2:
|
|||||||
{cli} user password user@domain.com [password]
|
{cli} user password user@domain.com [password]
|
||||||
{cli} user remove user@domain.com
|
{cli} user remove user@domain.com
|
||||||
{cli} user make-admin user@domain.com
|
{cli} user make-admin user@domain.com
|
||||||
{cli} user quota user@domain [new-quota]
|
{cli} user quota user@domain [new-quota] (get or set user quota)
|
||||||
{cli} user remove-admin user@domain.com
|
{cli} user remove-admin user@domain.com
|
||||||
{cli} user admins (lists admins)
|
{cli} user admins (lists admins)
|
||||||
{cli} user mfa show user@domain.com (shows MFA devices for user, if any)
|
{cli} user mfa show user@domain.com (shows MFA devices for user, if any)
|
||||||
@ -124,12 +124,12 @@ elif sys.argv[1] == "user" and sys.argv[2] == "admins":
|
|||||||
print(user['email'])
|
print(user['email'])
|
||||||
|
|
||||||
elif sys.argv[1] == "user" and sys.argv[2] == "quota" and len(sys.argv) == 4:
|
elif sys.argv[1] == "user" and sys.argv[2] == "quota" and len(sys.argv) == 4:
|
||||||
# Set a user's quota
|
# Get a user's quota
|
||||||
print(mgmt("/mail/users/quota?text=1&email=%s" % sys.argv[3]))
|
print(mgmt("/mail/users/quota?text=1&email=%s" % sys.argv[3]))
|
||||||
|
|
||||||
elif sys.argv[1] == "user" and sys.argv[2] == "quota" and len(sys.argv) == 5:
|
elif sys.argv[1] == "user" and sys.argv[2] == "quota" and len(sys.argv) == 5:
|
||||||
# Set a user's quota
|
# Set a user's quota
|
||||||
users = mgmt("/mail/users/quota", { "email": sys.argv[3], "quota": sys.argv[4] })
|
users = mgmt("/mail/users/quota", { "email": sys.argv[3], "quota": sys.argv[4] }, method='POST')
|
||||||
|
|
||||||
elif sys.argv[1] == "user" and len(sys.argv) == 5 and sys.argv[2:4] == ["mfa", "show"]:
|
elif sys.argv[1] == "user" and len(sys.argv) == 5 and sys.argv[2:4] == ["mfa", "show"]:
|
||||||
# Show MFA status for a user.
|
# Show MFA status for a user.
|
||||||
@ -161,4 +161,3 @@ elif sys.argv[1] == "system" and sys.argv[2] == "default-quota" and len(sys.argv
|
|||||||
else:
|
else:
|
||||||
print("Invalid command-line arguments.")
|
print("Invalid command-line arguments.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -276,4 +276,3 @@ if __name__ == "__main__":
|
|||||||
elif sys.argv[-1] == "--migrate":
|
elif sys.argv[-1] == "--migrate":
|
||||||
# Perform migrations.
|
# Perform migrations.
|
||||||
run_migrations()
|
run_migrations()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user