diff --git a/management/daemon.py b/management/daemon.py index 695b2a1..69bb929 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -98,7 +98,7 @@ def me(): @authorized_personnel_only def mail_users(): if request.args.get("format", "") == "json": - return json_response(get_mail_users_ex(env, with_archived=True)) + return json_response(get_mail_users_ex(env, with_archived=True, with_slow_info=True)) else: return "".join(x+"\n" for x in get_mail_users(env)) diff --git a/management/mailconfig.py b/management/mailconfig.py index 74b3c71..603934d 100755 --- a/management/mailconfig.py +++ b/management/mailconfig.py @@ -53,7 +53,7 @@ def get_mail_users(env): users = [ row[0] for row in c.fetchall() ] return utils.sort_email_addresses(users, env) -def get_mail_users_ex(env, with_archived=False): +def get_mail_users_ex(env, with_archived=False, with_slow_info=False): # Returns a complex data structure of all user accounts, optionally # including archived (status="inactive") accounts. # @@ -86,15 +86,20 @@ def get_mail_users_ex(env, with_archived=False): c.execute('SELECT email, privileges FROM users') for email, privileges in c.fetchall(): active_accounts.add(email) - users.append({ + + user = { "email": email, "privileges": parse_privs(privileges), "status": "active", - "aliases": [ + } + users.append(user) + + if with_slow_info: + user["aliases"] = [ (alias, sorted(evaluate_mail_alias_map(alias, aliases, env))) for alias in aliases.get(email.lower(), []) ] - }) + user["mailbox_size"] = utils.du(os.path.join(env['STORAGE_ROOT'], 'mail/mailboxes', *reversed(email.split("@")))) # Add in archived accounts. if with_archived: @@ -102,13 +107,17 @@ def get_mail_users_ex(env, with_archived=False): for domain in os.listdir(root): for user in os.listdir(os.path.join(root, domain)): email = user + "@" + domain + mbox = os.path.join(root, domain, user) if email in active_accounts: continue - users.append({ + user = { "email": email, "privileges": "", "status": "inactive", - "mailbox": os.path.join(root, domain, user), - }) + "mailbox": mbox, + } + users.append(user) + if with_slow_info: + user["mailbox_size"] = utils.du(mbox) # Group by domain. domains = { } diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index 8f01243..2b1ad46 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -39,7 +39,12 @@ function nice_size(bytes) { bytes /= 1024; powers.shift(); } - return (Math.round(bytes*10)/10) + " " + powers[0]; + // round to have three significant figures but at most one decimal place + if (bytes >= 100) + bytes = Math.round(bytes) + else + bytes = Math.round(bytes*10)/10; + return bytes + " " + powers[0]; } function show_system_backup() { diff --git a/management/templates/users.html b/management/templates/users.html index 8b07af6..3f54cac 100644 --- a/management/templates/users.html +++ b/management/templates/users.html @@ -1,8 +1,8 @@