-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
7 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,13 @@ | |
import sys, getpass, urllib.request, urllib.error, json, csv | ||
import contextlib | ||
|
||
def mgmt(cmd, data=None, is_json=False, method='GET'): | ||
def mgmt(cmd, data=None, is_json=False): | ||
# The base URL for the management daemon. (Listens on IPv4 only.) | ||
mgmt_uri = 'http://127.0.0.1:10222' | ||
|
||
setup_key_auth(mgmt_uri) | ||
|
||
req = urllib.request.Request(mgmt_uri + cmd, urllib.parse.urlencode(data).encode("utf8") if data else None, method=method) | ||
req = urllib.request.Request(mgmt_uri + cmd, urllib.parse.urlencode(data).encode("utf8") if data else None) | ||
try: | ||
response = urllib.request.urlopen(req) | ||
except urllib.error.HTTPError as e: | ||
|
@@ -65,7 +65,7 @@ def setup_key_auth(mgmt_uri): | |
{cli} user password [email protected] [password] | ||
{cli} user remove [email protected] | ||
{cli} user make-admin [email protected] | ||
{cli} user quota user@domain [new-quota] (get or set user quota) | ||
{cli} user quota user@domain [new-quota] | ||
{cli} user remove-admin [email protected] | ||
{cli} user admins (lists admins) | ||
{cli} user mfa show [email protected] (shows MFA devices for user, if any) | ||
|
@@ -123,12 +123,12 @@ def setup_key_auth(mgmt_uri): | |
print(user['email']) | ||
|
||
elif sys.argv[1] == "user" and sys.argv[2] == "quota" and len(sys.argv) == 4: | ||
# Get a user's quota | ||
# Set a user's quota | ||
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: | ||
# Set a user's quota | ||
users = mgmt("/mail/users/quota", { "email": sys.argv[3], "quota": sys.argv[4] }, method='POST') | ||
users = mgmt("/mail/users/quota", { "email": sys.argv[3], "quota": sys.argv[4] }) | ||
|
||
elif sys.argv[1] == "user" and len(sys.argv) == 5 and sys.argv[2:4] == ["mfa", "show"]: | ||
# Show MFA status for a user. | ||
|
@@ -154,3 +154,4 @@ def setup_key_auth(mgmt_uri): | |
else: | ||
print("Invalid command-line arguments.") | ||
sys.exit(1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,3 +275,4 @@ def run_migrations(): | |
elif sys.argv[-1] == "--migrate": | ||
# Perform migrations. | ||
run_migrations() | ||
|