Documentation
¶
Overview ¶
Package server initializes and configures the HTTP server for CookieFarm, including routing, static file serving, and debug settings.
Index ¶
- Variables
- func CookieAuthMiddleware(c *fiber.Ctx) error
- func CreateJWT(username string) (string, int64, error)
- func GetStatus(c *fiber.Ctx) error
- func HandleDeleteFlag(c *fiber.Ctx) error
- func HandleGetAllFlags(c *fiber.Ctx) error
- func HandleGetConfig(c *fiber.Ctx) error
- func HandleGetPaginatedFlags(c *fiber.Ctx) error
- func HandleGetProtocols(c *fiber.Ctx) error
- func HandleGetStats(c *fiber.Ctx) error
- func HandleIndexPage(c *fiber.Ctx) error
- func HandleLogin(c *fiber.Ctx) error
- func HandleLoginPage(c *fiber.Ctx) error
- func HandlePartialsFlags(c *fiber.Ctx) error
- func HandlePartialsPagination(c *fiber.Ctx) error
- func HandlePostConfig(c *fiber.Ctx) error
- func HandlePostFlag(c *fiber.Ctx) error
- func HandlePostFlags(c *fiber.Ctx) error
- func HandlePostFlagsStandalone(c *fiber.Ctx) error
- func HashPassword(password string) (string, error)
- func InitSecret() ([]byte, error)
- func MakePagination(current, totalPages int) []int
- func NewApp() (*fiber.App, error)
- func NewLimiter() fiber.Handler
- func PrepareStatic(app *fiber.App) error
- func RegisterRoutes(app *fiber.App)
- func VerifyToken(token string) error
- type Pagination
- type ResponseError
- type ResponseFlags
- type ResponseSuccess
- type SigninRequest
- type ViewParamsDashboard
- type ViewParamsFlags
- type ViewParamsPagination
Constants ¶
This section is empty.
Variables ¶
var ( MaxRequests = config.GetEnvAsInt("RATE_LIMIT_MAX", 50) Window = config.GetEnvAsInt("RATE_LIMIT_WINDOW", 1) )
Functions ¶
func CookieAuthMiddleware ¶
func CookieAuthMiddleware(c *fiber.Ctx) error
CookieAuthMiddleware checks if the user has a valid JWT token in their cookies.
func GetStatus ¶
func GetStatus(c *fiber.Ctx) error
GetStatus is a simple public endpoint used to check if the server is online.
func HandleDeleteFlag ¶
func HandleDeleteFlag(c *fiber.Ctx) error
HandleDeleteFlag deletes a flag by its ID.
func HandleGetAllFlags ¶
func HandleGetAllFlags(c *fiber.Ctx) error
HandleGetAllFlags retrieves and returns all the stored flags.
func HandleGetConfig ¶
func HandleGetConfig(c *fiber.Ctx) error
HandleGetConfig returns the current configuration of the server.
func HandleGetPaginatedFlags ¶
func HandleGetPaginatedFlags(c *fiber.Ctx) error
func HandleGetProtocols ¶
func HandleGetProtocols(c *fiber.Ctx) error
HandleGetFlag retrieves a single flag by its ID.
func HandleGetStats ¶
func HandleGetStats(c *fiber.Ctx) error
HandleGetStats returns statistics about the server state. Currently returns placeholders for flags and users.
func HandleIndexPage ¶
func HandleIndexPage(c *fiber.Ctx) error
HandleIndexPage renders the main dashboard page. It checks the cookie-based authentication and sets the default pagination limit.
func HandleLogin ¶
func HandleLogin(c *fiber.Ctx) error
HandleLogin handles the login request by checking the credentials and generating a JWT token.
func HandleLoginPage ¶
func HandleLoginPage(c *fiber.Ctx) error
HandleLoginPage renders the login page.
func HandlePartialsFlags ¶
func HandlePartialsFlags(c *fiber.Ctx) error
HandlePartialsFlags renders only the flags rows as a partial view. It fetches a limited and paginated list of flags from the database.
func HandlePartialsPagination ¶
func HandlePartialsPagination(c *fiber.Ctx) error
HandlePartialsPagination renders only the pagination component as a partial view. It computes the current page and the total number of pages based on the flags count.
func HandlePostConfig ¶
func HandlePostConfig(c *fiber.Ctx) error
HandlePostConfig updates the server configuration and restarts the flag processing loop.
func HandlePostFlag ¶
func HandlePostFlag(c *fiber.Ctx) error
HandlePostFlag processes a single flag and optionally submits it to an external checker.
func HandlePostFlags ¶
func HandlePostFlags(c *fiber.Ctx) error
HandlePostFlags processes a batch of flags submitted in the request.
func HandlePostFlagsStandalone ¶
func HandlePostFlagsStandalone(c *fiber.Ctx) error
HandlePostFlag processes a single flag and optionally submits it to an external checker.
func HashPassword ¶
HashPassword hashes the password using bcrypt.
func InitSecret ¶
InitSecret generates a random secret key and assigns it to the config.
func MakePagination ¶
MakePagination generates a list of page numbers for pagination.
func NewApp ¶
func NewApp() (*fiber.App, error)
NewApp initializes and returns a new Fiber app instance, setting up static file routes, debug middleware, and template engine.
func NewLimiter ¶
func NewLimiter() fiber.Handler
NewLimiter returns a rate limiter middleware for Fiber. When in debug mode, rate limiting is disabled to ease development. In production, it limits to 5 requests per minute per IP to prevent abuse (e.g., brute-force on login).
func PrepareStatic ¶
func PrepareStatic(app *fiber.App) error
func RegisterRoutes ¶
func RegisterRoutes(app *fiber.App)
RegisterRoutes configures all routes and middlewares of the Fiber app, including CORS policies, public and protected API endpoints, and view rendering routes.
func VerifyToken ¶
VerifyToken validates the JWT token using the secret key.
Types ¶
type Pagination ¶
type Pagination struct { Limit int // Maximum number of items per page Pages int // Total number of pages Current int // Current page number (offset / limit) PageList []int // List of page numbers to display in the pagination HasPrev bool // Indicates if there is a previous page HasNext bool // Indicates if there is a next page }
Pagination structure for manage data in the view
type ResponseError ¶
type ResponseError struct { Error string `json:"error"` // Error message for the error response Details string `json:"details"` // Details for the error response }
ResponseError represents the response for the error api
type ResponseFlags ¶
type ResponseFlags struct { Nflags int `json:"n_flags"` Flags []models.ClientData `json:"flags"` }
ResponseFlags represents the response for the flags api
type ResponseSuccess ¶
type ResponseSuccess struct {
Message string `json:"message"` // Message for the success response
}
ResponseSuccess represents the response for the success api
type SigninRequest ¶
type SigninRequest struct { Username string `json:"username,omitzero"` // Username for authentication Password string `json:"password"` // Password for authentication }
SigninRequest from the client to the server
type ViewParamsDashboard ¶
type ViewParamsDashboard struct {
Limit int `json:"limit"` // Maximum number of items per page
}
ViewParamsDashboard represents the parameters for the dashboard view
type ViewParamsFlags ¶
type ViewParamsFlags struct {
Flags []models.ClientData `json:"flags"` // List of flags to display
}
ViewParamsFlags represents the parameters for the flags view
type ViewParamsPagination ¶
type ViewParamsPagination struct {
Pagination Pagination // Pagination parameters
}
ViewParamsPagination represents the parameters for the pagination view