diff --git a/powerdnsadmin/routes/admin.py b/powerdnsadmin/routes/admin.py
index b2c3af6..e01f258 100644
--- a/powerdnsadmin/routes/admin.py
+++ b/powerdnsadmin/routes/admin.py
@@ -4,7 +4,7 @@ import traceback
import re
from base64 import b64encode
from ast import literal_eval
-from flask import Blueprint, render_template, make_response, url_for, current_app, request, redirect, jsonify, abort, flash, session
+from flask import Blueprint, render_template, render_template_string, make_response, url_for, current_app, request, redirect, jsonify, abort, flash, session
from flask_login import login_required, current_user
from ..decorators import operator_role_required, admin_role_required, history_access_required
@@ -752,119 +752,142 @@ def manage_account():
'There is something wrong, please contact Administrator.'
}), 400)
-# check for lower key as well for old databases
-def get_key_val(dict, k):
- key_lowercase = k.lower()
- if k in dict.keys():
- return str(dict[k])
- elif key_lowercase in dict.keys():
- return str(dict[key_lowercase])
- else:
- return ""
+
class DetailedHistory():
- def __init__(self, history, change_set):
- self.history = history
- self.detailed_msg = ""
- self.change_set = change_set
-
- if not history.detail:
- self.detailed_msg = ""
- return
- if 'add_rrest' not in history.detail:
- detail_dict = json.loads(history.detail.replace("'", '"'))
- else:
- detail_dict = json.loads(history.detail.replace("\'", ''))
- key_array = list(detail_dict.keys())
- if 'domain_type' in detail_dict.keys() and 'account_id' in detail_dict.keys(): # this is a domain creation
- self.detailed_msg = """
-
Domain type: | {0} |
Account: | {1} |
- """.format(detail_dict['domain_type'],
- Account.get_name_by_id(self=None, account_id=detail_dict['account_id']) if detail_dict['account_id'] != "0" else "None")
- elif 'authenticator' in detail_dict.keys(): # this is a user authentication
- self.detailed_msg = """
-
-
-
-
- User {0} authentication success
- |
- """.format(detail_dict['username'])
+ if not history.detail:
+ self.detailed_msg = ""
+ return
- else:
- self.detailed_msg+= """
- rgba(201,48,44);">
- User {0} authentication failure
-
- """.format(detail_dict['username'])
+ if 'add_rrest' in history.detail:
+ detail_dict = json.loads(history.detail.replace("\'", ''))
+ else:
+ detail_dict = json.loads(history.detail.replace("'", '"'))
+
+ if 'domain_type' in detail_dict and 'account_id' in detail_dict: # this is a domain creation
+ self.detailed_msg = render_template_string("""
+
+ Domain type: | {{ domaintype }} |
+ Account: | {{ account }} |
+
+ """,
+ domaintype=detail_dict['domain_type'],
+ account=Account.get_name_by_id(self=None, account_id=detail_dict['account_id']) if detail_dict['account_id'] != "0" else "None")
+
+ elif 'authenticator' in detail_dict: # this is a user authentication
+ self.detailed_msg = render_template_string("""
+
+
+
+
+ User {{ username }} authentication {{ auth_result }}
+ |
+
+
+
+
+ Authenticator Type: |
+ {{ authenticator }} |
+
+
+ IP Address |
+ {{ ip_address }} |
+
+
+
+ """,
+ background_rgba="68,157,68" if detail_dict['success'] == 1 else "201,48,44",
+ username=detail_dict['username'],
+ auth_result="success" if detail_dict['success'] == 1 else "failure",
+ authenticator=detail_dict['authenticator'],
+ ip_address=detail_dict['ip_address'])
+
+ elif 'add_rrests' in detail_dict: # this is a domain record change
+ # changes_set = []
+ self.detailed_msg = ""
+ # extract_changelogs_from_a_history_entry(changes_set, history, 0)
+
+ elif 'name' in detail_dict and 'template' in history.msg: # template creation / deletion
+ self.detailed_msg = render_template_string("""
+
+ Template name: | {{ template_name }} |
+ Description: | {{ description }} |
+
+ """,
+ template_name=DetailedHistory.get_key_val(detail_dict, "name"),
+ description=DetailedHistory.get_key_val(detail_dict, "description"))
+
+ elif 'Change domain' in history.msg and 'access control' in history.msg: # added or removed a user from a domain
+ users_with_access = DetailedHistory.get_key_val(detail_dict, "user_has_access")
+ self.detailed_msg = render_template_string("""
+
+ Users with access to this domain | {{ users_with_access }} |
+ Number of users: | {{ users_with_access | length }} |
+
+ """,
+ users_with_access=users_with_access)
+
+ elif 'Created API key' in history.msg or 'Updated API key' in history.msg:
+ self.detailed_msg = render_template_string("""
+
+ Key: | {{ keyname }} |
+ Role: | {{ rolename }} |
+ Description: | {{ description }} |
+ Accessible domains with this API key: | {{ linked_domains }} |
+ Accessible accounts with this API key: | {{ linked_accounts }} |
+
+ """,
+ keyname=DetailedHistory.get_key_val(detail_dict, "key"),
+ rolename=DetailedHistory.get_key_val(detail_dict, "role"),
+ description=DetailedHistory.get_key_val(detail_dict, "description"),
+ linked_domains=DetailedHistory.get_key_val(detail_dict, "domains"),
+ linked_accounts=DetailedHistory.get_key_val(detail_dict, "accounts"))
+
+ elif 'Delete API key' in history.msg:
+ self.detailed_msg = render_template_string("""
+
+ Key: | {{ keyname }} |
+ Role: | {{ rolename }} |
+ Description: | {{ description }} |
+ Accessible domains with this API key: | {{ linked_domains }} |
+
+ """,
+ keyname=DetailedHistory.get_key_val(detail_dict, "key"),
+ rolename=DetailedHistory.get_key_val(detail_dict, "role"),
+ description=DetailedHistory.get_key_val(detail_dict, "description"),
+ linked_domains=DetailedHistory.get_key_val(detail_dict, "domains"))
+
+ elif 'Update type for domain' in history.msg:
+ self.detailed_msg = render_template_string("""
+
+ Domain: | {{ domain }} |
+ Domain type: | {{ domain_type }} |
+ Masters: | {{ masters }} |
+
+ """,
+ domain=DetailedHistory.get_key_val(detail_dict, "domain"),
+ domain_type=DetailedHistory.get_key_val(detail_dict, "type"),
+ masters=DetailedHistory.get_key_val(detail_dict, "masters"))
+
+ elif 'reverse' in history.msg:
+ self.detailed_msg = render_template_string("""
+
+ Domain Type: | {{ domain_type }} |
+ Domain Master IPs: | {{ domain_master_ips }} |
+
+ """,
+ domain_type=DetailedHistory.get_key_val(detail_dict, "domain_type"),
+ domain_master_ips=DetailedHistory.get_key_val(detail_dict, "domain_master_ips"))
+
+ # check for lower key as well for old databases
+ @staticmethod
+ def get_key_val(_dict, key):
+ return _dict.get(key, _dict.get(key.lower(), ''))
- self.detailed_msg+= """
-
-
-
-
- Authenticator Type: |
- {0} |
-
-
- IP Address |
- {1} |
-
-
-
- """.format(detail_dict['authenticator'], detail_dict['ip_address'])
- elif 'add_rrests' in detail_dict.keys(): # this is a domain record change
- # changes_set = []
- self.detailed_msg = ""
- # extract_changelogs_from_a_history_entry(changes_set, history, 0)
- elif 'name' in detail_dict.keys() and 'template' in history.msg: # template creation
- self.detailed_msg = """
- Template name: | {0} |
Description: | {1} |
- """.format(get_key_val(detail_dict, key_array[0]), get_key_val(detail_dict, key_array[1]))
- elif 'Change domain' in history.msg and 'access control' in history.msg: # added or removed a user from a domain
- self.detailed_msg = """
- Users with access to this domain | {0} |
Number of users: | {1} |
|
- """.format(get_key_val(detail_dict, key_array[0]), len((detail_dict[key_array[0]])))
- elif 'Created API key' in history.msg or 'Updated API key' in history.msg:
- self.detailed_msg = """
-
- Key: | {0} |
- Role: | {1} |
- Description: | {2} |
- Accessible domains with this API key: | {3} |
-
- """.format(get_key_val(detail_dict, key_array[0]), get_key_val(detail_dict, key_array[1]),
- get_key_val(detail_dict, key_array[2]), get_key_val(detail_dict, key_array[3]))
- elif 'Update type for domain' in history.msg:
- self.detailed_msg = """
-
- Domain: | {0} |
- Domain type: | {1} |
- Masters: | {2} |
-
- """.format(get_key_val(detail_dict, key_array[0]), get_key_val(detail_dict, key_array[1]), get_key_val(detail_dict, key_array[2]))
- elif 'Delete API key' in history.msg:
- self.detailed_msg = """
-
- Key: | {0} |
- Role: | {1} |
- Description: | {2} |
- Accessible domains with this API key: | {3} |
-
- """.format(get_key_val(detail_dict, key_array[0]), get_key_val(detail_dict, key_array[1]),
- get_key_val(detail_dict, key_array[2]), get_key_val(detail_dict, key_array[3]))
- elif 'reverse' in history.msg:
- self.detailed_msg = """
-
- Domain Type: | {0} |
- Domain Master IPs: | {1} |
-
- """.format(get_key_val(detail_dict, key_array[0]), get_key_val(detail_dict, key_array[1]))
# convert a list of History objects into DetailedHistory objects
def convert_histories(histories):