adminapi

package
v9.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNAS

func CreateNAS(c echo.Context) error

CreateNAS creates a NAS device @Summary create a NAS device @Tags NAS @Param nas body nasPayload true "NAS device information" @Success 201 {object} domain.NetNas @Router /api/v1/network/nas [post]

func CreateProfile

func CreateProfile(c echo.Context) error

CreateProfile creates a RADIUS profile @Summary create a RADIUS profile @Tags RadiusProfile @Param profile body ProfileRequest true "Profile information" @Success 201 {object} domain.RadiusProfile @Router /api/v1/radius-profiles [post]

func CreateTestAppContext

func CreateTestAppContext(t *testing.T) (*gorm.DB, *echo.Echo, app.AppContext)

CreateTestAppContext creates a test application context with an in-memory SQLite database Returns: db, echo instance, and app context

func CreateTestContext

func CreateTestContext(e *echo.Echo, db *gorm.DB, req *http.Request, rec *httptest.ResponseRecorder, appCtx app.AppContext) echo.Context

CreateTestContext creates an echo context with appCtx injected

func CreateTestContextWithApp

func CreateTestContextWithApp(t *testing.T, req *http.Request, rec *httptest.ResponseRecorder) (echo.Context, *gorm.DB, app.AppContext)

CreateTestContextWithApp is a helper that combines setupTestEcho, setupTestDB, and setupTestApp for backward compatibility with existing tests

func DeleteNAS

func DeleteNAS(c echo.Context) error

DeleteNAS deletes a NAS device @Summary delete a NAS device @Tags NAS @Param id path int true "NAS ID" @Success 200 {object} SuccessResponse @Router /api/v1/network/nas/{id} [delete]

func DeleteOnlineSession

func DeleteOnlineSession(c echo.Context) error

DeleteOnlineSession Force user offline @Summary Force user offline @Tags OnlineSession @Param id path int true "Session ID" @Success 200 {object} SuccessResponse @Router /api/v1/sessions/{id} [delete]

func DeleteProfile

func DeleteProfile(c echo.Context) error

DeleteProfile Delete RADIUS Profile @Summary Delete RADIUS Profile @Tags RadiusProfile @Param id path int true "Profile ID" @Success 200 {object} SuccessResponse @Router /api/v1/radius-profiles/{id} [delete]

func GetAccounting

func GetAccounting(c echo.Context) error

GetAccounting fetches a single accounting record @Summary get accounting record detail @Tags Accounting @Param id path int true "Accounting ID" @Success 200 {object} domain.RadiusAccounting @Router /api/v1/accounting/{id} [get]

func GetAppContext

func GetAppContext(c echo.Context) app.AppContext

GetAppContext gets the application context from echo context

func GetConfig

func GetConfig(c echo.Context) *app.ConfigManager

GetConfig gets the configuration from echo context

func GetDB

func GetDB(c echo.Context) *gorm.DB

GetDB gets the database connection from echo context

func GetDashboardStats

func GetDashboardStats(c echo.Context) error

GetDashboardStats retrieves dashboard statistics @Summary get dashboard statistics @Tags Dashboard @Accept json @Produce json @Success 200 {object} DashboardStats @Router /api/v1/dashboard/stats [get]

func GetNAS

func GetNAS(c echo.Context) error

GetNAS fetches a single NAS device @Summary get NAS device detail @Tags NAS @Param id path int true "NAS ID" @Success 200 {object} domain.NetNas @Router /api/v1/network/nas/{id} [get]

func GetOnlineSession

func GetOnlineSession(c echo.Context) error

GetOnlineSession Get single online session @Summary Get online session details @Tags OnlineSession @Param id path int true "Session ID" @Success 200 {object} domain.RadiusOnline @Router /api/v1/sessions/{id} [get]

func GetProfile

func GetProfile(c echo.Context) error

GetProfile retrieves a single RADIUS profile @Summary get RADIUS profile detail @Tags RadiusProfile @Param id path int true "Profile ID" @Success 200 {object} domain.RadiusProfile @Router /api/v1/radius-profiles/{id} [get]

func Init

func Init(appCtx app.AppContext)

Init registers all admin API routes

func ListAccounting

func ListAccounting(c echo.Context) error

ListAccounting retrieves the accounting logs table @Summary get accounting logs table @Tags Accounting @Param page query int false "Page number" @Param perPage query int false "Items per page" @Param sort query string false "Sort field" @Param order query string false "Sort direction" @Param username query string false "Username" @Param nas_addr query string false "NAS address" @Param acct_session_id query string false "Session ID" @Param framed_ipaddr query string false "User IP address" @Param mac_addr query string false "MAC address" @Param framed_ipv6addr query string false "IPv6 address" @Param acct_start_time_gte query string false "Start time from (RFC3339 or datetime-local format)" @Param acct_start_time_lte query string false "Start time to (RFC3339 or datetime-local format)" @Success 200 {object} ListResponse @Router /api/v1/accounting [get]

func ListNAS

func ListNAS(c echo.Context) error

ListNAS retrieves the NAS device list @Summary get the NAS device list @Tags NAS @Param page query int false "Page number" @Param perPage query int false "Items per page" @Param sort query string false "Sort field" @Param order query string false "Sort direction" @Param name query string false "Device name" @Param status query string false "Device status" @Success 200 {object} ListResponse @Router /api/v1/network/nas [get]

func ListOnlineSessions

func ListOnlineSessions(c echo.Context) error

ListOnlineSessions List online sessions @Summary List online sessions @Tags OnlineSession @Param page query int false "Page number" @Param perPage query int false "Items per page" @Param sort query string false "Sort field" @Param order query string false "Sort direction" @Param username query string false "Username" @Param nas_addr query string false "NAS addresses" @Param framed_ipaddr query string false "User IP address" @Param framed_ipv6addr query string false "User IPv6 address" @Param mac_addr query string false "MAC address" @Param acct_session_id query string false "Session ID" @Param acct_start_time_gte query string false "Start time from (RFC3339 or datetime-local)" @Param acct_start_time_lte query string false "Start time to (RFC3339 or datetime-local)" @Success 200 {object} ListResponse @Router /api/v1/sessions [get]

func ListProfiles

func ListProfiles(c echo.Context) error

ListProfiles retrieves the RADIUS profile list @Summary get the RADIUS profile list @Tags RadiusProfile @Param page query int false "Page number" @Param perPage query int false "Items per page" @Param sort query string false "Sort field" @Param order query string false "Sort direction" @Success 200 {object} ListResponse @Router /api/v1/radius-profiles [get]

func UpdateNAS

func UpdateNAS(c echo.Context) error

UpdateNAS updates a NAS device @Summary update a NAS device @Tags NAS @Param id path int true "NAS ID" @Param nas body nasPayload true "NAS device information" @Success 200 {object} domain.NetNas @Router /api/v1/network/nas/{id} [put]

func UpdateProfile

func UpdateProfile(c echo.Context) error

UpdateProfile updates a RADIUS profile @Summary update a RADIUS profile @Tags RadiusProfile @Param id path int true "Profile ID" @Param profile body ProfileRequest true "Profile information" @Success 200 {object} domain.RadiusProfile @Router /api/v1/radius-profiles/{id} [put]

Types

type DashboardAuthTrendPoint

type DashboardAuthTrendPoint struct {
	Date  string `json:"date"`  // Date label formatted as YYYY-MM-DD
	Count int64  `json:"count"` // Authentication count for the day
}

DashboardAuthTrendPoint represents authentication count per day

type DashboardProfileSlice

type DashboardProfileSlice struct {
	ProfileID   int64  `json:"profile_id"`
	ProfileName string `json:"profile_name"`
	Value       int64  `json:"value"`
}

DashboardProfileSlice represents online user distribution grouped by profile

type DashboardStats

type DashboardStats struct {
	TotalUsers          int64                     `json:"total_users"`          // Total number of users
	OnlineUsers         int64                     `json:"online_users"`         // Currently online users
	TodayAuthCount      int64                     `json:"today_auth_count"`     // Authentication count for today
	TodayAcctCount      int64                     `json:"today_acct_count"`     // Accounting record count for today
	TotalProfiles       int64                     `json:"total_profiles"`       // Total number of profiles
	DisabledUsers       int64                     `json:"disabled_users"`       // Disabled users
	ExpiredUsers        int64                     `json:"expired_users"`        // Expired users
	TodayInputGB        float64                   `json:"today_input_gb"`       // Today's upstream traffic (GB)
	TodayOutputGB       float64                   `json:"today_output_gb"`      // Today's downstream traffic (GB)
	AuthTrend           []DashboardAuthTrendPoint `json:"auth_trend"`           // Daily authentication trend (last 7 days)
	Traffic24h          []DashboardTrafficPoint   `json:"traffic_24h"`          // Hourly traffic statistics (last 24 hours)
	ProfileDistribution []DashboardProfileSlice   `json:"profile_distribution"` // Online users grouped by profile
}

DashboardStats represents the dashboard statistics structure

type DashboardTrafficPoint

type DashboardTrafficPoint struct {
	Hour       string  `json:"hour"`        // Hour label formatted as YYYY-MM-DD HH:00
	UploadGB   float64 `json:"upload_gb"`   // Upload traffic in GB within the hour
	DownloadGB float64 `json:"download_gb"` // Download traffic in GB within the hour
}

DashboardTrafficPoint represents hourly upload/download traffic

type ErrorResponse

type ErrorResponse struct {
	Error   string      `json:"error"`
	Message string      `json:"message"`
	Details interface{} `json:"details,omitempty"`
}

ErrorResponse represents the error response structure

type Meta

type Meta struct {
	Total    int64 `json:"total"`
	Page     int   `json:"page"`
	PageSize int   `json:"pageSize"`
}

Meta describes pagination information

type ProfileRequest

type ProfileRequest struct {
	Name           string      `json:"name" validate:"required,min=1,max=100"`
	Status         interface{} `json:"status"` // Can be string or boolean
	AddrPool       string      `json:"addr_pool" validate:"omitempty,addrpool"`
	ActiveNum      int         `json:"active_num" validate:"gte=0,lte=100"`
	UpRate         int         `json:"up_rate" validate:"gte=0,lte=10000000"`
	DownRate       int         `json:"down_rate" validate:"gte=0,lte=10000000"`
	Domain         string      `json:"domain" validate:"omitempty,max=50"`
	IPv6PrefixPool string      `json:"ipv6_prefix_pool" validate:"omitempty"`
	BindMac        interface{} `json:"bind_mac"`  // Can be int or boolean
	BindVlan       interface{} `json:"bind_vlan"` // Can be int or boolean
	Remark         string      `json:"remark" validate:"omitempty,max=500"`
	NodeId         interface{} `json:"node_id"` // Can be int64 or string
}

ProfileRequest represents the mixed-type JSON sent from the frontend

type ProfileUpdateRequest

type ProfileUpdateRequest struct {
	Name           string      `json:"name" validate:"omitempty,min=1,max=100"`
	Status         interface{} `json:"status"` // Can be string or boolean
	AddrPool       string      `json:"addr_pool" validate:"omitempty,addrpool"`
	ActiveNum      int         `json:"active_num" validate:"gte=0,lte=100"`
	UpRate         int         `json:"up_rate" validate:"gte=0,lte=10000000"`
	DownRate       int         `json:"down_rate" validate:"gte=0,lte=10000000"`
	Domain         string      `json:"domain" validate:"omitempty,max=50"`
	IPv6PrefixPool string      `json:"ipv6_prefix_pool" validate:"omitempty"`
	BindMac        interface{} `json:"bind_mac"`  // Can be int or boolean
	BindVlan       interface{} `json:"bind_vlan"` // Can be int or boolean
	Remark         string      `json:"remark" validate:"omitempty,max=500"`
	NodeId         interface{} `json:"node_id"` // Can be int64 or string
}

ProfileUpdateRequest represents the mixed-type JSON sent from the frontend for updates

type Response

type Response struct {
	Data interface{} `json:"data,omitempty"`
	Meta *Meta       `json:"meta,omitempty"`
}

Response represents the unified response structure

type UserRequest

type UserRequest struct {
	NodeID     interface{} `json:"node_id"`                                     // Can be int64 or string
	ProfileID  interface{} `json:"profile_id" validate:"required"`              // Can be int64 or string
	Realname   string      `json:"realname" validate:"omitempty,max=100"`       // Real name
	Email      string      `json:"email" validate:"omitempty,email,max=100"`    // Email
	Mobile     string      `json:"mobile" validate:"omitempty,max=20"`          // Mobile number (optional, max 20 characters)
	Address    string      `json:"address" validate:"omitempty,max=255"`        // addresses
	Username   string      `json:"username" validate:"required,min=3,max=50"`   // Username
	Password   string      `json:"password" validate:"omitempty,min=6,max=128"` // Password
	AddrPool   string      `json:"addr_pool" validate:"omitempty,max=50"`       // Address pool
	Vlanid1    int         `json:"vlanid1" validate:"gte=0,lte=4096"`           // VLAN ID 1
	Vlanid2    int         `json:"vlanid2" validate:"gte=0,lte=4096"`           // VLAN ID 2
	IpAddr     string      `json:"ip_addr" validate:"omitempty,ipv4"`           // IPv4addresses
	Ipv6Addr   string      `json:"ipv6_addr" validate:"omitempty"`              // IPv6addresses
	MacAddr    string      `json:"mac_addr" validate:"omitempty,mac"`           // MACaddresses
	BindVlan   interface{} `json:"bind_vlan"`                                   // Can be int or boolean
	BindMac    interface{} `json:"bind_mac"`                                    // Can be int or boolean
	ExpireTime string      `json:"expire_time" validate:"omitempty"`            // Expiration time
	Status     interface{} `json:"status"`                                      // Can be string or boolean
	Remark     string      `json:"remark" validate:"omitempty,max=500"`         // Remark
}

UserRequest Used to handle user data sent from frontend

type UserUpdateRequest

type UserUpdateRequest struct {
	NodeID          interface{} `json:"node_id"`                                       // Can be int64 or string
	ProfileID       interface{} `json:"profile_id"`                                    // Can be int64 or string
	Realname        string      `json:"realname" validate:"omitempty,max=100"`         // Real name
	Email           string      `json:"email" validate:"omitempty,email,max=100"`      // Email
	Mobile          string      `json:"mobile" validate:"omitempty,max=20"`            // Mobile number (optional, max 20 characters)
	Address         string      `json:"address" validate:"omitempty,max=255"`          // addresses
	Username        string      `json:"username" validate:"omitempty,min=3,max=50"`    // Username
	Password        string      `json:"password" validate:"omitempty,min=6,max=128"`   // Password
	AddrPool        string      `json:"addr_pool" validate:"omitempty,max=50"`         // Address pool
	Vlanid1         int         `json:"vlanid1" validate:"gte=0,lte=4096"`             // VLAN ID 1
	Vlanid2         int         `json:"vlanid2" validate:"gte=0,lte=4096"`             // VLAN ID 2
	IpAddr          string      `json:"ip_addr" validate:"omitempty,ipv4"`             // IPv4addresses
	Ipv6Addr        string      `json:"ipv6_addr" validate:"omitempty"`                // IPv6addresses
	MacAddr         string      `json:"mac_addr" validate:"omitempty,mac"`             // MACaddresses
	BindVlan        interface{} `json:"bind_vlan"`                                     // Can be int or boolean
	BindMac         interface{} `json:"bind_mac"`                                      // Can be int or boolean
	ExpireTime      string      `json:"expire_time" validate:"omitempty"`              // Expiration time
	Status          interface{} `json:"status"`                                        // Can be string or boolean
	Remark          string      `json:"remark" validate:"omitempty,max=500"`           // Remark
	IPv6PrefixPool  string      `json:"ipv6_prefix_pool" validate:"omitempty,max=100"` // IPv6 prefix pool name
	Domain          string      `json:"domain" validate:"omitempty,max=100"`           // User domain
	ProfileLinkMode int         `json:"profile_link_mode" validate:"gte=0,lte=1"`      // Profile link mode (0=static, 1=dynamic)
}

UserUpdateRequest Used to handle user update data

Jump to

Keyboard shortcuts

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