api

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActorCanAccessClient

func ActorCanAccessClient(actor *Actor, clientID int) bool

func ActorPrimaryClientID

func ActorPrimaryClientID(actor *Actor) (int, bool)

func ApplySessionIdentity

func ApplySessionIdentity(c Context, identity *webservice.SessionIdentity) error

ApplySessionIdentity stores identity in the session; an error says that the session could not be saved.

func PageSpecEnabled

func PageSpecEnabled(cfg *servercfg.Snapshot, spec PageSpec) bool

func PrincipalFromActor

func PrincipalFromActor(actor *Actor) webservice.Principal

func VisitorIP added in v0.35.0

func VisitorIP(c Context, cfg *servercfg.Snapshot) string

VisitorIP returns the address of the visitor of a web request: the peer, or the X-Real-IP header a trusted proxy sets, or that a request carrying the HTTP-only pass sets. A header value that is not an IP address, with or without a port, is ignored. It is the one resolver of the visitor address for the web interface; gin's own ClientIP is not used.

Types

type ActionEntry

type ActionEntry struct {
	Controller       string          `json:"controller"`
	Name             string          `json:"name"`
	Method           string          `json:"method"`
	APIPath          string          `json:"api_path"`
	LegacyPath       string          `json:"legacy_path,omitempty"`
	Permission       string          `json:"permission,omitempty"`
	Ownership        ActionOwnership `json:"ownership,omitempty"`
	RequiredFeatures []PageFeature   `json:"required_features,omitempty"`
	ClientScope      bool            `json:"client_scope"`
	Protected        bool            `json:"protected"`
}

func VisibleActionEntries

func VisibleActionEntries(cfg *servercfg.Snapshot, baseURL string, actor *Actor, authz webservice.AuthorizationService, specs []ActionSpec) []ActionEntry

type ActionOwnership

type ActionOwnership string
const (
	ActionOwnershipNone   ActionOwnership = ""
	ActionOwnershipClient ActionOwnership = "client"
	ActionOwnershipTunnel ActionOwnership = "tunnel"
	ActionOwnershipHost   ActionOwnership = "host"
)

type ActionSpec

type ActionSpec struct {
	Controller       string
	Name             string
	Method           string
	APIPath          string
	LegacyPath       string
	Permission       string
	Ownership        ActionOwnership
	RequiredFeatures []PageFeature
	Handler          Handler
	// Audit names the admin_action event of an action that changes
	// state, such as tunnel_delete; empty for one that only reads.
	Audit       string
	ClientScope bool
	Protected   bool
}

func ProtectedActionCatalog

func ProtectedActionCatalog(app *App) []ActionSpec

func SessionActionCatalog

func SessionActionCatalog(app *App) []ActionSpec

type Actor

type Actor struct {
	Kind        string            `json:"kind"`
	SubjectID   string            `json:"subject_id,omitempty"`
	Username    string            `json:"username,omitempty"`
	IsAdmin     bool              `json:"is_admin"`
	ClientIDs   []int             `json:"client_ids,omitempty"`
	Roles       []string          `json:"roles,omitempty"`
	Permissions []string          `json:"permissions,omitempty"`
	Attributes  map[string]string `json:"attributes,omitempty"`
}

func ActorFromSessionIdentity

func ActorFromSessionIdentity(identity *webservice.SessionIdentity) *Actor

func ActorFromSessionIdentityWithFallback

func ActorFromSessionIdentityWithFallback(identity *webservice.SessionIdentity, fallbackAdminUsername string) *Actor

func AdminActorWithFallback

func AdminActorWithFallback(username, fallbackAdminUsername string) *Actor

func AnonymousActor

func AnonymousActor() *Actor

func UserActor

func UserActor(username string, clientIDs []int) *Actor

type App

type App struct {
	NodeID         string
	Services       webservice.Services
	ConfigProvider func() *servercfg.Snapshot
	// Identity holds the key the login pages encrypt credentials to.
	Identity *crypt.Identity
}

func NewWithOptions

func NewWithOptions(cfg *servercfg.Snapshot, options Options) *App

func (*App) AddClient

func (a *App) AddClient(c Context)

func (*App) AddHost

func (a *App) AddHost(c Context)

func (*App) AddTunnel

func (a *App) AddTunnel(c Context)

func (*App) BanClean

func (a *App) BanClean(c Context)

func (*App) BanList

func (a *App) BanList(c Context)

func (*App) Bootstrap

func (a *App) Bootstrap(c Context)

func (*App) CertSuggestion added in v0.35.0

func (a *App) CertSuggestion(c Context)

CertSuggestion offers a certificate of another entry for a name. Only an administrator is offered those of other clients.

func (*App) ChangeClientStatus

func (a *App) ChangeClientStatus(c Context)

func (*App) ClearClient

func (a *App) ClearClient(c Context)

func (*App) ClearHost

func (a *App) ClearHost(c Context)

func (*App) ClearTunnel

func (a *App) ClearTunnel(c Context)

func (*App) ClientQRCode

func (a *App) ClientQRCode(c Context)

func (*App) CurrentConfig

func (a *App) CurrentConfig() *servercfg.Snapshot

func (*App) DashboardStats

func (a *App) DashboardStats(c Context)

func (*App) DeleteClient

func (a *App) DeleteClient(c Context)

func (*App) DeleteHost

func (a *App) DeleteHost(c Context)

func (*App) DeleteTunnel

func (a *App) DeleteTunnel(c Context)

func (*App) EditClient

func (a *App) EditClient(c Context)

func (*App) EditHost

func (a *App) EditHost(c Context)

func (*App) EditTunnel

func (a *App) EditTunnel(c Context)

func (*App) ExportConfig added in v0.35.0

func (a *App) ExportConfig(c Context)

ExportConfig sends the stored configuration, secrets included, as a file.

func (*App) GetAuthKey

func (a *App) GetAuthKey(c Context)

func (*App) GetCert

func (a *App) GetCert(c Context)

func (*App) GetClient

func (a *App) GetClient(c Context)

func (*App) GetClientLaunch added in v0.35.0

func (a *App) GetClientLaunch(c Context)

GetClientLaunch returns the saved start command form.

func (*App) GetHost

func (a *App) GetHost(c Context)

func (*App) GetOneTunnel

func (a *App) GetOneTunnel(c Context)

func (*App) GetTime

func (a *App) GetTime(c Context)

func (*App) GetTunnel

func (a *App) GetTunnel(c Context)

func (*App) GetTunnelLaunch added in v0.35.0

func (a *App) GetTunnelLaunch(c Context)

GetTunnelLaunch returns the saved start command form.

func (*App) HostList

func (a *App) HostList(c Context)

func (*App) IPRegister added in v0.34.9

func (a *App) IPRegister(c Context)

IPRegister registers the address of the visitor. Wrong keys count as failed logins, so that guessing them leads to a ban.

func (*App) IPRegisterPage added in v0.34.9

func (a *App) IPRegisterPage(c Context)

IPRegisterPage renders the registration page of the web interface; a key query parameter fills in the key, so that a link can be shared.

func (*App) ImportConfig added in v0.35.0

func (a *App) ImportConfig(c Context)

ImportConfig adds the entries of an exported file, taken from the form field "data" verbatim.

func (*App) KickClient added in v0.35.0

func (a *App) KickClient(c Context)

func (*App) ListClients

func (a *App) ListClients(c Context)

func (*App) LiveStatus added in v0.34.10

func (a *App) LiveStatus(c Context)

LiveStatus accepts only explicit runtime fields, never configuration or credentials. Each resource is checked against the current owner, not a caller-supplied client ID.

func (*App) LogEntries added in v0.35.0

func (a *App) LogEntries(c Context)

LogEntries returns the log lines kept in memory (log_memory), oldest first: those after seq "after", at or above "level", of the comma-separated "module" and "event" lists, containing "text". "seq" in the answer is what to pass as after next time, so a viewer can follow the log by asking again.

func (*App) LogLevels added in v0.35.0

func (a *App) LogLevels(c Context)

LogLevels returns the levels of the log as log_level reads them.

func (*App) LogOverride added in v0.35.0

func (a *App) LogOverride(c Context)

LogOverride sets the level of "module" (empty for every module) to "level" for "ttl" seconds, for troubleshooting; a ttl of 0 ends it. log_level in nps.conf is not changed.

func (*App) LoginVerify

func (a *App) LoginVerify(c Context)

func (*App) Logout

func (a *App) Logout(c Context)

func (*App) LogoutRedirect

func (a *App) LogoutRedirect(c Context)

func (*App) ManagementShell

func (a *App) ManagementShell(c Context)

func (*App) PageModel

func (a *App) PageModel(c Context, controller, action string)

func (*App) PageModelController

func (a *App) PageModelController(c Context, controller string, defaultAction string)

func (*App) PingClient

func (a *App) PingClient(c Context)

func (*App) RegisterUser

func (a *App) RegisterUser(c Context)

func (*App) ReloadConfig added in v0.35.0

func (a *App) ReloadConfig(c Context)

ReloadConfig reloads the config file into the running server.

func (*App) ReloadShaping added in v0.35.5

func (a *App) ReloadShaping(c Context)

ReloadShaping fetches or reads the shaping bundle now. The answer carries the state of the source in data either way; code 0 when the reload failed.

func (*App) RenderControllerPage

func (a *App) RenderControllerPage(c Context, controller string, defaultAction string)

func (*App) RenderPage

func (a *App) RenderPage(c Context, controller, action string)

func (*App) SaveClientLaunch added in v0.35.0

func (a *App) SaveClientLaunch(c Context)

SaveClientLaunch stores the start command form; an empty form restores the default.

func (*App) SaveGlobal

func (a *App) SaveGlobal(c Context)

func (*App) SaveTunnelLaunch added in v0.35.0

func (a *App) SaveTunnelLaunch(c Context)

SaveTunnelLaunch stores the start command form; an empty form restores the default.

func (*App) StandaloneIPRegisterPage added in v0.34.9

func (a *App) StandaloneIPRegisterPage(c Context)

StandaloneIPRegisterPage renders the registration page of its own listener, which serves it from the root.

func (*App) StartHost

func (a *App) StartHost(c Context)

func (*App) StartTunnel

func (a *App) StartTunnel(c Context)

func (*App) StopHost

func (a *App) StopHost(c Context)

func (*App) StopTunnel

func (a *App) StopTunnel(c Context)

func (*App) Unban

func (a *App) Unban(c Context)

func (*App) UnbanAll

func (a *App) UnbanAll(c Context)

func (*App) UpdateClient added in v0.34.9

func (a *App) UpdateClient(c Context)

func (*App) UpdateGeoData added in v0.34.9

func (a *App) UpdateGeoData(c Context)

func (*App) UpdateServer added in v0.34.9

func (a *App) UpdateServer(c Context)

type AuthKeyResponse

type AuthKeyResponse struct {
	Status       int    `json:"status"`
	CryptAuthKey string `json:"crypt_auth_key,omitempty"`
	CryptType    string `json:"crypt_type,omitempty"`
}

type BootstrapApp

type BootstrapApp struct {
	Name           string `json:"name"`
	Version        string `json:"version"`
	Year           int    `json:"year"`
	WebBaseURL     string `json:"web_base_url"`
	HeadCustomCode string `json:"head_custom_code"`
}

type BootstrapAuthorizationExtension

type BootstrapAuthorizationExtension struct {
	Roles               []string            `json:"roles,omitempty"`
	Permissions         []string            `json:"permissions,omitempty"`
	ClientIDs           []int               `json:"client_ids,omitempty"`
	KnownRoles          []string            `json:"known_roles,omitempty"`
	KnownPermissions    []string            `json:"known_permissions,omitempty"`
	ManagementAdmin     string              `json:"management_admin"`
	ResourcePermissions map[string][]string `json:"resource_permissions,omitempty"`
}

type BootstrapClusterExtension

type BootstrapClusterExtension struct {
	NodeID         string `json:"node_id,omitempty"`
	EventsEnabled  bool   `json:"events_enabled"`
	CallbacksReady bool   `json:"callbacks_ready"`
}

type BootstrapExtensions

type BootstrapExtensions struct {
	Authorization BootstrapAuthorizationExtension `json:"authorization"`
	Cluster       BootstrapClusterExtension       `json:"cluster"`
}

type BootstrapFeatures

type BootstrapFeatures struct {
	AllowUserLogin          bool `json:"allow_user_login"`
	AllowUserRegister       bool `json:"allow_user_register"`
	AllowUserVkeyLogin      bool `json:"allow_user_vkey_login"`
	AllowFlowLimit          bool `json:"allow_flow_limit"`
	AllowRateLimit          bool `json:"allow_rate_limit"`
	AllowTimeLimit          bool `json:"allow_time_limit"`
	AllowConnectionNumLimit bool `json:"allow_connection_num_limit"`
	AllowMultiIP            bool `json:"allow_multi_ip"`
	AllowTunnelNumLimit     bool `json:"allow_tunnel_num_limit"`
	AllowLocalProxy         bool `json:"allow_local_proxy"`
	AllowUserLocal          bool `json:"allow_user_local"`
	AllowUserChangeUsername bool `json:"allow_user_change_username"`
	SystemInfoDisplay       bool `json:"system_info_display"`
	OpenCaptcha             bool `json:"open_captcha"`
}

type BootstrapPayload

type BootstrapPayload struct {
	Status     int                 `json:"status"`
	App        BootstrapApp        `json:"app"`
	Session    BootstrapSession    `json:"session"`
	Actor      *Actor              `json:"actor"`
	Pages      []PageEntry         `json:"pages"`
	Actions    []ActionEntry       `json:"actions"`
	Features   BootstrapFeatures   `json:"features"`
	Security   BootstrapSecurity   `json:"security"`
	Routes     BootstrapRoutes     `json:"routes"`
	UI         BootstrapUI         `json:"ui"`
	Extensions BootstrapExtensions `json:"extensions"`
	Request    RequestMetadata     `json:"request"`
	PublicKey  string              `json:"public_key,omitempty"`
}

type BootstrapRoutes

type BootstrapRoutes struct {
	Page              string `json:"page"`
	Render            string `json:"render"`
	AppShell          string `json:"app_shell"`
	StaticBase        string `json:"static_base"`
	AppAssetsBase     string `json:"app_assets_base"`
	CaptchaNew        string `json:"captcha_new"`
	CaptchaBase       string `json:"captcha_base"`
	APIBase           string `json:"api_base"`
	ManagementAPIBase string `json:"management_api_base"`
	APIAuth           string `json:"api_auth"`
	APILogin          string `json:"api_login"`
	APICaptcha        string `json:"api_captcha"`
	APIGetAuthKey     string `json:"api_get_auth_key"`
	APIGetTime        string `json:"api_get_time"`
	APIGetCert        string `json:"api_get_cert"`
	GetAuthKey        string `json:"get_auth_key"`
	GetTime           string `json:"get_time"`
	GetCert           string `json:"get_cert"`
	Login             string `json:"login"`
	Logout            string `json:"logout"`
}

type BootstrapSecurity

type BootstrapSecurity struct {
	SecureMode bool `json:"secure_mode"`
	ForcePoW   bool `json:"force_pow"`
	PoWBits    int  `json:"pow_bits"`
}

type BootstrapSession

type BootstrapSession struct {
	Authenticated bool   `json:"authenticated"`
	IsAdmin       bool   `json:"is_admin"`
	Username      string `json:"username,omitempty"`
	ClientID      *int   `json:"client_id"`
	ClientIDs     []int  `json:"client_ids,omitempty"`
	SubjectID     string `json:"subject_id,omitempty"`
	Provider      string `json:"provider,omitempty"`
	Kind          string `json:"kind,omitempty"`
}

type BootstrapUI

type BootstrapUI struct {
	Mode                string                   `json:"mode"`
	ManagementShell     string                   `json:"management_shell"`
	LegacyPagesEnabled  bool                     `json:"legacy_pages_enabled"`
	SPAFallbackEnabled  bool                     `json:"spa_fallback_enabled"`
	ReactBootstrapReady bool                     `json:"react_bootstrap_ready"`
	ShellAssetsReady    bool                     `json:"shell_assets_ready"`
	ShellAssets         ui.ManagementShellAssets `json:"shell_assets"`
}

type CertResponse

type CertResponse struct {
	Status int    `json:"status"`
	Cert   string `json:"cert,omitempty"`
}

type ClientListResponse

type ClientListResponse struct {
	Rows       any    `json:"rows"`
	Total      int    `json:"total"`
	IP         string `json:"ip"`
	Addr       string `json:"addr"`
	BridgeType string `json:"bridgeType"`
	BridgePort int    `json:"bridgePort"`
	// Traffic is the server-wide forwarded traffic, for administrators.
	Traffic *GlobalTrafficPayload `json:"traffic,omitempty"`
}

type CodeDataResponse

type CodeDataResponse struct {
	Code int `json:"code"`
	Data any `json:"data,omitempty"`
}

type CodeRTTResponse

type CodeRTTResponse struct {
	Code int `json:"code"`
	RTT  int `json:"rtt"`
}

type CodeResponse

type CodeResponse struct {
	Code int `json:"code"`
}

type Context

type Context interface {
	BaseContext() context.Context
	String(string) string
	Int(string, ...int) int
	Bool(string, ...bool) bool
	Method() string
	Host() string
	RemoteAddr() string
	RequestHeader(string) string
	SessionValue(string) any
	// SetSessionValue and DeleteSessionValue change the session and save it
	// in the response; an error says that it could not be saved.
	SetSessionValue(string, any) error
	DeleteSessionValue(string) error
	RespondJSON(int, any)
	RespondString(int, string)
	RespondData(int, string, []byte)
	Redirect(int, string)
	SetResponseHeader(string, string)
	IsWritten() bool
	Actor() *Actor
	SetActor(*Actor)
	Metadata() RequestMetadata
}

type GlobalTrafficPayload added in v0.34.9

type GlobalTrafficPayload struct {
	In     int64 `json:"in"`
	Out    int64 `json:"out"`
	InBps  int64 `json:"inBps"`
	OutBps int64 `json:"outBps"`
	Limit  int64 `json:"limit"`
}

GlobalTrafficPayload is the traffic forwarded by the whole server: In from visitors to clients and Out back, in bytes and bytes per second, and the global rate limit in bytes per second, 0 for none.

type Handler

type Handler func(Context)

type IPRegisterHourOption added in v0.34.9

type IPRegisterHourOption struct {
	Hours int
	Label string
}

IPRegisterHourOption is a duration offered on the registration page.

type IPRegisterResponse added in v0.34.9

type IPRegisterResponse struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
	IP     string `json:"ip,omitempty"`
	Until  string `json:"until,omitempty"`
}

IPRegisterResponse answers a registration.

type Options

type Options struct {
	NodeID            string
	Services          *webservice.Services
	ConfigureServices func(*webservice.Services)
	ConfigProvider    func() *servercfg.Snapshot
	// Identity holds the key the login pages encrypt credentials to.
	Identity *crypt.Identity
	// Store is the store the services act on.
	Store *file.DbUtils
	// Runtime is the running server the services act on; nil means none.
	Runtime webservice.Runtime
}

type PageEntry

type PageEntry struct {
	Controller       string        `json:"controller"`
	Action           string        `json:"action"`
	Section          string        `json:"section,omitempty"`
	Menu             string        `json:"menu,omitempty"`
	Template         string        `json:"template,omitempty"`
	Permission       string        `json:"permission,omitempty"`
	Ownership        PageOwnership `json:"ownership,omitempty"`
	Protected        bool          `json:"protected"`
	Navigation       bool          `json:"navigation"`
	Params           []PageParam   `json:"params,omitempty"`
	RequiredFeatures []PageFeature `json:"required_features,omitempty"`
	PagePath         string        `json:"page_path"`
	RenderPath       string        `json:"render_path"`
	DirectPath       string        `json:"direct_path"`
}

func VisiblePageEntries

func VisiblePageEntries(cfg *servercfg.Snapshot, baseURL string, actor *Actor, authz webservice.AuthorizationService) []PageEntry

type PageFeature

type PageFeature string
const (
	PageFeatureAllowUserRegister PageFeature = "allow_user_register"
)

type PageModelResponse

type PageModelResponse struct {
	Controller string         `json:"controller"`
	Action     string         `json:"action"`
	TplName    string         `json:"tpl_name"`
	Layout     string         `json:"layout,omitempty"`
	Data       map[string]any `json:"data"`
	Page       PageEntry      `json:"page"`
}

type PageOwnership

type PageOwnership string
const (
	PageOwnershipClient PageOwnership = "client"
	PageOwnershipTunnel PageOwnership = "tunnel"
	PageOwnershipHost   PageOwnership = "host"
)

type PageParam

type PageParam struct {
	Name     string `json:"name"`
	In       string `json:"in"`
	Type     string `json:"type,omitempty"`
	Required bool   `json:"required"`
}

type PageSpec

type PageSpec struct {
	Controller            string
	Action                string
	Permission            string
	Ownership             PageOwnership
	Section               string
	Menu                  string
	Template              string
	Params                []PageParam
	RequiredFeatures      []PageFeature
	IncludeControllerRoot bool
	Protected             bool
	Navigation            bool
}

func AllPageSpecs

func AllPageSpecs() []PageSpec

func AvailablePageSpecs

func AvailablePageSpecs(cfg *servercfg.Snapshot, specs []PageSpec) []PageSpec

func FindPageSpec

func FindPageSpec(cfg *servercfg.Snapshot, controller, action string) (PageSpec, bool)

func ProtectedPageSpecs

func ProtectedPageSpecs() []PageSpec

func SessionPageSpecs

func SessionPageSpecs() []PageSpec

type ReloadConfigResponse added in v0.35.0

type ReloadConfigResponse struct {
	Status int              `json:"status"`
	Msg    string           `json:"msg"`
	Report servercfg.Report `json:"report"`
}

ReloadConfigResponse is the answer of ReloadConfig: status 1 when the new settings are current, msg sums the report up.

type RequestMetadata

type RequestMetadata struct {
	NodeID    string `json:"node_id,omitempty"`
	RequestID string `json:"request_id,omitempty"`
	Source    string `json:"source,omitempty"`
}

type StatusMessageIDResponse

type StatusMessageIDResponse struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
	ID     int    `json:"id"`
	// Count is the number of entries a port range added, the first one's id
	// being ID; absent for a single entry.
	Count int `json:"count,omitempty"`
}

type StatusMessageResponse

type StatusMessageResponse struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
}

type StatusNonceBitsResponse

type StatusNonceBitsResponse struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
	Nonce  string `json:"nonce,omitempty"`
	Bits   int    `json:"bits"`
}

type StatusNonceCertResponse

type StatusNonceCertResponse struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
	Nonce  string `json:"nonce,omitempty"`
	Cert   string `json:"cert,omitempty"`
}

type StatusNonceResponse

type StatusNonceResponse struct {
	Status int    `json:"status"`
	Msg    string `json:"msg"`
	Nonce  string `json:"nonce,omitempty"`
}

type StatusNonceTimestampResponse

type StatusNonceTimestampResponse struct {
	Status    int    `json:"status"`
	Msg       string `json:"msg"`
	Nonce     string `json:"nonce,omitempty"`
	Timestamp int64  `json:"timestamp"`
}

type TableResponse

type TableResponse struct {
	Rows  any `json:"rows"`
	Total int `json:"total"`
}

type TimeResponse

type TimeResponse struct {
	Time int64 `json:"time"`
}

Jump to

Keyboard shortcuts

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