mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
- Upgraded `golang.org/x/crypto` to v0.36.0 and other indirect dependencies to their latest versions. - Added functionality to assign admin roles to users upon creation in the main application logic. - Introduced new templates for admin role management, including forms for creating and editing roles. - Removed deprecated admin tools template to streamline the admin interface. - Added audit logging for role changes to improve tracking and accountability.
198 lines
7.7 KiB
Go
198 lines
7.7 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// RegisterRoutes registers all the routes for the web interface
|
|
func (h *Handlers) RegisterRoutes(router *gin.Engine) {
|
|
// Register error handlers first
|
|
h.RegisterErrorHandlers(router)
|
|
|
|
// Public routes
|
|
router.GET("/", h.HandleHome)
|
|
router.GET("/login", h.HandleLoginPage)
|
|
router.POST("/login", h.HandleLogin)
|
|
router.GET("/login/verify", h.Handle2FAVerifyPage)
|
|
router.POST("/login/verify", h.Handle2FAVerify)
|
|
router.GET("/login/backup-code", h.Handle2FABackupCodePage)
|
|
router.GET("/forgot-password", h.HandleForgotPasswordPage)
|
|
router.POST("/forgot-password", h.HandleForgotPassword)
|
|
router.GET("/reset-password", h.HandleResetPasswordPage)
|
|
router.POST("/reset-password", h.HandleResetPassword)
|
|
|
|
// Protected routes
|
|
authorized := router.Group("/")
|
|
authorized.Use(h.AuthMiddleware())
|
|
|
|
// Password change route - only accessed from profile page
|
|
authorized.POST("/change-password", h.HandleChangePassword)
|
|
|
|
// 2FA routes - under profile
|
|
authorized.GET("/profile/2fa/setup", h.Handle2FASetup)
|
|
authorized.POST("/profile/2fa/verify", h.Handle2FAVerifySetup)
|
|
authorized.POST("/profile/2fa/disable", h.Handle2FADisable)
|
|
authorized.GET("/profile/2fa/backup-codes", h.Handle2FABackupCodes)
|
|
authorized.POST("/profile/2fa/regenerate-codes", h.Handle2FARegenerateCodes)
|
|
|
|
{
|
|
authorized.GET("/dashboard", h.HandleDashboard)
|
|
authorized.GET("/configs", h.HandleConfigs)
|
|
authorized.GET("/configs/new", h.HandleNewConfig)
|
|
authorized.GET("/configs/:id", h.HandleEditConfig)
|
|
authorized.POST("/configs", h.HandleCreateConfig)
|
|
authorized.PUT("/configs/:id", h.HandleUpdateConfig)
|
|
authorized.POST("/configs/:id", h.HandleUpdateConfig)
|
|
authorized.DELETE("/configs/:id", h.HandleDeleteConfig)
|
|
|
|
// Path validation endpoint
|
|
authorized.GET("/check-path", h.HandleCheckPath)
|
|
|
|
// Google Drive authentication routes
|
|
authorized.GET("/configs/:id/gdrive-auth", h.HandleGDriveAuth)
|
|
authorized.GET("/configs/gdrive-callback", h.HandleGDriveAuthCallback)
|
|
authorized.GET("/configs/gdrive-token", h.HandleGDriveTokenProcess)
|
|
|
|
authorized.GET("/jobs", h.HandleJobs)
|
|
authorized.GET("/jobs/new", h.HandleNewJob)
|
|
authorized.GET("/jobs/:id", h.HandleEditJob)
|
|
authorized.POST("/jobs", h.HandleCreateJob)
|
|
authorized.PUT("/jobs/:id", h.HandleUpdateJob)
|
|
authorized.POST("/jobs/:id", h.HandleUpdateJob)
|
|
authorized.DELETE("/jobs/:id", h.HandleDeleteJob)
|
|
authorized.POST("/jobs/:id/run", h.HandleRunJob)
|
|
authorized.GET("/history", h.HandleHistory)
|
|
authorized.GET("/job-runs/:id", h.HandleJobRunDetails)
|
|
authorized.GET("/profile", h.HandleProfile)
|
|
authorized.POST("/profile/theme", h.HandleUpdateTheme)
|
|
authorized.POST("/logout", h.HandleLogout)
|
|
|
|
// File metadata routes
|
|
fileMetadataHandler := &FileMetadataHandler{DB: h.DB}
|
|
fileGroup := authorized.Group("/files")
|
|
fileGroup.GET("", fileMetadataHandler.ListFileMetadata)
|
|
fileGroup.GET("/:id", fileMetadataHandler.GetFileMetadataDetails)
|
|
fileGroup.GET("/job/:job_id", fileMetadataHandler.GetFileMetadataForJob)
|
|
fileGroup.GET("/search", fileMetadataHandler.SearchFileMetadata)
|
|
fileGroup.GET("/search/partial", fileMetadataHandler.HandleFileMetadataSearchPartial)
|
|
fileGroup.DELETE("/:id", fileMetadataHandler.DeleteFileMetadata)
|
|
fileGroup.GET("/partial", fileMetadataHandler.HandleFileMetadataPartial)
|
|
|
|
// AJAX routes for dashboard
|
|
authorized.GET("/dashboard/data", h.HandleDashboardData)
|
|
authorized.GET("/dashboard/jobs", h.HandleDashboardJobsData)
|
|
authorized.GET("/dashboard/history", h.HandleDashboardHistoryData)
|
|
|
|
}
|
|
|
|
// Admin-only routes
|
|
admin := router.Group("/admin")
|
|
admin.Use(h.AuthMiddleware())
|
|
{
|
|
// Main admin dashboard - requires admin role
|
|
admin.GET("", h.AdminMiddleware(), h.HandleAdminDashboard)
|
|
|
|
// User management routes
|
|
userGroup := admin.Group("/users")
|
|
userGroup.Use(h.PermissionMiddleware("users.view"))
|
|
{
|
|
userGroup.GET("", h.HandleUsers)
|
|
userGroup.GET("/new", h.PermissionMiddleware("users.create"), h.AdminNewUserPage)
|
|
userGroup.POST("", h.PermissionMiddleware("users.create"), h.HandleCreateUser)
|
|
userGroup.GET("/:id/edit", h.PermissionMiddleware("users.edit"), h.HandleEditUser)
|
|
userGroup.PUT("/:id", h.PermissionMiddleware("users.edit"), h.AdminUpdateUser)
|
|
userGroup.DELETE("/:id", h.PermissionMiddleware("users.delete"), h.HandleDeleteUser)
|
|
userGroup.PUT("/:id/toggle-lock", h.PermissionMiddleware("users.edit"), h.AdminToggleLockUser)
|
|
}
|
|
|
|
// Admin routes for role management
|
|
adminRoles := admin.Group("/roles")
|
|
adminRoles.Use(h.PermissionMiddleware("roles.admin"))
|
|
{
|
|
adminRoles.GET("", h.AdminRoles)
|
|
adminRoles.GET("/new", h.AdminNewRolePage)
|
|
adminRoles.GET("/:id/edit", h.AdminEditRolePage)
|
|
adminRoles.POST("", h.AdminCreateRole)
|
|
adminRoles.PUT("/:id", h.AdminUpdateRole)
|
|
adminRoles.DELETE("/:id", h.AdminDeleteRole)
|
|
}
|
|
|
|
// Audit log routes
|
|
auditGroup := admin.Group("/audit")
|
|
auditGroup.Use(h.PermissionMiddleware("audit.view"))
|
|
{
|
|
auditGroup.GET("", h.HandleAuditLogs)
|
|
auditGroup.GET("/export", h.PermissionMiddleware("audit.export"), h.HandleExportAuditLogs)
|
|
}
|
|
|
|
// System settings routes
|
|
settingsGroup := admin.Group("/settings")
|
|
settingsGroup.Use(h.PermissionMiddleware("system.settings"))
|
|
{
|
|
settingsGroup.GET("", h.HandleSettings)
|
|
settingsGroup.POST("/notifications", h.HandleCreateNotificationService)
|
|
settingsGroup.DELETE("/notifications/:id", h.HandleDeleteNotificationService)
|
|
settingsGroup.POST("/general", h.HandleSettings) // Placeholder for future implementation
|
|
settingsGroup.POST("/security", h.HandleSettings) // Placeholder for future implementation
|
|
}
|
|
|
|
// Database tools routes
|
|
dbGroup := admin.Group("/database")
|
|
dbGroup.Use(h.PermissionMiddleware("system.backup"))
|
|
{
|
|
dbGroup.GET("", h.HandleDatabaseTools)
|
|
dbGroup.POST("/backup-database", h.HandleBackupDatabase)
|
|
dbGroup.POST("/restore-database", h.PermissionMiddleware("system.restore"), h.HandleRestoreDatabase)
|
|
dbGroup.GET("/restore-database/:filename", h.PermissionMiddleware("system.restore"), h.HandleRestoreDatabase)
|
|
dbGroup.GET("/download-backup/:filename", h.HandleDownloadBackup)
|
|
dbGroup.POST("/delete-backup/:filename", h.HandleDeleteBackup)
|
|
dbGroup.GET("/refresh-backups", h.HandleRefreshBackups)
|
|
dbGroup.POST("/vacuum-database", h.HandleVacuumDatabase)
|
|
dbGroup.POST("/clear-job-history", h.HandleClearJobHistory)
|
|
}
|
|
|
|
}
|
|
|
|
// API routes
|
|
api := router.Group("/api")
|
|
{
|
|
api.POST("/login", h.HandleAPILogin)
|
|
|
|
// Protected API routes
|
|
apiAuthorized := api.Group("/")
|
|
apiAuthorized.Use(h.APIAuthMiddleware())
|
|
{
|
|
// Config endpoints
|
|
apiAuthorized.GET("/configs", h.HandleAPIConfigs)
|
|
apiAuthorized.GET("/configs/:id", h.HandleAPIConfig)
|
|
apiAuthorized.POST("/configs", h.HandleAPICreateConfig)
|
|
apiAuthorized.PUT("/configs/:id", h.HandleAPIUpdateConfig)
|
|
apiAuthorized.DELETE("/configs/:id", h.HandleAPIDeleteConfig)
|
|
|
|
// Job endpoints
|
|
apiAuthorized.GET("/jobs", h.HandleAPIJobs)
|
|
apiAuthorized.GET("/jobs/:id", h.HandleAPIJob)
|
|
apiAuthorized.POST("/jobs", h.HandleAPICreateJob)
|
|
apiAuthorized.PUT("/jobs/:id", h.HandleAPIUpdateJob)
|
|
apiAuthorized.DELETE("/jobs/:id", h.HandleAPIDeleteJob)
|
|
apiAuthorized.POST("/jobs/:id/run", h.HandleAPIRunJob)
|
|
|
|
// History endpoints
|
|
apiAuthorized.GET("/history", h.HandleAPIHistory)
|
|
apiAuthorized.GET("/job-runs/:id", h.HandleAPIJobRun)
|
|
|
|
// Admin-only API routes
|
|
apiAdmin := apiAuthorized.Group("/admin")
|
|
apiAdmin.Use(h.APIAdminMiddleware())
|
|
{
|
|
// User management
|
|
apiAdmin.GET("/users", h.HandleAPIUsers)
|
|
apiAdmin.GET("/users/:id", h.HandleAPIUser)
|
|
apiAdmin.POST("/users", h.HandleAPICreateUser)
|
|
apiAdmin.PUT("/users/:id", h.HandleAPIUpdateUser)
|
|
apiAdmin.DELETE("/users/:id", h.HandleAPIDeleteUser)
|
|
}
|
|
}
|
|
}
|
|
}
|