diff --git a/powerdnsadmin/models/account.py b/powerdnsadmin/models/account.py index 4e3ca97..7425afc 100644 --- a/powerdnsadmin/models/account.py +++ b/powerdnsadmin/models/account.py @@ -34,8 +34,12 @@ class Account(db.Model): self.API_EXTENDED_URL = utils.pdns_api_extended_uri(self.PDNS_VERSION) if self.name is not None: + if Setting().get('account_name_extra_chars'): + char_list = "abcdefghijklmnopqrstuvwxyz0123456789_-." + else: + char_list = "abcdefghijklmnopqrstuvwxyz0123456789" self.name = ''.join(c for c in self.name.lower() - if c in "abcdefghijklmnopqrstuvwxyz0123456789_-") + if c in char_list) def __repr__(self): return ''.format(self.name) diff --git a/powerdnsadmin/models/setting.py b/powerdnsadmin/models/setting.py index cdeb865..51e78e5 100644 --- a/powerdnsadmin/models/setting.py +++ b/powerdnsadmin/models/setting.py @@ -192,7 +192,8 @@ class Setting(db.Model): 'custom_css': '', 'otp_force': False, 'max_history_records': 1000, - 'deny_domain_override': False + 'deny_domain_override': False, + 'account_name_extra_chars': False } def __init__(self, id=None, name=None, value=None): @@ -273,15 +274,15 @@ class Setting(db.Model): def get(self, setting): if setting in self.defaults: - + if setting.upper() in current_app.config: result = current_app.config[setting.upper()] else: result = self.query.filter(Setting.name == setting).first() - + if result is not None: if hasattr(result,'value'): - result = result.value + result = result.value return strtobool(result) if result in [ 'True', 'False' ] else result @@ -289,7 +290,7 @@ class Setting(db.Model): return self.defaults[setting] else: current_app.logger.error('Unknown setting queried: {0}'.format(setting)) - + def get_records_allow_to_edit(self): return list( set(self.get_forward_records_allow_to_edit() + diff --git a/powerdnsadmin/routes/admin.py b/powerdnsadmin/routes/admin.py index b0adc61..c5f28d1 100644 --- a/powerdnsadmin/routes/admin.py +++ b/powerdnsadmin/routes/admin.py @@ -1268,7 +1268,8 @@ def setting_basic(): 'allow_user_create_domain', 'allow_user_remove_domain', 'allow_user_view_history', 'bg_domain_updates', 'site_name', 'session_timeout', 'warn_session_timeout', 'ttl_options', 'pdns_api_timeout', 'verify_ssl_connections', 'verify_user_email', - 'delete_sso_accounts', 'otp_field_enabled', 'custom_css', 'enable_api_rr_history', 'max_history_records', 'otp_force', 'deny_domain_override', 'enforce_api_ttl' + 'delete_sso_accounts', 'otp_field_enabled', 'custom_css', 'enable_api_rr_history', 'max_history_records', 'otp_force', + 'deny_domain_override', 'enforce_api_ttl', 'account_name_extra_chars' ] return render_template('admin_setting_basic.html', settings=settings) diff --git a/powerdnsadmin/routes/index.py b/powerdnsadmin/routes/index.py index 342b06e..6f5f0e2 100644 --- a/powerdnsadmin/routes/index.py +++ b/powerdnsadmin/routes/index.py @@ -401,7 +401,7 @@ def login(): if name_prop in me and desc_prop in me: accounts_name_prop = [me[name_prop]] if type(me[name_prop]) is not list else me[name_prop] accounts_desc_prop = [me[desc_prop]] if type(me[desc_prop]) is not list else me[desc_prop] - + #Run on all groups the user is in by the index num. for i in range(len(accounts_name_prop)): description = '' @@ -411,7 +411,7 @@ def login(): account_to_add.append(account) user_accounts = user.get_accounts() - + # Add accounts for account in account_to_add: if account not in user_accounts: @@ -1092,8 +1092,12 @@ def create_group_to_account_mapping(): def handle_account(account_name, account_description=""): + if Setting().get('account_name_extra_chars'): + char_list = "abcdefghijklmnopqrstuvwxyz0123456789_-." + else: + char_list = "abcdefghijklmnopqrstuvwxyz0123456789" clean_name = ''.join(c for c in account_name.lower() - if c in "abcdefghijklmnopqrstuvwxyz0123456789_-") + if c in char_list) if len(clean_name) > Account.name.type.length: current_app.logger.error( "Account name {0} too long. Truncated.".format(clean_name)) diff --git a/powerdnsadmin/templates/admin_edit_account.html b/powerdnsadmin/templates/admin_edit_account.html index 0514ead..1946bc9 100644 --- a/powerdnsadmin/templates/admin_edit_account.html +++ b/powerdnsadmin/templates/admin_edit_account.html @@ -49,7 +49,7 @@ {% if invalid_accountname %} Cannot be blank and must only contain alphanumeric - characters, hyphens or underscores. + characters{% if SETTING.get('account_name_extra_chars') %}, dots, hyphens or underscores{% endif %}. {% elif duplicate_accountname %} Account name already in use. {% endif %} @@ -113,7 +113,8 @@

Fill in all the fields to the in the form to the left.

Name is an account identifier. It will be lowercased and can contain alphanumeric - characters, hyphens and underscores (no space or other special character is allowed).
+ characters{% if SETTING.get('account_name_extra_chars') %}, dots, hyphens and underscores (no space or other special character is allowed) + {% else %} (no extra character is allowed){% endif %}.
Description is a user friendly name for this account.
Contact person is the name of a contact person at the account.
Mail Address is an e-mail address for the contact person.