2025-01-29 19:49:51 +01:00
|
|
|
// Fail2ban UI - A Swiss made, management interface for Fail2ban.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2025 Swissmakers GmbH (https://swissmakers.ch)
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the GNU General Public License, Version 3 (GPL-3.0)
|
|
|
|
|
// You may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
2025-01-25 16:21:14 +01:00
|
|
|
package web
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RegisterRoutes sets up the routes for the Fail2ban UI.
|
2025-12-15 20:12:41 +01:00
|
|
|
func RegisterRoutes(r *gin.Engine, hub *Hub) {
|
|
|
|
|
// Set the global WebSocket hub
|
|
|
|
|
SetWebSocketHub(hub)
|
2025-02-06 21:41:54 +01:00
|
|
|
|
2025-01-25 16:21:14 +01:00
|
|
|
// Render the dashboard
|
|
|
|
|
r.GET("/", IndexHandler)
|
|
|
|
|
|
2025-01-26 20:05:07 +01:00
|
|
|
api := r.Group("/api")
|
|
|
|
|
{
|
|
|
|
|
api.GET("/summary", SummaryHandler)
|
|
|
|
|
api.POST("/jails/:jail/unban/:ip", UnbanIPHandler)
|
2026-01-07 16:14:48 +01:00
|
|
|
api.POST("/jails/:jail/ban/:ip", BanIPHandler)
|
2025-01-25 16:21:14 +01:00
|
|
|
|
2025-02-26 16:55:21 +01:00
|
|
|
// Routes for jail-filter management (TODO: rename API-call)
|
2025-01-26 20:05:07 +01:00
|
|
|
api.GET("/jails/:jail/config", GetJailFilterConfigHandler)
|
|
|
|
|
api.POST("/jails/:jail/config", SetJailFilterConfigHandler)
|
2025-12-03 20:43:44 +01:00
|
|
|
api.POST("/jails/:jail/logpath/test", TestLogpathHandler)
|
2025-01-25 16:21:14 +01:00
|
|
|
|
2025-02-26 16:55:21 +01:00
|
|
|
// Routes for jail management
|
|
|
|
|
api.GET("/jails/manage", ManageJailsHandler)
|
|
|
|
|
api.POST("/jails/manage", UpdateJailManagementHandler)
|
2025-12-30 01:10:49 +01:00
|
|
|
api.POST("/jails", CreateJailHandler)
|
|
|
|
|
api.DELETE("/jails/:jail", DeleteJailHandler)
|
2025-02-26 16:55:21 +01:00
|
|
|
|
2025-02-06 21:41:54 +01:00
|
|
|
// Settings endpoints
|
2025-01-25 21:18:29 +01:00
|
|
|
api.GET("/settings", GetSettingsHandler)
|
|
|
|
|
api.POST("/settings", UpdateSettingsHandler)
|
2025-01-30 11:00:14 +01:00
|
|
|
api.POST("/settings/test-email", TestEmailHandler)
|
2025-11-18 15:02:50 +01:00
|
|
|
api.GET("/advanced-actions/blocks", ListPermanentBlocksHandler)
|
|
|
|
|
api.POST("/advanced-actions/test", AdvancedActionsTestHandler)
|
2025-01-26 20:05:07 +01:00
|
|
|
|
2025-11-12 15:52:34 +01:00
|
|
|
// Fail2ban servers management
|
|
|
|
|
api.GET("/servers", ListServersHandler)
|
|
|
|
|
api.POST("/servers", UpsertServerHandler)
|
|
|
|
|
api.DELETE("/servers/:id", DeleteServerHandler)
|
|
|
|
|
api.POST("/servers/:id/default", SetDefaultServerHandler)
|
|
|
|
|
api.GET("/ssh/keys", ListSSHKeysHandler)
|
|
|
|
|
api.POST("/servers/:id/test", TestServerHandler)
|
|
|
|
|
|
2025-02-06 21:41:54 +01:00
|
|
|
// Filter debugger endpoints
|
2025-01-25 21:18:29 +01:00
|
|
|
api.GET("/filters", ListFiltersHandler)
|
|
|
|
|
api.POST("/filters/test", TestFilterHandler)
|
2025-12-30 01:10:49 +01:00
|
|
|
api.POST("/filters", CreateFilterHandler)
|
|
|
|
|
api.DELETE("/filters/:filter", DeleteFilterHandler)
|
2025-01-25 21:18:29 +01:00
|
|
|
|
2025-02-26 17:44:13 +01:00
|
|
|
// Restart endpoint
|
|
|
|
|
api.POST("/fail2ban/restart", RestartFail2banHandler)
|
2025-01-29 23:48:06 +01:00
|
|
|
|
|
|
|
|
// Handle Fail2Ban notifications
|
|
|
|
|
api.POST("/ban", BanNotificationHandler)
|
2025-12-16 22:22:32 +01:00
|
|
|
api.POST("/unban", UnbanNotificationHandler)
|
2025-11-12 15:52:34 +01:00
|
|
|
|
|
|
|
|
// Internal database overview
|
|
|
|
|
api.GET("/events/bans", ListBanEventsHandler)
|
|
|
|
|
api.GET("/events/bans/stats", BanStatisticsHandler)
|
2025-11-17 13:29:50 +01:00
|
|
|
api.GET("/events/bans/insights", BanInsightsHandler)
|
2025-12-15 20:12:41 +01:00
|
|
|
|
|
|
|
|
// WebSocket endpoint
|
|
|
|
|
api.GET("/ws", WebSocketHandler(hub))
|
2025-01-26 20:05:07 +01:00
|
|
|
}
|
2025-01-25 16:21:14 +01:00
|
|
|
}
|