diff --git a/docs/wiki/configuration/basic_settings.md b/docs/wiki/configuration/basic_settings.md new file mode 100644 index 0000000..6a47d6a --- /dev/null +++ b/docs/wiki/configuration/basic_settings.md @@ -0,0 +1,17 @@ +### PowerDNSAdmin basic settings + +PowerDNSAdmin has many features and settings available to be turned either off or on. +In this docs those settings will be explain. +To find the settings in the the dashboard go to settings>basic. + +allow_user_create_domain: This setting is used to allow users with the `user` role to create a domain, not possible by +default. + +allow_user_remove_domain: Same as `allow_user_create_domain` but for removing a domain. + +allow_user_view_history: Allow a user with the role `user` to view and access the history. + +custom_history_header: This is a string type variable, when inputting an header name, if exists in the request it will +be in the created_by column in the history, if empty or not mentioned will default to the api_key description. + +site_name: This will be the site name. diff --git a/powerdnsadmin/models/setting.py b/powerdnsadmin/models/setting.py index bef6897..2b1c7d7 100644 --- a/powerdnsadmin/models/setting.py +++ b/powerdnsadmin/models/setting.py @@ -28,6 +28,7 @@ class Setting(db.Model): 'allow_user_create_domain': False, 'allow_user_remove_domain': False, 'allow_user_view_history': False, + 'custom_history_header': '', 'delete_sso_accounts': False, 'bg_domain_updates': False, 'enable_api_rr_history': True, diff --git a/powerdnsadmin/routes/admin.py b/powerdnsadmin/routes/admin.py index 900e70c..4333977 100644 --- a/powerdnsadmin/routes/admin.py +++ b/powerdnsadmin/routes/admin.py @@ -1391,6 +1391,7 @@ def setting_basic(): 'default_domain_table_size', 'default_record_table_size', 'delete_sso_accounts', + 'custom_history_header', 'deny_domain_override', 'dnssec_admins_only', 'enable_api_rr_history', diff --git a/powerdnsadmin/routes/api.py b/powerdnsadmin/routes/api.py index 2c9a2cc..e764f91 100644 --- a/powerdnsadmin/routes/api.py +++ b/powerdnsadmin/routes/api.py @@ -48,6 +48,12 @@ user_detailed_schema = UserDetailedSchema() account_schema = AccountSchema(many=True) account_single_schema = AccountSchema() +def is_custom_header_api(): + custom_header_setting = Setting().get('custom_history_header') + if custom_header_setting != '' and custom_header_setting in request.headers: + return request.headers[custom_header_setting] + else: + return g.apikey.description def get_user_domains(): domains = db.session.query(Domain) \ @@ -1104,6 +1110,7 @@ def api_zone_forward(server_id, zone_id): domain = Domain() domain.update() status = resp.status_code + created_by_value=is_custom_header_api() if 200 <= status < 300: current_app.logger.debug("Request to powerdns API successful") if Setting().get('enable_api_rr_history'): @@ -1116,19 +1123,19 @@ def api_zone_forward(server_id, zone_id): 'add_rrsets': list(filter(lambda r: r['changetype'] == "REPLACE", data['rrsets'])), 'del_rrsets': list(filter(lambda r: r['changetype'] == "DELETE", data['rrsets'])) }), - created_by=g.apikey.description, + created_by=created_by_value, domain_id=Domain().get_id_by_name(zone_id.rstrip('.'))) history.add() elif request.method == 'DELETE': history = History(msg='Deleted zone {0}'.format(zone_id.rstrip('.')), detail='', - created_by=g.apikey.description, + created_by=created_by_value, domain_id=Domain().get_id_by_name(zone_id.rstrip('.'))) history.add() elif request.method != 'GET': history = History(msg='Updated zone {0}'.format(zone_id.rstrip('.')), detail='', - created_by=g.apikey.description, + created_by=created_by_value, domain_id=Domain().get_id_by_name(zone_id.rstrip('.'))) history.add() return resp.content, resp.status_code, resp.headers.items() @@ -1152,6 +1159,7 @@ def api_create_zone(server_id): if resp.status_code == 201: current_app.logger.debug("Request to powerdns API successful") + created_by_value=is_custom_header_api() data = request.get_json(force=True) if g.apikey.role.name not in ['Administrator', 'Operator']: @@ -1166,7 +1174,7 @@ def api_create_zone(server_id): history = History(msg='Add domain {0}'.format( data['name'].rstrip('.')), detail=json.dumps(data), - created_by=g.apikey.description, + created_by=created_by_value, domain_id=domain.get_id_by_name(data['name'].rstrip('.'))) history.add()