Documentation
¶
Index ¶
- Constants
- func InterfaceOf(c *Client) string
- type APITokenEntry
- type BaseData
- type Client
- type ClientData
- type ClientDefaults
- type ClientServerHashes
- type ClientUsageData
- type GlobalSetting
- type Interface
- type QRCodeSettings
- type Server
- type ServerInterface
- type ServerKeypair
- type User
- type UserRole
- type WGInterface
- type WakeOnLanHost
Constants ¶
const DefaultInterfaceName = "wg0"
DefaultInterfaceName is the interface a legacy install is migrated into, and the one a client falls back to when it has no explicit assignment.
const MaxAPITokensPerUser = 10
MaxAPITokensPerUser caps how many concurrent sessions a single user can hold. When the cap is hit the oldest token is evicted, so a user who never logs out cannot grow this list without bound (it lives inside the user's JSON record).
const WakeOnLanHostCollectionName = "wake_on_lan_hosts"
Variables ¶
This section is empty.
Functions ¶
func InterfaceOf ¶ added in v1.0.1
InterfaceOf returns the interface a client belongs to, falling back to the default when the client predates multi-interface support.
Types ¶
type APITokenEntry ¶ added in v1.0.1
type APITokenEntry struct {
Token string `json:"token"`
ExpireAt time.Time `json:"expire_at"`
CreatedAt time.Time `json:"created_at"`
// Label is free-form ("site", "windows-client", a User-Agent, ...). Purely
// informational - useful when showing a user their active sessions.
Label string `json:"label,omitempty"`
}
APITokenEntry is one independent, individually-expiring API token.
Previously a user had exactly ONE token field: every new login overwrote it, which silently logged out every other device that user had. Tokens are now a list, so the site, the desktop client and a phone can each hold their own.
type Client ¶
type Client struct {
ID string `json:"id"`
PrivateKey string `json:"private_key"`
PublicKey string `json:"public_key"`
Name string `json:"name"`
TgUserid string `json:"telegram_userid"`
Email string `json:"email"`
SubnetRanges []string `json:"subnet_ranges,omitempty"`
AllocatedIPs []string `json:"allocated_ips"`
AllowedIPs []string `json:"allowed_ips"`
ExtraAllowedIPs []string `json:"extra_allowed_ips"`
Endpoint string `json:"endpoint"`
AdditionalNotes string `json:"additional_notes"`
UseServerDNS bool `json:"use_server_dns"`
Enabled bool `json:"enabled"`
CreatedBy string `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Quota int64 `json:"quota,omitempty"`
UsedQuota int64 `json:"used_quota,omitempty"`
Expiration time.Time `json:"expiration,omitempty"`
ExpirationDays int `json:"expiration_days,omitempty"`
FirstConnectedAt time.Time `json:"first_connected_at,omitempty"`
Status string `json:"status,omitempty"`
LastHandshake time.Time `json:"last_handshake,omitempty"`
// Interface is which WireGuard interface (wg0/wg1/...) this client lives on.
// Empty means DefaultInterfaceName, so records written before multi-interface
// support keep working unchanged.
Interface string `json:"interface,omitempty"`
// Persistent storage for usage data
PersistentUsageData *ClientUsageData `json:"persistent_usage_data,omitempty"`
}
Client model
type ClientData ¶
ClientData includes the Client and extra data
type ClientDefaults ¶
type ClientDefaults struct {
AllowedIps []string
ExtraAllowedIps []string
UseServerDNS bool
EnableAfterCreation bool
}
ClientDefaults Defaults for creation of new clients used in the templates
type ClientServerHashes ¶
ClientServerHashes struct, to save hashes to detect changes
type ClientUsageData ¶
type ClientUsageData struct {
TotalBytesReceived uint64 `json:"total_bytes_received"`
TotalBytesSent uint64 `json:"total_bytes_sent"`
LastInterfaceBytesReceived uint64 `json:"last_interface_bytes_received"`
LastInterfaceBytesSent uint64 `json:"last_interface_bytes_sent"`
LastSeen time.Time `json:"last_seen"`
FirstSeen time.Time `json:"first_seen"`
UpdatedAt time.Time `json:"updated_at"`
}
ClientUsageData stores persistent usage information
type GlobalSetting ¶
type GlobalSetting struct {
EndpointAddress string `json:"endpoint_address"`
RelayEndpoint string `json:"relay_endpoint"`
DNSServers []string `json:"dns_servers"`
MTU int `json:"mtu,string"`
PersistentKeepalive int `json:"persistent_keepalive,string"`
FirewallMark string `json:"firewall_mark"`
Table string `json:"table"`
ConfigFilePath string `json:"config_file_path"`
AppSecretToken string `json:"app_secret_token"`
UpdatedAt time.Time `json:"updated_at"`
// Display settings
Timezone string `json:"timezone"`
Language string `json:"language"`
}
GlobalSetting model
type QRCodeSettings ¶
type ServerInterface ¶
type ServerInterface struct {
Addresses []string `json:"addresses"`
ListenPort int `json:"listen_port"`
UpdatedAt time.Time `json:"updated_at"`
PostUp string `json:"post_up"`
PreDown string `json:"pre_down"`
PostDown string `json:"post_down"`
// فیلد جدید برای فاصله بررسی (بر حسب دقیقه)
CheckInterval int `json:"check_interval"`
}
ServerInterface model
func (*ServerInterface) UnmarshalJSON ¶
func (s *ServerInterface) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom decoding to allow listen_port and check_interval to be provided as either strings or numbers.
type ServerKeypair ¶
type ServerKeypair struct {
PrivateKey string `json:"private_key"`
PublicKey string `json:"public_key"`
UpdatedAt time.Time `json:"updated_at"`
}
ServerKeypair model
type User ¶
type User struct {
Username string `json:"username"`
PasswordHash string `json:"password_hash"`
Role UserRole `json:"role"`
APIToken string `json:"api_token,omitempty"`
TokenExpire time.Time `json:"token_expire,omitempty"`
// APITokens holds every currently valid token. APIToken/TokenExpire above
// are kept only so that records written by an older build keep working and
// so that any external caller still reading `api_token` sees the most
// recent one; ValidateAPIToken accepts either representation.
APITokens []APITokenEntry `json:"api_tokens,omitempty"`
}
User model
func (*User) AddAPIToken ¶ added in v1.0.1
AddAPIToken registers a new token WITHOUT invalidating the existing ones.
func (*User) PruneExpiredTokens ¶ added in v1.0.1
func (u *User) PruneExpiredTokens()
PruneExpiredTokens drops expired entries. Safe to call at any time.
func (*User) RevokeAPIToken ¶ added in v1.0.1
RevokeAPIToken removes a single token (logout on one device only). Reports whether anything was removed.
func (*User) RevokeAllAPITokens ¶ added in v1.0.1
func (u *User) RevokeAllAPITokens()
RevokeAllAPITokens logs the user out everywhere.
func (*User) ValidateAPIToken ¶ added in v1.0.1
ValidateAPIToken reports whether token is currently valid for this user. Comparison is constant-time so a token cannot be recovered by timing.
type WGInterface ¶ added in v1.0.1
type WGInterface struct {
// Name is the netdev name AND the config file stem: /etc/wireguard/<Name>.conf
Name string `json:"name"`
// Description is free text shown in the UI.
Description string `json:"description,omitempty"`
// Enabled interfaces are brought up and written out; disabled ones are kept
// in the database but skipped.
Enabled bool `json:"enabled"`
PrivateKey string `json:"private_key"`
PublicKey string `json:"public_key"`
// Addresses are the interface's own CIDRs, e.g. ["10.66.0.1/24"].
Addresses []string `json:"addresses"`
ListenPort int `json:"listen_port"`
// MTU of 0 means "let the template decide".
MTU int `json:"mtu,omitempty"`
PostUp string `json:"post_up,omitempty"`
PreDown string `json:"pre_down,omitempty"`
PostDown string `json:"post_down,omitempty"`
// Endpoint that clients on this interface should dial. Empty falls back to
// the global setting. This is what makes per-interface routing useful: wg1
// can hand out a relay endpoint while wg0 hands out the direct one.
Endpoint string `json:"endpoint,omitempty"`
// DNSServers overrides the global DNS for clients on this interface.
DNSServers []string `json:"dns_servers,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
WGInterface describes a single WireGuard interface managed by the panel.
func WGInterfaceFromLegacy ¶ added in v1.0.1
func WGInterfaceFromLegacy(s Server, name string) *WGInterface
WGInterfaceFromLegacy builds the default interface from the old Server record. Used once, during migration.
func (*WGInterface) ConfigFilePath ¶ added in v1.0.1
func (w *WGInterface) ConfigFilePath() string
ConfigFilePath is where wg-quick expects this interface's config.
func (*WGInterface) ServiceName ¶ added in v1.0.1
func (w *WGInterface) ServiceName() string
ServiceName is the systemd unit that carries this interface.
func (*WGInterface) ToLegacyServer ¶ added in v1.0.1
func (w *WGInterface) ToLegacyServer() Server
ToLegacyServer projects an interface back onto the old single-server shape. Everything that still expects model.Server keeps working through this.
func (*WGInterface) Validate ¶ added in v1.0.1
func (w *WGInterface) Validate() error
Validate checks an interface definition before it is persisted.
type WakeOnLanHost ¶
type WakeOnLanHost struct {
MacAddress string `json:"MacAddress"`
Name string `json:"Name"`
LatestUsed *time.Time `json:"LatestUsed"`
}
func (WakeOnLanHost) ResolveResourceName ¶
func (host WakeOnLanHost) ResolveResourceName() (string, error)