diff --git a/database/audit.go b/database/audit.go index 69577e3..addd66e 100644 --- a/database/audit.go +++ b/database/audit.go @@ -11,13 +11,53 @@ package database import ( "context" + _ "embed" "fmt" "time" "git.erbosoft.com/amy/amsterdam/config" log "github.com/sirupsen/logrus" + "gopkg.in/yaml.v3" ) +// AuditRefRecord stores the reference data for an audit message. +type AuditRefRecord struct { + Code int `yaml:"code"` + Text string `yaml:"text"` +} + +// AuditReference stores the audit reference data. +type AuditReference struct { + Ref []AuditRefRecord `yaml:"auditReference"` + table map[int]*AuditRefRecord +} + +//go:embed auditref.yaml +var initAuditData []byte + +// auditref is the master audit data reference. +var auditRef AuditReference + +// init loads the audit data. +func init() { + if err := yaml.Unmarshal(initAuditData, &auditRef); err != nil { + panic(err) // can't happen + } + auditRef.table = make(map[int]*AuditRefRecord) + for i := range auditRef.Ref { + auditRef.table[auditRef.Ref[i].Code] = &(auditRef.Ref[i]) + } +} + +// AmAuditText gets the text of an audit from its code. +func AmAuditText(code int) string { + rec, ok := auditRef.table[code] + if ok { + return rec.Text + } + return fmt.Sprintf("[audit code:%d]", code) +} + // AuditRecord holds an audit record instance. type AuditRecord struct { Record int64 `db:"record"` // audit record ID @@ -32,7 +72,8 @@ type AuditRecord struct { Data4 *string `db:"data4"` // fourth data parameter } -// These are the audit record types. +// These are the audit record types. N.B.: Keep these synchronized with the definitions in database/auditref.yaml +// at all times! const ( AuditPublishToFrontPage = 1 AuditLoginOK = 101 diff --git a/database/auditref.yaml b/database/auditref.yaml new file mode 100644 index 0000000..b58721e --- /dev/null +++ b/database/auditref.yaml @@ -0,0 +1,100 @@ +# +# Amsterdam Web Communities System +# Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# ---------------------------------------------------------------------------- +# N.B.: Keep this synchronized with the constant definitions in +# database/audit.go at all times! +auditReference: + - code: 1 + text: "Publish Message to Front Page" + - code: 101 + text: "Login OK" + - code: 102 + text: "Login Failure" + - code: 103 + text: "Account Created" + - code: 104 + text: "Verify Email OK" + - code: 105 + text: "Verify Email Failure" + - code: 106 + text: "Set User Contact Info" + - code: 107 + text: "Resend Email Confirmation" + - code: 108 + text: "Password Change" + - code: 109 + text: "Admin Set User Contact Info" + - code: 110 + text: "Admin Change User Password" + - code: 111 + text: "Admin Change User Account" + - code: 112 + text: "Admin Set Account Security" + - code: 113 + text: "Admin Lock/Unlock Account" + - code: 201 + text: "Create New Community" + - code: 202 + text: "Set Community Membership" + - code: 203 + text: "Set Community Contact Info" + - code: 204 + text: "Set Community Services" + - code: 205 + text: "Set Community Name" + - code: 206 + text: "Set Community Alias" + - code: 207 + text: "Set Community Category" + - code: 208 + text: "Set Community Hiding Information" + - code: 209 + text: "Set Community Members-Only Flag" + - code: 210 + text: "Set Community Join Key" + - code: 211 + text: "Set Community Security Levels" + - code: 212 + text: "Delete Community" + - code: 301 + text: "Create New Conference" + - code: 302 + text: "Set Conference Security Levels" + - code: 303 + text: "Set Conference Name" + - code: 304 + text: "Change Conference Aliases" + - code: 305 + text: "Change Conference Membership" + - code: 306 + text: "Create New Topic" + - code: 307 + text: "Delete Topic" + - code: 308 + text: "Set Topic Frozen" + - code: 309 + text: "Set Topic Archive" + - code: 310 + text: "Post Message" + - code: 311 + text: "Hide Message" + - code: 312 + text: "Scribble Message" + - code: 313 + text: "Nuke Message" + - code: 314 + text: "Upload Message Attachment" + - code: 315 + text: "Delete Conference" + - code: 316 + text: "Move Message" + - code: 317 + text: "Set Topic Sticky" + - code: 318 + text: "Prune Message Attachment" diff --git a/setup/database.sql b/setup/database.sql index cf617c6..8b2a3c1 100644 --- a/setup/database.sql +++ b/setup/database.sql @@ -58,12 +58,6 @@ CREATE TABLE audit ( INDEX comm_view (commid, on_date) ); -# A mapping from audit type codes to descriptions. -CREATE TABLE refaudit ( - type INT NOT NULL PRIMARY KEY, - descr VARCHAR(255) -); - # The user information table. CREATE TABLE users ( uid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -452,54 +446,6 @@ GRANT INSERT, DELETE, UPDATE, SELECT, LOCK TABLES ON amsterdam.* # Constant Data Population ############################################################################## -# Types of audit records. This MUST be kept in sync with the constant definitions in -# com.silverwrist.venice.security.Audit!!!! -INSERT INTO refaudit (type, descr) VALUES - (1, 'Publish Message to Front Page'), - (101, 'Login OK'), - (102, 'Login Failure'), - (103, 'Account Created'), - (104, 'Verify Email OK'), - (105, 'Verify Email Failure'), - (106, 'Set User Contact Info'), - (107, 'Resend Email Confirmation'), - (108, 'Password Change'), - (109, 'Admin Set User Contact Info'), - (110, 'Admin Change User Password'), - (111, 'Admin Change User Account'), - (112, 'Admin Set Account Security'), - (113, 'Admin Lock/Unlock Account'), - (201, 'Create New Community'), - (202, 'Set Community Membership'), - (203, 'Set Community Contact Info'), - (204, 'Set Community Services'), - (205, 'Set Community Name'), - (206, 'Set Community Alias'), - (207, 'Set Community Category'), - (208, 'Set Community Hiding Information'), - (209, 'Set Community Members-Only Flag'), - (210, 'Set Community Join Key'), - (211, 'Set Community Security Levels'), - (212, 'Delete Community'), - (301, 'Create New Conference'), - (302, 'Set Conference Security Levels'), - (303, 'Set Conference Name'), - (304, 'Change Conference Aliases'), - (305, 'Change Conference Membership'), - (306, 'Create New Topic'), - (307, 'Delete Topic'), - (308, 'Set Topic Frozen'), - (309, 'Set Topic Archive'), - (310, 'Post Message'), - (311, 'Hide Message'), - (312, 'Scribble Message'), - (313, 'Nuke Message'), - (314, 'Upload Message Attachment'), - (315, 'Delete Conference'), - (316, 'Move Message'), - (317, 'Set Topic Sticky'), - (9999999, 'DUMMY'); - # Populate the Category table. # Source: Mozilla Open Directory Project categorization system ; # additional categorization from WebbMe categories