server

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2025 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package server initializes and configures the HTTP server for CookieFarm, including routing, static file serving, and debug settings.

Index

Constants

This section is empty.

Variables

View Source
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 CreateJWT

func CreateJWT(username string) (string, int64, error)

CreateJWT generates a new JWT token with an expiration time of 24 hours.

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

func HashPassword(password string) (string, error)

HashPassword hashes the password using bcrypt.

func InitSecret

func InitSecret() ([]byte, error)

InitSecret generates a random secret key and assigns it to the config.

func MakePagination

func MakePagination(current, totalPages int) []int

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

func VerifyToken(token string) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL