{% from "macros/form_inputs.html" import input_text, input_csrf_token with context %} {# ------------ Load JS files ------------- #} {% macro load_jquery() -%} {%- endmacro %} {# ------------ END JS ------------- #} {% macro display_remove_mailbox_days(num) -%} {% if num == 0 %} {{ _('Keep mailbox forever') }} {% elif num == 1 %} {{ _('Keep mailbox for 1 day') }} {% elif 1 < num < 30 %} {% if num == 7 %} {{ _('Keep mailbox for 1 week') }} {% else %} {% set _div = num % 7 %} {% if _div == 0 %} {{ _('Keep mailbox for %d weeks') | format(num/7) }} {% else %} {{ _('Keep mailbox for %d days') | format(num) }} {% endif %} {% endif %} {% elif num == 30 %} {{ _('Keep mailbox for 1 month ') }} {% elif 30 < num < 365 %} {% set _div = num % 30 %} {% if _div == 0 %} {{ _('Keep mailbox for %d months') | format(num/30) }} {% else %} {{ _('Keep mailbox for %d days') | format(num) }} {% endif %} {% elif num == 365 %} {{ _('Keep mailbox for 1 year') }} {% else %} {# num > 365 #} {% set _div = num % 365 %} {% if _div == 0 %} {{ _('Keep mailbox for %d years') | format(num / 365) }} {% endif %} {% endif %} {% endmacro %} {%- macro display_subnav(crumbs) -%} {# Crumb format: (link, label), ('active', link, label) #} {% if crumbs %} {% endif %} {%- endmacro -%} {% macro set_account_status_img(status, account_type='user', is_relay=false, relay='', is_backupmx=false, backupmx='', float="right", tooltip=true, vcenter=true) -%} {# @relay is required if status == 'relay' #} {% if float == 'right' %} {% set imgfloat = 'fr-space' %} {% elif float == 'left' %} {% set imgfloat = 'fl-space' %} {% elif float == 'center' %} {% set imgfloat = 'fl-space' %} {% else %} {% set imgfloat = '' %} {% endif %} {% if is_relay in ['1', 1, true] %} {% set is_relay = true %} {% else %} {% set is_relay = false %} {% endif %} {% if is_backupmx in ['yes', '1', 1, true] %} {% set is_backupmx = true %} {% else %} {% set is_backupmx = false %} {% endif %} {% if status in ['active', '1', 1] %} {% if is_backupmx %} {{ _('Backup MX') }} {% elif is_relay %} {{ _('Relay') }} {% endif %} {% else %} {% endif %} {%- endmacro %} {% macro set_user_admin_type_img(value) -%} {# :param value in [domainadmin, globaladmin] #} {% if value == 'globaladmin' %} {% endif %} {%- endmacro %} {% macro set_admin_type_img(value, hide_negative=true) -%} {% if value == 'yes' %} {% else %} {% if hide_negative is not sameas true %} {% endif %} {% endif %} {%- endmacro %} {% macro set_alias_domain_img(alias_domains=None) -%} {% if alias_domains %} A{{ alias_domains |length }} {% endif %} {%- endmacro %} {% macro set_member_of_mailing_list_img(user, addresses=None) -%} {% if addresses %} L{{ addresses |length }} {% endif %} {%- endmacro %} {% macro display_progress_bar(percent, tooltip=none, show_zero=false, style='normal', width='100%') -%} {% set percent = percent |int %} {% if percent < 0 %} {% set percent = 0 %} {% elif percent > 100 %} {% set percent = 100 %} {% endif %} {% if tooltip is sameas none %} {% set title = percent |string + '%' %} {% else %} {% set title = tooltip |string + ' (' + percent | string + '%)' %} {% endif %} {% if style == 'thin' %} {% set height = '3px' %} {% else %} {% set height = '1.6em' %} {% endif %} {% if percent < 80 %} {% set bgcolor = '#ACE97C' %} {% elif 80 <= percent < 90 %} {% set bgcolor = 'yellow' %} {% elif 90 <= percent < 99 %} {% set bgcolor = '#F76541' %} {% else %} {% set bgcolor = '#F62217' %} {% endif %} {% if percent > 0 or show_zero %}
{% endif %} {%- endmacro %} {% macro display_filter_by_first_char(baseurl, first_char=None, account_type='user', disabled_only=False, available_chars=None, separator='?starts_with=') -%}
{% if not available_chars %} {% set available_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] %} {% endif %} {% for char in available_chars %} {{char}} {% endfor %} {% if account_type in ['domain', 'user'] %} | {{ _('Disabled') }} {% endif %}
{%- endmacro %} {% macro display_input_mail(mail='', name='mail', required=false) -%} {{ input_text(label=_('Mail Address'), input_name=name, value=mail, required=required) }} {%- endmacro %} {% macro display_input_domain(domain='', name='domainName', required=false, enable_input=true) -%} {{ input_text(label=_('Domain Name'), input_name=name, value=domain, required=required, enable_input=enable_input) }} {%- endmacro %} {% macro display_input_employeeid(value=None) -%} {{ input_text(label=_('User/Employee ID'), input_name='employeeNumber', value=value) }} {%- endmacro %} {% macro display_input_mobile(value=None) -%} {{ input_text(label=_('Mobile'), input_name='mobile', value=value) }} {%- endmacro %} {% macro display_phone_numbers(phone_numbers=None) -%} {% if not phone_numbers %}

{{ _('Telephone Number') }}

{% else %} {% for phone in phone_numbers %}
{% if loop.first %}

{{ _('Telephone Number') }}

{% else %}

 

{% endif %}
{% endfor %} {% endif %} {#-- Always display one more field to input new value --#}

 

{%- endmacro %} {% macro display_preferred_language(value='', languagemaps=['en_US'], label=none) -%}
{% if label is sameas none %}

{{ _('Preferred language') }}

{% else %}

{{ label }}

{% endif %}
{%- endmacro %} {% macro display_timezones(value, timezones) -%} {% if not timezones %} {% set timezones = {} %} {% endif %}

{{ _('Time zone') }}

{%- endmacro %} {% macro display_input_global_admin(value='no') %}

{{ _('Mark as global admin') }}

{# ldap: yes, no mysql: true, false #}
{%- endmacro %} {# Used to display domainMaxXXXNumber #} {% macro display_number_of_account_limited(value, hide_unlimited=true, hide_slash=false) -%} {% if value == '0' or value == 0 or value == 'None' %} {% if hide_unlimited is not sameas true %} {% if hide_slash is not sameas true %}/{% endif %}{{ _('Unlimited') }} {% endif %} {%else%} {% if hide_slash is not sameas true %}/ {% endif %}{{ value |e }} {%endif%} {%- endmacro %} {# Display accountStatus #} {% macro display_account_status(status, account_type='user') %}
{% if account_type == 'domain' %}

{{ _('Enable this domain') }}

{% else %}

{{ _('Enable this account') }}

{% endif %}
{%- endmacro %} {% macro display_reset_password(show_oldpw=false, show_confirmpw=true, min_passwd_length='0', max_passwd_length='0', store_password_in_plain_text=false, enable_input=true) -%} {% set min_passwd_length = min_passwd_length | string %} {% set max_passwd_length = max_passwd_length | string %} {% if min_passwd_length != '0' and max_passwd_length != '0' %} {% set pw_hint = _('Must be %s - %s characters.') |format(min_passwd_length, max_passwd_length) %} {% elif min_passwd_length != '0' and max_passwd_length == '0' %} {% set pw_hint = _('At least %s characters.') |format(min_passwd_length) %} {% elif max_passwd_length == '0' and max_passwd_length != '0' %} {% set pw_hint = _('No more than %s characters.') |format(max_passwd_length) %} {% else %} {% set pw_hint = '' %} {% endif %} {% if show_oldpw %}

{{ _('Old password') }} *

{% endif %}

{{ _('New password') }} *

{% if pw_hint != '' %} {{ pw_hint }} {% endif %}
{% if show_confirmpw %}

{{ _('Confirm new password') }} *

{% endif %} {% if store_password_in_plain_text %}

{{ _('Store password in plain text') }}

{% endif %} {%- endmacro %} {% macro display_quota(value='', label='', comment='', used_quota=0, stored_messages=0, spare_quota_bytes=0, show_spare_quota=false, show_value_in_input=true, hide_zero=true, show_used_quota=false, enable_input=true) -%} {# Convert to string #} {% set used_quota = used_quota |string %} {% if spare_quota_bytes > 0 %} {% if value > spare_quota_bytes/1024/1024 %} {% set value = spare_quota_bytes/1024/1024 %} {% endif %} {% endif %} {% set value = value |string %} {% if hide_zero %} {% if value == '0' %} {% set value = '' %} {% endif %} {% endif %}
{% if label == '' %}

{{ _('Mailbox Quota') }}

{% else %}

{{ label |e }}

{% endif %}
{% if show_used_quota %} {% if value |int > 0 %} {% if session.get('show_used_quota') and value.isdigit() and used_quota.isdigit() %} {% set percent = used_quota |convert_to_percentage(value |int * 1024 * 1024) %} {% if (stored_messages | int) > 0 %} {% else %} {% endif %} {% endif %} {% elif value | int == 0 %} {% endif %} {% endif %}
{%- endmacro %} {% macro display_domain_cn(cn='', input_name='cn', enable_input=true) -%} {% if cn in [None, 'None'] %} {% set cn = '' %} {% endif %}

{{ _('Company/Organization Name') }}

{% endmacro %} {% macro display_input_cn(value='', input_name='cn', account_type='user', tooltip='', size="size-250", show_first_last_name=false, first_name='', last_name='', email='', empty_if_equal_to_username=true, enable_input=true) -%} {% if value is sameas none %} {% set value = '' %} {% endif %} {% if account_type == 'user' and mail %} {% set username = email.split('@', 1)[0] %} {% if value == username and empty_if_equal_to_username %} {% set value = '' %} {% endif %} {% if first_name == username and empty_if_equal_to_username %} {% set first_name = '' %} {% endif %} {% if last_name == username and empty_if_equal_to_username %} {% set last_name = '' %} {% endif %} {% endif %}

{{ _('Display Name') }}

{% if show_first_last_name %}

 

{% endif %} {%- endmacro %} {% macro display_mark_user_as_admin(is_global_admin=false) %}

{{ _('Mark this user as global admin') }}

{{ _('Note: Global admin can manage all mail domains.') }}
{%- endmacro %} {% macro display_add_admin(min_passwd_length='0', max_passwd_length='0', lang='en_US', languagemaps=['en_US']) -%} {{ display_input_mail(required=true) }}
 
{{ display_reset_password(show_confirmpw=true, min_passwd_length=min_passwd_length, max_passwd_length=max_passwd_length) }}
{{ display_input_cn() }} {{ display_preferred_language(lang, languagemaps) }} {%- endmacro %} {% macro display_add_domain(label=false, preferred_language='en_US', languagemaps=['en_US'], timezones=None) %}
{% if label %}

{{ _('Add domain') }}

{% endif %}
{{ input_csrf_token() }} {{ display_input_domain(required=true) }} {{ display_domain_cn() }}

 

{%- endmacro %} {% macro display_list_access_policy_name(policy, enable_input=true) -%} {% if policy %} {% set policy = policy.lower() %} {% if policy not in ['public', 'domain', 'subdomain', 'membersonly', 'moderatorsonly', 'allowedonly', 'membersandmoderatorsonly'] %} {% set policy = 'public' %} {% endif %} {% else %} {% set policy = 'public' %} {% endif %} {% if policy == 'public' %} {{ _('Unrestricted') }} {% elif policy == 'domain' %} {{ _('Users under same domain') }} {% elif policy == 'subdomain' %} {{ _('Users under same domain and its sub-domains') }} {% elif policy == 'membersonly' %} {{ _('Members') }} {% elif policy in ['allowedonly', 'moderatorsonly'] %} {{ _('Moderators') }} {% elif policy == 'membersandmoderatorsonly' %} {{ _('Members and moderators') }} {% else %} {{ _('Unrestricted') }} {% endif %} {% endmacro %} {% macro display_list_access_policies(policy, enable_members_and_moderators_only=true, enable_input=true) -%} {% if policy %} {% set policy = policy.lower() %} {% if policy not in ['public', 'domain', 'subdomain', 'membersonly', 'allowedonly', 'moderatorsonly', 'membersandmoderatorsonly'] %} {% set policy = 'public' %} {% endif %} {# Use 'moderatorsonly' instead of 'allowedonly' #} {% if policy == 'allowedonly' %} {% set policy = 'moderatorsonly' %} {% endif %} {% else %} {% set policy = 'public' %} {% endif %} {% set policies = [ ('public', _('Unrestricted') + '. ' + _('Everyone can send mail to this address')), ('domain', _('Users under same domain')), ('subdomain', _('Users under same domain and its sub-domains')), ('membersonly', _('Members')), ('moderatorsonly', _('Moderators')), ] %} {% if enable_members_and_moderators_only %} {% set policies = policies + [('membersandmoderatorsonly', _('Members and moderators'))] %} {% endif %} {% for p in policies %}
{% if not loop.first %}

 

{% else %}

{{ _('Who can send email to this list') }}

{% endif %} {{ p[1] }}
{% endfor %} {% endmacro %} {% macro highlight_username_in_mail(mail) -%} {{ mail.split('@')[0] |e }}@{{ mail.split('@')[-1] |e }} {% endmacro %} {%- macro display_random_password(password_length, password_policies, replace_ids=None, password_last_change_date=None) -%}
{% if true in password_policies.values() %}

{{ _('Password must contain') }}

{% endif %}
{% set random_password = password_length | generate_random_password %}

{{ _('Need a strong password?') }}

{{ random_password | e }}

{% if password_last_change_date %}

{{ _('Password last change:') }}

{{ password_last_change_date | utc_to_timezone(timezone=session.get('timezone')) }}

{% endif %}
{%- endmacro -%} {% macro show_pages(baseurl, total, cur_page, near_pages=4, sep='/page/', url_suffix='') -%} {% if total % page_size_limit > 0 %} {% set total_pages = total // page_size_limit + 1 %} {% else %} {% set total_pages = total // page_size_limit %} {% endif %} {% set baseurl = baseurl |e %} {% set sep = sep |e %}
{# Show links of 'First Page', 'Previous Page' #} {%- if total_pages > 0 -%} {% if total_pages > 3 %} {{ _('First Page') }} {% endif %} {% if cur_page != 1 and cur_page != 0 %} {% endif %} {%- endif -%} {% if total_pages <= near_pages %} {# Show all cur_page numbers if total pages is less than or equal to 4 pages.#} {% for page_no in range(1, total_pages + 1) %} {{page_no}} {% endfor %} {% else %} {# Show current cur_page number and near numbers.#} {% if cur_page <= near_pages %} {# Show near pages. #} {% if total_pages - cur_page <= near_pages %} {% set end_page = cur_page + (total_pages - cur_page) %} {% else %} {% set end_page = cur_page + near_pages %} {% endif %} {% for page_no in range(1, end_page) %} {% if page_no != cur_page %} {{page_no}} {% else %} {{ cur_page }} {% endif %} {% endfor %} {# Show last page. #} {% if cur_page + near_pages < total_pages %} {% if cur_page + near_pages <= total_pages - 1 %}...{% endif %} {% endif %} {{total_pages}} {% else %} {# Show first page number. #} {%- if cur_page - near_pages == 2 -%} 1 {%- elif cur_page - near_pages > 2 -%} 1 ... {%- endif -%} {# Show nearby pages which number larger than cur_page. #} {% if total_pages - cur_page < near_pages %} {% set end_page = cur_page + (total_pages - cur_page) %} {% else %} {% set end_page = cur_page + near_pages %} {% endif %} {% for page_no in range((cur_page-near_pages), end_page + 1) %} {% if page_no != cur_page %} {{page_no}} {% else %} {{ cur_page }} {% endif %} {% endfor %} {% if total_pages - cur_page > near_pages and total_pages - cur_page != near_pages + 1 %} ... {% endif %} {% if end_page < total_pages %} {{total_pages}} {% endif %} {% endif %} {% endif %} {# -- Show 'Next' and 'Last' -- #} {% if total_pages > 0 %} {% if cur_page < total_pages and cur_page != 0 %} {% endif %} {% if total_pages != 1 %} {{ _('Last Page') }} {% endif %} {% endif %}
{%- endmacro %} {# Convert event code to event name #} {% macro show_event_name(event) -%} {% set event_names = {'all': _('Events'), 'login': _('Admin login'), 'user_login': _('User login (self-service)'), 'create': _('Add account'), 'delete': _('Delete account'), 'disable': _('Disable account'), 'active': _('Activate account'), 'update': _('Edit account profile'), 'grant': _('Grant admin'), 'revoke': _('Revoke admin privilege'), 'backup': _('Backup'), 'update_wblist': _('Update whitelists and blacklists'), 'iredapd': 'iRedAPD', 'unban': _('Unban IP address'), 'delete_mailboxes': _('Delete mailboxes')} %} {% if event in event_names %} {{ event_names[event] }} {% else %} {{ event |e }} {% endif %} {%- endmacro %}