class ParametersForm(AdminParametersForm): app = "webmail" sep3 = SeparatorField(label=_("General")) max_attachment_size = forms.CharField( label=_("Maximum attachment size"), initial="2048", help_text=_("Maximum attachment size in bytes (or KB, MB, GB if specified)") ) sep1 = SeparatorField(label=_("IMAP settings")) imap_server = forms.CharField( label=_("Server address"), initial="127.0.0.1", help_text=_("Address of your IMAP server") ) imap_secured = YesNoField( label=_("Use a secured connection"), initial="no", help_text=_("Use a secured connection to access IMAP server") ) imap_port = forms.IntegerField( label=_("Server port"), initial=143, help_text=_("Listening port of your IMAP server") ) sep2 = SeparatorField(label=_("SMTP settings")) smtp_server = forms.CharField( label=_("Server address"), initial="127.0.0.1", help_text=_("Address of your SMTP server") ) smtp_secured_mode = forms.ChoiceField( label=_("Secured connection mode"), choices=[("none", _("None")), ("starttls", "STARTTLS"), ("ssl", "SSL/TLS")], initial="none", help_text=_("Use a secured connection to access SMTP server"), widget=InlineRadioSelect ) smtp_port = forms.IntegerField( label=_("Server port"), initial=25, help_text=_("Listening port of your SMTP server") ) smtp_authentication = YesNoField( label=_("Authentication required"), initial="no", help_text=_("Server needs authentication") )
class ParametersForm(AdminParametersForm): app = "sievefilters" sep1 = SeparatorField(label=_("ManageSieve settings")) server = forms.CharField( label=_("Server address"), initial="127.0.0.1", help_text=_("Address of your MANAGESIEVE server"), widget=forms.TextInput(attrs={"class": "form-control"})) port = forms.IntegerField( label=_("Server port"), initial=4190, help_text=_("Listening port of your MANAGESIEVE server"), widget=forms.TextInput(attrs={"class": "form-control"})) starttls = YesNoField(label=_("Connect using STARTTLS"), initial="no", help_text=_("Use the STARTTLS extension")) authentication_mech = forms.ChoiceField( label=_("Authentication mechanism"), choices=supported_auth_mechs(), initial="auto", help_text=_("Prefered authentication mechanism"), widget=forms.Select(attrs={"class": "form-control"}))
class ParametersForm(AdminParametersForm): app = "radicale" server_settings = SeparatorField(label=ugettext_lazy("Server settings")) server_location = forms.CharField( label=ugettext_lazy("Server URL"), help_text=ugettext_lazy("The URL of your Radicale server. " "It will be used to construct calendar URLs."), widget=forms.TextInput(attrs={"class": "form-control"})) rights_management_sep = SeparatorField( label=ugettext_lazy("Rights management")) rights_file_path = forms.CharField( label=ugettext_lazy("Rights file's path"), initial="/etc/radicale/rights", help_text=ugettext_lazy( "Path to the file that contains rights definition"), widget=forms.TextInput(attrs={"class": "form-control"})) allow_calendars_administration = YesNoField( label=ugettext_lazy("Allow calendars administration"), initial="no", help_text=ugettext_lazy( "Allow domain administrators to manage user calendars " "(read and write)"))
class AdminParametersForm(parameters.AdminParametersForm): app = "admin" mbsep = SeparatorField(label=ugettext_lazy("Mailboxes")) handle_mailboxes = YesNoField( label=ugettext_lazy("Handle mailboxes on filesystem"), initial="no", help_text=ugettext_lazy("Rename or remove mailboxes on the filesystem when they get renamed or removed within Modoboa") ) mailboxes_owner = forms.CharField( label=ugettext_lazy("Mailboxes ower"), initial="vmail", help_text=ugettext_lazy("The UNIX account who owns mailboxes on the filesystem") ) auto_account_removal = YesNoField( label=ugettext_lazy("Automatic account removal"), initial="no", help_text=ugettext_lazy("When a mailbox is removed, also remove the associated account"), ) # Visibility rules visibility_rules = { "mailboxes_owner": "handle_mailboxes=yes", } def __init__(self, *args, **kwargs): super(AdminParametersForm, self).__init__(*args, **kwargs) hide_fields = False try: code, version = exec_cmd("dovecot --version") except OSError: hide_fields = True else: if code or not version.strip().startswith("2"): hide_fields = True if hide_fields: del self.fields["handle_mailboxes"] del self.fields["mailboxes_owner"]
def extra_mailform_fields(form_name, mailbox=None): """Define extra fields to include in mail forms. For now, only the auto-reply state can be modified. :param str form_name: form name (must be 'mailform') :param Mailbox mailbox: mailbox """ from modoboa.lib.formutils import YesNoField if form_name != "mailform": return [] status = False if mailbox is not None and mailbox.armessage_set.count(): status = mailbox.armessage_set.all()[0].enabled return [ ('autoreply', YesNoField( label=ugettext_lazy("Enable auto-reply"), initial="yes" if status else "no", help_text=ugettext_lazy("Enable or disable Postfix auto-reply"))) ]
class ParametersForm(AdminParametersForm): app = "amavis" qsettings_sep = SeparatorField(label=_("Quarantine settings")) max_messages_age = forms.IntegerField( label=_("Maximum message age"), initial=14, help_text=_( "Quarantine messages maximum age (in days) before deletion")) sep1 = SeparatorField(label=_("Messages releasing")) released_msgs_cleanup = YesNoField( label=_("Remove released messages"), initial="no", help_text=_( "Remove messages marked as released while cleaning up the database" )) am_pdp_mode = forms.ChoiceField( label=_("Amavis connection mode"), choices=[("inet", "inet"), ("unix", "unix")], initial="unix", help_text=_("Mode used to access the PDP server"), widget=InlineRadioSelect) am_pdp_host = forms.CharField( label=_("PDP server address"), initial="localhost", help_text=_("PDP server address (if inet mode)")) am_pdp_port = forms.IntegerField( label=_("PDP server port"), initial=9998, help_text=_("PDP server port (if inet mode)")) am_pdp_socket = forms.CharField( label=_("PDP server socket"), initial="/var/amavis/amavisd.sock", help_text=_("Path to the PDP server socket (if unix mode)")) check_requests_interval = forms.IntegerField( label=_("Check requests interval"), initial=30, help_text=_("Interval between two release requests checks")) user_can_release = YesNoField( label=_("Allow direct release"), initial="no", help_text=_("Allow users to directly release their messages")) self_service = YesNoField(label=_("Enable self-service mode"), initial="no", help_text=_("Activate the 'self-service' mode")) notifications_sender = forms.EmailField( label=_("Notifications sender"), initial="*****@*****.**", help_text=_("The e-mail address used to send notitications")) visibility_rules = { "am_pdp_host": "am_pdp_mode=inet", "am_pdp_port": "am_pdp_mode=inet", "am_pdp_socket": "am_pdp_mode=unix" }
class GeneralParametersForm(parameters.AdminParametersForm): app = "core" sep1 = SeparatorField(label=ugettext_lazy("Authentication")) authentication_type = forms.ChoiceField( label=ugettext_lazy("Authentication type"), choices=[('local', ugettext_lazy("Local")), ('ldap', "LDAP")], initial="local", help_text=ugettext_lazy("The backend used for authentication"), widget=InlineRadioSelect ) password_scheme = forms.ChoiceField( label=ugettext_lazy("Default password scheme"), choices=[("crypt", "crypt"), ("md5", "md5"), ("md5crypt", "md5crypt"), ("sha256", "sha256"), ("plain", "plain")], initial="md5crypt", help_text=ugettext_lazy("Scheme used to crypt mailbox passwords") ) secret_key = forms.CharField( label=ugettext_lazy("Secret key"), initial=random_key(), help_text=ugettext_lazy("Key used to encrypt/decrypt passwords") ) # LDAP specific settings ldap_sep = SeparatorField(label=ugettext_lazy("LDAP settings")) ldap_server_address = forms.CharField( label=ugettext_lazy("Server address"), initial="localhost", help_text=ugettext_lazy("The IP address of the DNS name of the LDAP server") ) ldap_server_port = forms.IntegerField( label=ugettext_lazy("Server port"), initial=389, help_text=ugettext_lazy("The TCP port number used by the LDAP server") ) ldap_secured = YesNoField( label=ugettext_lazy("Use a secured connection"), initial="no", help_text=ugettext_lazy("Use an SSL/TLS connection to access the LDAP server") ) ldap_auth_method = forms.ChoiceField( label=ugettext_lazy("Authentication method"), choices=[('searchbind', ugettext_lazy("Search and bind")), ('directbind', ugettext_lazy("Direct bind"))], initial='searchbind', help_text=ugettext_lazy("Choose the authentication method to use"), widget=InlineRadioSelect ) ldap_bind_dn = forms.CharField( label=ugettext_lazy("Bind DN"), initial='', help_text=ugettext_lazy("The distinguished name to use when binding to the LDAP server. Leave empty for an anonymous bind"), required=False ) ldap_bind_password = forms.CharField( label=ugettext_lazy("Bind password"), initial='', help_text=ugettext_lazy("The password to use when binding to the LDAP server (with 'Bind DN')"), widget=forms.PasswordInput, required=False ) ldap_search_base = forms.CharField( label=ugettext_lazy("Search base"), initial="", help_text=ugettext_lazy("The distinguished name of the search base"), required=False ) ldap_search_filter = forms.CharField( label=ugettext_lazy("Search filter"), initial="(mail=%(user)s)", help_text=ugettext_lazy("An optional filter string (e.g. '(objectClass=person)'). In order to be valid, it must be enclosed in parentheses."), required=False ) ldap_user_dn_template = forms.CharField( label=ugettext_lazy("User DN template"), initial="", help_text=ugettext_lazy("The template used to construct a user's DN. It should contain one placeholder (ie. %(user)s)"), required=False ) ldap_password_attribute = forms.CharField( label=ugettext_lazy("Password attribute"), initial="userPassword", help_text=ugettext_lazy("The attribute used to store user passwords") ) ldap_is_active_directory = YesNoField( label=ugettext_lazy("Active Directory"), initial="no", help_text=ugettext_lazy("Tell if the LDAP server is an Active Directory one") ) sep3 = SeparatorField(label=ugettext_lazy("Miscellaneous")) log_maximum_age = forms.IntegerField( label=ugettext_lazy("Maximum log record age"), initial=365, help_text=ugettext_lazy("The maximum age in days of a log record") ) items_per_page = forms.IntegerField( label=ugettext_lazy("Items per page"), initial=30, help_text=ugettext_lazy("Number of displayed items per page") ) default_top_redirection = forms.ChoiceField( label=ugettext_lazy("Default top redirection"), choices=[], initial="core", help_text=ugettext_lazy("The default redirection used when no application is specified") ) # Visibility rules visibility_rules = { "ldap_sep": "authentication_type=ldap", "ldap_server_address": "authentication_type=ldap", "ldap_server_port": "authentication_type=ldap", "ldap_secured": "authentication_type=ldap", "ldap_auth_method": "authentication_type=ldap", "ldap_bind_dn": "ldap_auth_method=searchbind", "ldap_bind_password": "******", "ldap_search_base": "ldap_auth_method=searchbind", "ldap_search_filter": "ldap_auth_method=searchbind", "ldap_user_dn_template": "ldap_auth_method=directbind", "ldap_password_attribute": "authentication_type=ldap", "ldap_is_active_directory": "authentication_type=ldap" } def __init__(self, *args, **kwargs): super(GeneralParametersForm, self).__init__(*args, **kwargs) self.fields["default_top_redirection"].choices = enabled_applications() def clean_ldap_user_dn_template(self): tpl = self.cleaned_data["ldap_user_dn_template"] try: test = tpl % {"user": "******"} except ValueError: raise forms.ValidationError(_("Invalid syntax")) return tpl def clean(self): """Custom validation method Depending on 'ldap_auth_method' value, we check for different required parameters. """ super(GeneralParametersForm, self).clean() if len(self._errors): raise forms.ValidationError(self._errors) cleaned_data = self.cleaned_data if cleaned_data["authentication_type"] != "ldap": return cleaned_data if cleaned_data["ldap_auth_method"] == "searchbind": required_fields = ["ldap_search_base", "ldap_search_filter"] else: required_fields = ["ldap_user_dn_template"] for f in required_fields: if not f in cleaned_data or cleaned_data[f] == u'': self._errors[f] = self.error_class([_("This field is required")]) return cleaned_data def to_django_settings(self): """Apply LDAP related parameters to Django settings Doing so, we can use the django_auth_ldap module. """ try: import ldap from django_auth_ldap.config import LDAPSearch ldap_available = True except ImportError: ldap_available = False values = self.get_current_values() if not ldap_available or values["authentication_type"] != "ldap": return if not hasattr(settings, "AUTH_LDAP_USER_ATTR_MAP"): setattr(settings, "AUTH_LDAP_USER_ATTR_MAP", { "first_name": "givenName", "email": "mail", "last_name": "sn" }) ldap_uri = 'ldaps://' if values["ldap_secured"] == "yes" else "ldap://" ldap_uri += "%s:%s" % (values["ldap_server_address"], values["ldap_server_port"]) setattr(settings, "AUTH_LDAP_SERVER_URI", ldap_uri) if values["ldap_auth_method"] == "searchbind": setattr(settings, "AUTH_LDAP_BIND_DN", values["ldap_bind_dn"]) setattr(settings, "AUTH_LDAP_BIND_PASSWORD", values["ldap_bind_password"]) search = LDAPSearch( values["ldap_search_base"], ldap.SCOPE_SUBTREE, values["ldap_search_filter"] ) setattr(settings, "AUTH_LDAP_USER_SEARCH", search) else: setattr(settings, "AUTH_LDAP_USER_DN_TEMPLATE", values["ldap_user_dn_template"]) if values["ldap_is_active_directory"] == "yes": if not hasattr(settings, "AUTH_LDAP_GLOBAL_OPTIONS"): setattr(settings, "AUTH_LDAP_GLOBAL_OPTIONS", { ldap.OPT_REFERRALS: False }) else: settings.AUTH_LDAP_GLOBAL_OPTIONS[ldap.OPT_REFERRALS] = False
class GeneralParametersForm(parameters.AdminParametersForm): app = "admin" sep1 = SeparatorField(label=ugettext_lazy("Authentication")) authentication_type = forms.ChoiceField( label=ugettext_lazy("Authentication type"), choices=[('local', ugettext_lazy("Local")), ('ldap', "LDAP")], initial="local", help_text=ugettext_lazy("The backend used for authentication"), widget=InlineRadioSelect) password_scheme = forms.ChoiceField( label=ugettext_lazy("Default password scheme"), choices=[("crypt", "crypt"), ("md5", "md5"), ("md5crypt", "md5crypt"), ("sha256", "sha256"), ("plain", "plain")], initial="md5crypt", help_text=ugettext_lazy("Scheme used to crypt mailbox passwords")) secret_key = forms.CharField( label=ugettext_lazy("Secret key"), initial=random_key(), help_text=ugettext_lazy("Key used to encrypt/decrypt passwords")) # LDAP specific settings ldap_sep = SeparatorField(label=ugettext_lazy("LDAP settings")) ldap_server_address = forms.CharField( label=ugettext_lazy("Server address"), initial="localhost", help_text=ugettext_lazy( "The IP address of the DNS name of the LDAP server")) ldap_server_port = forms.IntegerField( label=ugettext_lazy("Server port"), initial=389, help_text=ugettext_lazy("The TCP port number used by the LDAP server")) ldap_secured = YesNoField( label=ugettext_lazy("Use a secured connection"), initial="no", help_text=ugettext_lazy( "Use an SSL/TLS connection to access the LDAP server")) ldap_auth_method = forms.ChoiceField( label=ugettext_lazy("Authentication method"), choices=[('searchbind', ugettext_lazy("Search and bind")), ('directbind', ugettext_lazy("Direct bind"))], initial='searchbind', help_text=ugettext_lazy("Choose the authentication method to use"), widget=InlineRadioSelect) ldap_bind_dn = forms.CharField( label=ugettext_lazy("Bind DN"), initial='', help_text=ugettext_lazy( "The distinguished name to use when binding to the LDAP server. Leave empty for an anonymous bind" ), required=False) ldap_bind_password = forms.CharField( label=ugettext_lazy("Bind password"), initial='', help_text=ugettext_lazy( "The password to use when binding to the LDAP server (with 'Bind DN')" ), widget=forms.PasswordInput, required=False) ldap_search_base = forms.CharField( label=ugettext_lazy("Search base"), initial="", help_text=ugettext_lazy("The distinguished name of the search base"), required=False) ldap_search_filter = forms.CharField( label=ugettext_lazy("Search filter"), initial="(mail=%(user)s)", help_text=ugettext_lazy( "An optional filter string (e.g. '(objectClass=person)'). In order to be valid, it must be enclosed in parentheses." ), required=False) ldap_user_dn_template = forms.CharField( label=ugettext_lazy("User DN template"), initial="", help_text=ugettext_lazy( "The template used to construct a user's DN. It should contain one placeholder (ie. %(user)s)" ), required=False) ldap_password_attribute = forms.CharField( label=ugettext_lazy("Password attribute"), initial="userPassword", help_text=ugettext_lazy("The attribute used to store user passwords")) ldap_is_active_directory = YesNoField( label=ugettext_lazy("Active Directory"), initial="no", help_text=ugettext_lazy( "Tell if the LDAP server is an Active Directory one")) sep2 = SeparatorField(label=ugettext_lazy("Mailboxes")) handle_mailboxes = YesNoField( label=ugettext_lazy("Handle mailboxes on filesystem"), initial="no", help_text=ugettext_lazy( "Rename or remove mailboxes on the filesystem when they get renamed or removed within Modoboa" )) mailboxes_owner = forms.CharField( label=ugettext_lazy("Mailboxes ower"), initial="vmail", help_text=ugettext_lazy( "The UNIX account who owns mailboxes on the filesystem")) auto_account_removal = YesNoField( label=ugettext_lazy("Automatic account removal"), initial="no", help_text=ugettext_lazy( "When a mailbox is removed, also remove the associated account"), ) sep3 = SeparatorField(label=ugettext_lazy("Miscellaneous")) log_maximum_age = forms.IntegerField( label=ugettext_lazy("Maximum log record age"), initial=365, help_text=ugettext_lazy("The maximum age in days of a log record")) items_per_page = forms.IntegerField( label=ugettext_lazy("Items per page"), initial=30, help_text=ugettext_lazy("Number of displayed items per page")) default_top_redirection = forms.ChoiceField( label=ugettext_lazy("Default top redirection"), choices=[], initial="admin", help_text=ugettext_lazy( "The default redirection used when no application is specified")) # Visibility rules visibility_rules = { "mailboxes_owner": "handle_mailboxes=yes", "ldap_sep": "authentication_type=ldap", "ldap_server_address": "authentication_type=ldap", "ldap_server_port": "authentication_type=ldap", "ldap_secured": "authentication_type=ldap", "ldap_auth_method": "authentication_type=ldap", "ldap_bind_dn": "ldap_auth_method=searchbind", "ldap_bind_password": "******", "ldap_search_base": "ldap_auth_method=searchbind", "ldap_search_filter": "ldap_auth_method=searchbind", "ldap_user_dn_template": "ldap_auth_method=directbind", "ldap_password_attribute": "authentication_type=ldap", "ldap_is_active_directory": "authentication_type=ldap" } def __init__(self, *args, **kwargs): super(GeneralParametersForm, self).__init__(*args, **kwargs) self.fields["default_top_redirection"].choices = enabled_applications() hide_fields = False try: code, version = exec_cmd("dovecot --version") except OSError, e: hide_fields = True else:
class UserSettings(UserParametersForm): app = "webmail" sep1 = SeparatorField(label=_("Display")) displaymode = forms.ChoiceField( initial="plain", label=_("Default message display mode"), choices=[("html", "html"), ("plain", "text")], help_text=_("The default mode used when displaying a message"), widget=InlineRadioSelect()) enable_links = YesNoField(initial="no", label=_("Enable HTML links display"), help_text=_("Enable/Disable HTML links display")) messages_per_page = forms.IntegerField( initial=40, label=_("Number of displayed emails per page"), help_text=_("Sets the maximum number of messages displayed in a page")) refresh_interval = forms.IntegerField( initial=300, label=_("Listing refresh rate"), help_text=_("Automatic folder refresh rate (in seconds)")) mboxes_col_width = forms.IntegerField( initial=200, label=_("Mailboxes container's width"), help_text=_("The width of the mailbox list container")) sep2 = SeparatorField(label=_("Mailboxes")) trash_folder = forms.CharField( initial="Trash", label=_("Trash folder"), help_text=_("Folder where deleted messages go")) sent_folder = forms.CharField( initial="Sent", label=_("Sent folder"), help_text=_("Folder where copies of sent messages go")) drafts_folder = forms.CharField(initial="Drafts", label=_("Drafts folder"), help_text=_("Folder where drafts go")) sep3 = SeparatorField(label=_("Composing messages")) editor = forms.ChoiceField( initial="plain", label=_("Default editor"), choices=[("html", "html"), ("plain", "text")], help_text=_("The default editor to use when composing a message"), widget=InlineRadioSelect()) signature = forms.CharField(initial="", label=_("Signature text"), help_text=_("User defined email signature"), required=False) visibility_rules = {"enable_links": "displaymode=html"} @staticmethod def has_access(user): return user.mailbox_set.count() != 0 def clean_mboxes_col_width(self): """Check if the entered value is a positive integer. It must also be different from 0. """ if self.cleaned_data['mboxes_col_width'] <= 0: raise forms.ValidationError( _('Value must be a positive integer (> 0)')) return self.cleaned_data['mboxes_col_width']
class ParametersForm(AdminParametersForm): """Extension settings.""" app = "amavis" qsettings_sep = SeparatorField(label=_("Quarantine settings")) max_messages_age = forms.IntegerField( label=_("Maximum message age"), initial=14, help_text=_( "Quarantine messages maximum age (in days) before deletion")) sep1 = SeparatorField(label=_("Messages releasing")) released_msgs_cleanup = YesNoField( label=_("Remove released messages"), initial="no", help_text=_("Remove messages marked as released while cleaning up " "the database")) am_pdp_mode = forms.ChoiceField( label=_("Amavis connection mode"), choices=[("inet", "inet"), ("unix", "unix")], initial="unix", help_text=_("Mode used to access the PDP server"), widget=InlineRadioSelect(attrs={"type": "checkbox"})) am_pdp_host = forms.CharField( label=_("PDP server address"), initial="localhost", help_text=_("PDP server address (if inet mode)"), widget=forms.TextInput(attrs={"class": "form-control"})) am_pdp_port = forms.IntegerField( label=_("PDP server port"), initial=9998, help_text=_("PDP server port (if inet mode)")) am_pdp_socket = forms.CharField( label=_("PDP server socket"), initial="/var/amavis/amavisd.sock", help_text=_("Path to the PDP server socket (if unix mode)")) user_can_release = YesNoField( label=_("Allow direct release"), initial="no", help_text=_("Allow users to directly release their messages")) self_service = YesNoField(label=_("Enable self-service mode"), initial="no", help_text=_("Activate the 'self-service' mode")) notifications_sender = forms.EmailField( label=_("Notifications sender"), initial="*****@*****.**", help_text=_("The e-mail address used to send notitications")) lsep = SeparatorField(label=_("Manual learning")) manual_learning = YesNoField( label=_("Enable manual learning"), initial="yes", help_text=_( "Allow super administrators to manually train Spamassassin")) sa_is_local = YesNoField( label=_("Is Spamassassin local?"), initial="yes", help_text=_( "Tell if Spamassassin is running on the same server than modoboa")) default_user = forms.CharField( label=_("Default user"), initial="amavis", help_text=_("Name of the user owning the default bayesian database")) spamd_address = forms.CharField( label=_("Spamd address"), initial="127.0.0.1", help_text=_("The IP address where spamd can be reached")) spamd_port = forms.IntegerField( label=_("Spamd port"), initial=783, help_text=_("The TCP port spamd is listening on")) domain_level_learning = YesNoField( label=_("Enable per-domain manual learning"), initial="no", help_text=_("Allow domain administrators to train Spamassassin " "(within dedicated per-domain databases)")) user_level_learning = YesNoField( label=_("Enable per-user manual learning"), initial="no", help_text=_("Allow simple users to personally train Spamassassin " "(within a dedicated database)")) visibility_rules = { "am_pdp_host": "am_pdp_mode=inet", "am_pdp_port": "am_pdp_mode=inet", "am_pdp_socket": "am_pdp_mode=unix", "sa_is_local": "manual_learning=yes", "default_user": "******", "spamd_address": "sa_is_local=no", "spamd_port": "sa_is_local=no", "domain_level_learning": "manual_learning=yes", "user_level_learning": "manual_learning=yes" }
class UserSettings(UserParametersForm): app = "webmail" sep1 = SeparatorField(label=_("Display")) displaymode = forms.ChoiceField( initial="plain", label=_("Default message display mode"), choices=[("html", "html"), ("plain", "text")], help_text=_("The default mode used when displaying a message"), widget=InlineRadioSelect) enable_links = YesNoField(initial="no", label=_("Enable HTML links display"), help_text=_("Enable/Disable HTML links display")) messages_per_page = forms.IntegerField( initial=40, label=_("Number of displayed emails per page"), help_text=_("Sets the maximum number of messages displayed in a page")) refresh_interval = forms.IntegerField( initial=300, label=_("Listing refresh rate"), help_text=_("Automatic folder refresh rate (in seconds)")) sep2 = SeparatorField(label=_("Mailboxes")) trash_folder = forms.CharField( initial="Trash", label=_("Trash folder"), help_text=_("Folder where deleted messages go")) sent_folder = forms.CharField( initial="Sent", label=_("Sent folder"), help_text=_("Folder where copies of sent messages go")) drafts_folder = forms.CharField(initial="Drafts", label=_("Drafts folder"), help_text=_("Folder where drafts go")) sep3 = SeparatorField(label=_("Composing messages")) editor = forms.ChoiceField( initial="plain", label=_("Default editor"), choices=[("html", "html"), ("plain", "text")], help_text=_("The default editor to use when composing a message"), widget=InlineRadioSelect) signature = forms.CharField(initial="", label=_("Signature text"), help_text=_("User defined email signature"), widget=forms.widgets.Textarea, required=False) visibility_rules = {"enable_links": "displaymode=html"} @staticmethod def has_access(user): return user.has_mailbox
class AdminParametersForm(parameters.AdminParametersForm): app = "admin" mbsep = SeparatorField(label=ugettext_lazy("Mailboxes")) handle_mailboxes = YesNoField( label=ugettext_lazy("Handle mailboxes on filesystem"), initial="no", help_text=ugettext_lazy( "Rename or remove mailboxes on the filesystem when they get renamed or removed within Modoboa" )) mailboxes_owner = forms.CharField( label=ugettext_lazy("Mailboxes ower"), initial="vmail", help_text=ugettext_lazy( "The UNIX account who owns mailboxes on the filesystem")) default_domain_quota = forms.IntegerField( label=ugettext_lazy("Default domain quota"), initial=0, help_text=ugettext_lazy( "Default quota (in MB) applied to freshly created domains with no " "value specified. A value of 0 means no quota."), widget=forms.TextInput(attrs={'class': 'span2'})) auto_account_removal = YesNoField( label=ugettext_lazy("Automatic account removal"), initial="no", help_text=ugettext_lazy( "When a mailbox is removed, also remove the associated account")) # Visibility rules visibility_rules = { "mailboxes_owner": "handle_mailboxes=yes", } def __init__(self, *args, **kwargs): super(AdminParametersForm, self).__init__(*args, **kwargs) hide_fields = False dpath = None code, output = exec_cmd("which dovecot") if not code: dpath = output.strip() else: known_paths = getattr( settings, "DOVECOT_LOOKUP_PATH", ("/usr/sbin/dovecot", "/usr/local/sbin/dovecot")) for fpath in known_paths: if os.path.isfile(fpath) and os.access(fpath, os.X_OK): dpath = fpath if dpath: try: code, version = exec_cmd("%s --version" % dpath) except OSError: hide_fields = True else: if code or not version.strip().startswith("2"): hide_fields = True else: hide_fields = True if hide_fields: del self.fields["handle_mailboxes"] del self.fields["mailboxes_owner"] def clean_default_domain_quota(self): """Ensure quota is a positive integer.""" if self.cleaned_data['default_domain_quota'] < 0: raise forms.ValidationError( ugettext_lazy('Must be a positive integer')) return self.cleaned_data['default_domain_quota']
class DomainFormOptions(forms.Form): create_dom_admin = YesNoField( label=ugettext_lazy("Create a domain administrator"), initial="no", help_text=ugettext_lazy( "Automatically create an administrator for this domain" ) ) dom_admin_username = forms.CharField( label=ugettext_lazy("Name"), initial="admin", help_text=ugettext_lazy( "The administrator's name. Don't include the domain's name here, " "it will be automatically appended." ), required=False ) create_aliases = YesNoField( label=ugettext_lazy("Create aliases"), initial="yes", help_text=ugettext_lazy( "Automatically create standard aliases for this domain" ), required=False ) def __init__(self, user, *args, **kwargs): super(DomainFormOptions, self).__init__(*args, **kwargs) if False in events.raiseQueryEvent('UserCanSetRole', user, 'DomainAdmins'): self.fields = {} return if args: if args[0].get("create_dom_admin", "no") == "yes": self.fields["dom_admin_username"].required = True self.fields["create_aliases"].required = True def clean_dom_admin_username(self): """Ensure admin username is an email address.""" if '@' in self.cleaned_data["dom_admin_username"]: raise forms.ValidationError(_("Invalid format")) return self.cleaned_data["dom_admin_username"] def save(self, user, domain): if not self.fields: return if self.cleaned_data["create_dom_admin"] == "no": return username = "******" % ( self.cleaned_data["dom_admin_username"], domain.name) try: da = User.objects.get(username=username) except User.DoesNotExist: pass else: raise Conflict(_("User '%s' already exists" % username)) events.raiseEvent("CanCreate", user, "mailboxes") da = User(username=username, email=username, is_active=True) da.set_password("password") da.save() da.set_role("DomainAdmins") da.post_create(user) mb = Mailbox( address=self.cleaned_data["dom_admin_username"], domain=domain, user=da, use_domain_quota=True ) mb.set_quota(override_rules=user.has_perm("admin.change_domain")) mb.save(creator=user) if self.cleaned_data["create_aliases"] == "yes": events.raiseEvent("CanCreate", user, "mailbox_aliases") alias = Alias(address="postmaster", domain=domain, enabled=True) alias.save(int_rcpts=[mb]) alias.post_create(user) domain.add_admin(da)