mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-11 13:47:05 +02:00
Prepare for a multi-language implementation
This commit is contained in:
@@ -12,36 +12,43 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get application settings from the config package.
|
||||
settings := config.GetSettings()
|
||||
|
||||
// Set Gin mode based on settings
|
||||
// Set Gin mode based on the debug flag in settings.
|
||||
if settings.Debug {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
} else {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
// Create a new Gin router.
|
||||
router := gin.Default()
|
||||
|
||||
// To detect if running inside a container or not
|
||||
// Load HTML templates depending on whether the application is running inside a container.
|
||||
_, container := os.LookupEnv("CONTAINER")
|
||||
if container {
|
||||
router.LoadHTMLGlob("/app/templates/*") // Load HTML templates
|
||||
// In container, templates are assumed to be in /app/templates
|
||||
router.LoadHTMLGlob("/app/templates/*")
|
||||
} else {
|
||||
router.LoadHTMLGlob("pkg/web/templates/*") // Load HTML templates
|
||||
// When running locally, load templates from pkg/web/templates
|
||||
router.LoadHTMLGlob("pkg/web/templates/*")
|
||||
}
|
||||
|
||||
// Register all application routes, including the static file serving route for locales.
|
||||
web.RegisterRoutes(router)
|
||||
|
||||
printWelcomeBanner()
|
||||
log.Println("--- Fail2Ban-UI started in", gin.Mode(), "mode ---")
|
||||
log.Println("Server listening on port :8080.")
|
||||
|
||||
// Start the server on port 8080.
|
||||
if err := router.Run(":8080"); err != nil {
|
||||
log.Fatalf("Server crashed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// printWelcomeBanner prints a cool Tux banner with startup info
|
||||
// printWelcomeBanner prints a cool Tux banner with startup info.
|
||||
func printWelcomeBanner() {
|
||||
greeting := getGreeting()
|
||||
const tuxBanner = `
|
||||
@@ -64,7 +71,7 @@ Listening on: http://0.0.0.0:8080
|
||||
fmt.Printf(tuxBanner, greeting, gin.Mode())
|
||||
}
|
||||
|
||||
// getGreeting returns a friendly greeting based on the time of day
|
||||
// getGreeting returns a friendly greeting based on the time of day.
|
||||
func getGreeting() string {
|
||||
hour := time.Now().Hour()
|
||||
switch {
|
||||
|
||||
@@ -22,6 +22,10 @@ import (
|
||||
|
||||
// RegisterRoutes sets up the routes for the Fail2ban UI.
|
||||
func RegisterRoutes(r *gin.Engine) {
|
||||
// Serve static files for locales from the "internal/locales" directory.
|
||||
// (This makes the translation files available under the /locales/ URL.)
|
||||
r.Static("/locales", "./internal/locales")
|
||||
|
||||
// Render the dashboard
|
||||
r.GET("/", IndexHandler)
|
||||
|
||||
@@ -30,19 +34,19 @@ func RegisterRoutes(r *gin.Engine) {
|
||||
api.GET("/summary", SummaryHandler)
|
||||
api.POST("/jails/:jail/unban/:ip", UnbanIPHandler)
|
||||
|
||||
// config endpoints
|
||||
// Config endpoints
|
||||
api.GET("/jails/:jail/config", GetJailFilterConfigHandler)
|
||||
api.POST("/jails/:jail/config", SetJailFilterConfigHandler)
|
||||
|
||||
// settings
|
||||
// Settings endpoints
|
||||
api.GET("/settings", GetSettingsHandler)
|
||||
api.POST("/settings", UpdateSettingsHandler)
|
||||
api.POST("/settings/test-email", TestEmailHandler)
|
||||
|
||||
// filter debugger
|
||||
// Filter debugger endpoints
|
||||
api.GET("/filters", ListFiltersHandler)
|
||||
api.POST("/filters/test", TestFilterHandler)
|
||||
// TODO create or generate new filters
|
||||
// TODO: create or generate new filters
|
||||
// api.POST("/filters/generate", GenerateFilterHandler)
|
||||
|
||||
// Reload endpoint
|
||||
|
||||
Reference in New Issue
Block a user