This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit bd8bfc51b7288d44eb9f3ea4ae180f0587b3d672
Author: Daniel Gruno <[email protected]>
AuthorDate: Wed Mar 31 13:50:56 2021 +0200

    Add a simple starter for viewing audit logs
---
 webui/css/scaffolding.css | 18 +++++++++++++++++-
 webui/js/source/mgmt.js   | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/webui/css/scaffolding.css b/webui/css/scaffolding.css
index 49987ed..d9d7756 100644
--- a/webui/css/scaffolding.css
+++ b/webui/css/scaffolding.css
@@ -1179,4 +1179,20 @@ pre {
 
 .chatty_body a {
     word-break: break-all !important;
-  }
\ No newline at end of file
+  }
+
+.auditlog_entry:nth-child(odd) {
+    background: #EEE;
+}
+
+.auditlog_entry:nth-child(even) {
+    background: #F8F8F8;
+}
+
+.auditlog_entry td {
+    padding: 2px;
+}
+
+.auditlog_entries th {
+    padding: 2px;
+}
\ No newline at end of file
diff --git a/webui/js/source/mgmt.js b/webui/js/source/mgmt.js
index 0565860..6f087fb 100644
--- a/webui/js/source/mgmt.js
+++ b/webui/js/source/mgmt.js
@@ -135,6 +135,49 @@ function admin_email_preview(stats, json) {
     div.inject(new HTML('small', {}, "Emails that are removed may still be 
recovered by the base system administrator. For complete expungement, please 
contact the system administrator."))
 }
 
+function admin_audit_view(state, json) {
+    let cp = document.getElementById("panel");
+    let div = new HTML('div', { style: { margin: '5px'}});
+    cp.inject(div);
+
+    div.inject(new HTML('h1', {}, "Audit log:"));
+    if (json.entries && json.entries.length > 0) {
+        let table = new HTML('table', {border: "1", class:"auditlog_entries"});
+        let trh = new HTML('tr');
+        let headers = ['Date', 'Author','Remote','Action','Target', 'Log'];
+        for (let i = 0; i < headers.length; i++) {
+            let th = new HTML('th', {}, headers[i] + ":");
+            trh.inject(th);
+        }
+        table.inject(trh)
+        for (let i = 0; i < json.entries.length; i++) {
+            let entry = json.entries[i];
+            let tr = new HTML('tr', {class: "auditlog_entry"});
+            for (let i = 0; i < headers.length; i++) {
+                let key = headers[i].toLowerCase();
+                let value = entry[key];
+                if (key == 'target') {
+                    value = new HTML('a', {href: "/admin/" +value}, value);
+                }
+                if (key == 'action') {
+                    let action_colors = {
+                        edit: 'blue',
+                        delete: 'red',
+                        default: 'black'
+                    };
+                    value = new HTML('spam', {style: {color: 
action_colors[value] ? action_colors[value] : action_colors['default']}}, 
value);
+                }
+                let th = new HTML('td', {}, value);
+                tr.inject(th);
+            }
+            table.inject(tr);
+        }
+        div.inject(table);
+    } else {
+        div.inject("Audit log is empty");
+    }
+
+}
 function admin_init() {
     let mid = location.href.split('/').pop();
     // Specific email/list handling?
@@ -147,5 +190,7 @@ function admin_init() {
         else {
             GET('%sapi/email.json?id=%s'.format(apiURL, mid), 
admin_email_preview, null);
         }
+    } else { // View audit log
+        GET('%sapi/mgmt.json?action=log'.format(apiURL), admin_audit_view, 
null);
     }
 }
\ No newline at end of file

Reply via email to