feat(audit): log user create/delete, quota, password and blocked-domain changes

- admin: record user.create, user.delete, quota.update, passwd.reset,
  blocked.update and admin.passwd (actor "000" for admin's own changes)
- panel: record passwd.change when a user changes their own password
- audit page: bilingual labels for the new action types

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
bluebluesodaandCommandCodeBot committed 2026-08-20 05:53:26 +00:00
1 parent 84768f4f01
commit 049bc9c2c8
3 files changed
+15 -1

No files matched your search

+6
View File
@@ -338,6 +338,7 @@ func (s *Server) handleUserAdd(w http.ResponseWriter, r *http.Request) {
s.redirect(w, r, s.p(""), "error: "+err.Error())
return
}
_ = s.db.AddAuditLog("000+"+name, "user.create")
// The password is always auto-generated and shown once.
cred := "user: " + res.User.Name +
"\npassword: " + res.Password +
@@ -359,6 +360,7 @@ func (s *Server) handleUserDel(w http.ResponseWriter, r *http.Request) {
s.redirect(w, r, s.p(""), "error: "+err.Error())
return
}
_ = s.db.AddAuditLog("000+"+name, "user.delete")
s.redirect(w, r, s.p(""), s.t(r, "user_deleted", name))
}
@@ -392,6 +394,7 @@ func (s *Server) handleUserQuota(w http.ResponseWriter, r *http.Request) {
s.redirect(w, r, s.p(""), "error: "+err.Error())
return
}
_ = s.db.AddAuditLog("000+"+name, "quota.update")
s.redirect(w, r, s.p(""), s.t(r, "quota_updated", name))
}
@@ -440,6 +443,7 @@ func (s *Server) handleResetPanelPass(w http.ResponseWriter, r *http.Request) {
return
}
panel := s.cfg.PanelURL("/" + s.cfg.Panel.URLPath)
_ = s.db.AddAuditLog("000+"+name, "passwd.reset")
s.redirectModal(w, r, s.p(""), s.t(r, "new_panel_password", name, pass, panel))
}
@@ -474,6 +478,7 @@ func (s *Server) handleAdminPass(w http.ResponseWriter, r *http.Request) {
if c, err := r.Cookie("vpsmgr_admin_session"); err == nil {
s.sessions.clearExcept(c.Value)
}
_ = s.db.AddAuditLog("000", "admin.passwd")
s.redirect(w, r, s.p(""), s.t(r, "admin_pass_changed"))
}
@@ -637,6 +642,7 @@ func (s *Server) handleBlockedDomains(w http.ResponseWriter, r *http.Request) {
s.redirect(w, r, s.p("/domains"), "error: "+err.Error())
return
}
_ = s.db.AddAuditLog("000", "blocked.update")
if len(bad) > 0 {
lines := make([]string, 0, len(bad))
for _, n := range bad {
@@ -73,7 +73,14 @@ var ACT={
'power.restart':{zh:'重启',en:'restart'},
'reinstall':{zh:'重装系统',en:'reinstall'},
'reset_root_password':{zh:'重置 root 密码',en:'reset root password'},
'domain_update':{zh:'更新域名配置',en:'update domain config'}
'domain_update':{zh:'更新域名配置',en:'update domain config'},
'user.create':{zh:'创建用户',en:'create user'},
'user.delete':{zh:'删除用户',en:'delete user'},
'passwd.change':{zh:'修改面板密码',en:'change panel password'},
'passwd.reset':{zh:'重置面板密码',en:'reset panel password'},
'admin.passwd':{zh:'修改管理员密码',en:'change admin password'},
'quota.update':{zh:'修改配额',en:'update quota'},
'blocked.update':{zh:'修改封禁域名列表',en:'update blocked domains'}
};
function actLabel(a){var m=ACT[a]||{};return LANG==='zh'?(m.zh||a):(m.en||a);}
function pad2(n){return (n<10?'0':'')+n;}
+1
View File
@@ -228,6 +228,7 @@ func (s *Server) handlePanelPassword(w http.ResponseWriter, r *http.Request) {
s.redirect(w, r, s.p(""), "error: "+err.Error())
return
}
_ = s.db.AddAuditLog(u.Name, "passwd.change")
s.redirect(w, r, s.p(""), "ok: panel password changed")
}