feat(khira): require admin password confirmation for database backup and rollback
This commit is contained in:
@@ -1087,6 +1087,24 @@ func (s *Server) handleDBSync(w http.ResponseWriter, r *http.Request) {
|
||||
s.writeJSON(w, http.StatusForbidden, map[string]string{"error": "Admin access required to sync backup database"})
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || strings.TrimSpace(req.Password) == "" {
|
||||
s.writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Admin password is required"})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := s.Store.AuthenticateUser(actor.Username, req.Password)
|
||||
if err != nil && !strings.EqualFold(actor.Username, "admin") {
|
||||
_, err = s.Store.AuthenticateUser("admin", req.Password)
|
||||
}
|
||||
if err != nil {
|
||||
s.writeJSON(w, http.StatusUnauthorized, map[string]string{"error": "Invalid administrator password"})
|
||||
return
|
||||
}
|
||||
|
||||
res, err := s.Store.SyncBackupDB()
|
||||
if err != nil {
|
||||
s.writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
@@ -1101,6 +1119,24 @@ func (s *Server) handleDBRollback(w http.ResponseWriter, r *http.Request) {
|
||||
s.writeJSON(w, http.StatusForbidden, map[string]string{"error": "Admin access required to rollback database"})
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || strings.TrimSpace(req.Password) == "" {
|
||||
s.writeJSON(w, http.StatusBadRequest, map[string]string{"error": "Admin password is required"})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := s.Store.AuthenticateUser(actor.Username, req.Password)
|
||||
if err != nil && !strings.EqualFold(actor.Username, "admin") {
|
||||
_, err = s.Store.AuthenticateUser("admin", req.Password)
|
||||
}
|
||||
if err != nil {
|
||||
s.writeJSON(w, http.StatusUnauthorized, map[string]string{"error": "Invalid administrator password"})
|
||||
return
|
||||
}
|
||||
|
||||
res, err := s.Store.RollbackFromBackupDB()
|
||||
if err != nil {
|
||||
s.writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user