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 33b8db5..08b4b89 100644 --- a/powerdnsadmin/models/setting.py +++ b/powerdnsadmin/models/setting.py @@ -190,7 +190,8 @@ class Setting(db.Model): 'otp_field_enabled': True, 'custom_css': '', 'otp_force': False, - 'max_history_records': 1000 + 'max_history_records': 1000, + 'account_name_extra_chars': False } def __init__(self, id=None, name=None, value=None): @@ -271,15 +272,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 @@ -287,7 +288,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 5573502..fc74eaa 100644 --- a/powerdnsadmin/routes/admin.py +++ b/powerdnsadmin/routes/admin.py @@ -1260,7 +1260,9 @@ 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' + 'delete_sso_accounts', 'otp_field_enabled', 'custom_css', 'enable_api_rr_history', 'max_history_records', 'otp_force', + '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 9893ff6..8682960 100644 --- a/powerdnsadmin/routes/index.py +++ b/powerdnsadmin/routes/index.py @@ -403,7 +403,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 = '' @@ -413,7 +413,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: @@ -1088,8 +1088,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.