Documentation
¶
Overview ¶
Package store is the SQLite-backed persistence layer. The DB is the single source of truth; the Xray config is always derived from it.
Index ¶
- func InspectDB(path string) (users, admins int, secret string, err error)
- type Store
- func (s *Store) AddConnection(userID int64, ip string, ts int64) error
- func (s *Store) AddDailyTraffic(userID int64, day string, up, down int64) error
- func (s *Store) Checkpoint() error
- func (s *Store) Close() error
- func (s *Store) CountAdmins() (int, error)
- func (s *Store) CreateAdmin(username, passwordHash string) (int64, error)
- func (s *Store) CreateSession(adminID int64, ttl time.Duration) (string, error)
- func (s *Store) CreateUser(name, uuid, password, subToken string, dataLimit, expireAt int64) (*model.User, error)
- func (s *Store) DeleteSession(token string) error
- func (s *Store) DeleteSessionsForAdminExcept(adminID int64, keepToken string) error
- func (s *Store) DeleteUser(id int64) error
- func (s *Store) GetAdminAuth(username string) (id int64, hash string, err error)
- func (s *Store) GetAdminHash(id int64) (string, error)
- func (s *Store) GetSettings() (*model.Settings, error)
- func (s *Store) GetUserBySubToken(token string) (*model.User, error)
- func (s *Store) ListUsers() ([]model.User, error)
- func (s *Store) LookupSession(token string) (adminID int64, username string, ok bool)
- func (s *Store) MarkConfigApplied() error
- func (s *Store) MustChangePassword() (bool, error)
- func (s *Store) RecentConnections(userID int64, limit int) ([]model.Connection, error)
- func (s *Store) ResetDailyStats() error
- func (s *Store) ResetTraffic(id, lastUp, lastDown int64) error
- func (s *Store) ResetUserQuota(id, now, lastUp, lastDown int64) error
- func (s *Store) SetACMEProvider(provider, eabKID, eabHMAC string) error
- func (s *Store) SetAntiDPI(tlsFragment, tlsMin13, blockQUIC bool, realityMaxTimeDiff int) error
- func (s *Store) SetConfigError(msg string) error
- func (s *Store) SetDecoyTemplate(name string) error
- func (s *Store) SetFingerprints(vless, trojan, reality string) error
- func (s *Store) SetHysteriaPorts(port, hopStart, hopEnd int, interval string) error
- func (s *Store) SetMustChangePassword(must bool) error
- func (s *Store) SetOpera(enabled bool, country string, port int) error
- func (s *Store) SetProtocolEnabled(name string, enabled bool) error
- func (s *Store) SetProxyMode(enabled bool, typ string, port int, user, pass string) error
- func (s *Store) SetRealityKeys(priv, pub, shortID, serviceName string) error
- func (s *Store) SetRealityPorts(port int, dest string) error
- func (s *Store) SetResetPeriod(id int64, period string, now int64) error
- func (s *Store) SetRoutingConfig(cfg model.RoutingConfig) error
- func (s *Store) SetSecretPath(p string) error
- func (s *Store) SetSetupDone(done bool) error
- func (s *Store) SetSubSettings(st *model.Settings) error
- func (s *Store) SetTLS(host, sni, mode, certPath, keyPath string) error
- func (s *Store) SetTLSMode(mode, host, sni, acmeEmail string) error
- func (s *Store) SetTimezone(tz string) error
- func (s *Store) SetUserEnabled(id int64, enabled bool) error
- func (s *Store) SetUserLimits(id, dataLimit, expireAt int64) error
- func (s *Store) SetUserName(id int64, name string) error
- func (s *Store) SetWSPath(p string) error
- func (s *Store) SetWarp(st *model.Settings) error
- func (s *Store) SetXrayDNS(dns string) error
- func (s *Store) StatsByUser(from, to string) ([]model.UserTotal, error)
- func (s *Store) StatsSeries(userID int64, from, to string) ([]model.DailyPoint, error)
- func (s *Store) TouchLastSeen(userID, ts int64) error
- func (s *Store) UpdateAdminPassword(id int64, passwordHash string) error
- func (s *Store) UpdateAdminUsername(id int64, username string) error
- func (s *Store) UpdateTraffic(id, addUp, addDown, lastUp, lastDown int64) error
- func (s *Store) WorkingUsers(now int64) ([]model.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InspectDB ¶
InspectDB opens the database file at path read-only and reports whether it's a usable rospanel database, along with its user/admin counts and configured secret path. A non-nil error means the file isn't a valid panel DB (missing, corrupt, or — the classic empty-backup case — a header with no tables because the data was left in an unbacked-up WAL).
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the SQLite connection pool.
func Open ¶
Open opens (creating if needed) the SQLite database at path, applies pragmas, and runs pending migrations.
func (*Store) AddConnection ¶
AddConnection records activity from a source IP for a user (upserting the per-IP row) and bumps the user's last_seen.
func (*Store) AddDailyTraffic ¶
AddDailyTraffic adds up/down deltas to a user's row for the given UTC day.
func (*Store) Checkpoint ¶
Checkpoint flushes the write-ahead log into the main database file and truncates it, so an on-disk copy (e.g. a backup) captures all committed data. Without this a live backup would copy a near-empty .db with everything still in the uncheckpointed .db-wal (which backups intentionally exclude).
func (*Store) CountAdmins ¶
CountAdmins returns the number of admin accounts.
func (*Store) CreateAdmin ¶
CreateAdmin inserts an admin with the given username and password hash.
func (*Store) CreateSession ¶
CreateSession issues a new opaque session token for an admin and stores only its hash. The raw token is returned to set as a cookie.
func (*Store) CreateUser ¶
func (s *Store) CreateUser(name, uuid, password, subToken string, dataLimit, expireAt int64) (*model.User, error)
CreateUser inserts a user with one credential set (UUID for VLESS, password for Trojan + Hysteria2), a subscription token, and optional quota/expiry.
func (*Store) DeleteSession ¶
DeleteSession revokes a session by its raw token.
func (*Store) DeleteSessionsForAdminExcept ¶
DeleteSessionsForAdminExcept revokes every session belonging to an admin except the one identified by keepToken — used after a credential change so a previously stolen cookie can't outlive the change, while the admin doing the change stays logged in.
func (*Store) GetAdminAuth ¶
GetAdminAuth returns the admin id and password hash for a username.
func (*Store) GetAdminHash ¶
GetAdminHash returns an admin's current password hash by id (for re-authenticating a credential change against the current password).
func (*Store) GetSettings ¶
GetSettings returns the singleton settings row.
func (*Store) GetUserBySubToken ¶
GetUserBySubToken resolves a subscription token to its user.
func (*Store) LookupSession ¶
LookupSession resolves a raw session token to its admin. Expired sessions are deleted and treated as invalid.
func (*Store) MarkConfigApplied ¶
MarkConfigApplied bumps the config revision and clears any prior error.
func (*Store) MustChangePassword ¶
MustChangePassword reports whether the admin must replace the default password before the rest of the panel unlocks (set at first-run bootstrap, cleared on the first password change).
func (*Store) RecentConnections ¶
RecentConnections returns a user's source IPs, most recent first.
func (*Store) ResetDailyStats ¶
ResetDailyStats clears the entire per-day traffic history.
func (*Store) ResetTraffic ¶
ResetTraffic zeroes a user's usage (so a "limited" user works again) and re-baselines the raw counters to the supplied live Xray values, so the next stats poll measures the delta from now. Passing 0/0 would make the poll re-add the user's whole lifetime Xray total straight back onto the freshly-zeroed usage. Does not touch enabled or expiry — an expired user stays expired.
func (*Store) ResetUserQuota ¶
ResetUserQuota zeroes a user's usage and records the reset time (automatic reset scheduler). It re-baselines the raw counters to the supplied live Xray values so the next stats poll measures the delta from now — passing 0/0 would make the poll re-add the whole lifetime total back. enabled/expiry untouched; status is derived on read.
func (*Store) SetACMEProvider ¶
SetACMEProvider persists the ACME CA selection and (for ZeroSSL) the External Account Binding credentials. An empty provider defaults to "letsencrypt".
func (*Store) SetAntiDPI ¶
SetAntiDPI persists the anti-DPI transport-hardening settings (Settings → Подключения): client-config shaping (TLS fragmentation, QUIC block) and the server-inbound knobs (TLS 1.3 floor, REALITY anti-replay window + donor port).
func (*Store) SetConfigError ¶
SetConfigError records the last failed config-apply error.
func (*Store) SetDecoyTemplate ¶
SetDecoyTemplate persists the masquerade (decoy) template slug.
func (*Store) SetFingerprints ¶
SetFingerprints persists the per-connection uTLS fingerprints used in links.
func (*Store) SetHysteriaPorts ¶
SetHysteriaPorts persists the Hysteria2 base port, hop range, and hop interval.
func (*Store) SetMustChangePassword ¶
SetMustChangePassword sets or clears the forced-password-change gate.
func (*Store) SetOpera ¶
SetOpera persists the Opera VPN egress settings (enable flag, region, and the local proxy port the opera-proxy helper listens on).
func (*Store) SetProtocolEnabled ¶
SetProtocolEnabled flips a single protocol's on/off toggle.
func (*Store) SetProxyMode ¶
SetProxyMode persists the forward-proxy inbound configuration.
func (*Store) SetRealityKeys ¶
SetRealityKeys persists a freshly generated REALITY keypair, shortId, and gRPC service name.
func (*Store) SetRealityPorts ¶
SetRealityPorts persists the REALITY port and destination (SNI/serverName).
func (*Store) SetResetPeriod ¶
SetResetPeriod sets a user's automatic quota-reset period and anchors the cycle at now.
func (*Store) SetRoutingConfig ¶
func (s *Store) SetRoutingConfig(cfg model.RoutingConfig) error
SetRoutingConfig persists the structured routing configuration as JSON.
func (*Store) SetSecretPath ¶
SetSecretPath persists the hidden panel path segment.
func (*Store) SetSetupDone ¶
SetSetupDone marks the first-run wizard as completed.
func (*Store) SetSubSettings ¶
SetSubSettings persists the subscription delivery settings.
func (*Store) SetTLSMode ¶
SetTLSMode persists the TLS mode, domain (host), SNI and ACME e-mail.
func (*Store) SetTimezone ¶
SetTimezone persists the operator's IANA timezone (e.g. "Europe/Moscow").
func (*Store) SetUserEnabled ¶
SetUserEnabled sets the independent manual on/off flag. Expiry/quota are separate and never change this.
func (*Store) SetUserLimits ¶
SetUserLimits sets the data limit (bytes) and expiry (unix, 0 = none). Does not touch the manual enabled flag; status is derived on read.
func (*Store) SetUserName ¶
SetUserName updates a user's display name.
func (*Store) SetXrayDNS ¶
SetXrayDNS persists the operator's Xray DNS servers.
func (*Store) StatsByUser ¶
StatsByUser returns each user's traffic total over the period (users with no traffic appear with zeros), busiest first.
func (*Store) StatsSeries ¶
StatsSeries returns per-day totals between from and to (inclusive, YYYY-MM-DD). userID == 0 aggregates across all users.
func (*Store) TouchLastSeen ¶
TouchLastSeen updates a user's last activity time (used by the poller too).
func (*Store) UpdateAdminPassword ¶
UpdateAdminPassword replaces an admin's password hash.
func (*Store) UpdateAdminUsername ¶
UpdateAdminUsername changes an admin's login name.
func (*Store) UpdateTraffic ¶
UpdateTraffic adds deltas to lifetime totals and records the raw counters.
func (*Store) WorkingUsers ¶
WorkingUsers returns users that should be in the proxy config right now: manually enabled AND not expired AND within their data limit. enabled is an independent manual flag — expiry/quota never change it, they just exclude the user from the config here.