mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-12-04 19:15:30 +00:00
Merge pull request #1440 from benshalev849/custom_current_user
Added custom header to be used in the created_by column.
This commit is contained in:
commit
6a5bc8adeb
17
docs/wiki/configuration/basic_settings.md
Normal file
17
docs/wiki/configuration/basic_settings.md
Normal file
@ -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.
|
@ -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,
|
||||
|
@ -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',
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user