Documentation ¶
Index ¶
- Constants
- func IsValidPermission(p string) bool
- func MeasureDiscSpaceAvailable(path string) (int64, error)
- func Migrations(log logs.Log) []migration.Migrator
- func NormalizeUsername(username string) string
- func RestartNeeded(c1, c2 *ConfigJSON) bool
- func ValidateConfig(c *ConfigJSON) error
- func ValidateRecordingConfig(isDefaults bool, c *RecordingJSON) error
- type BaseModel
- type Camera
- type ConfigDB
- func (c *ConfigDB) GenerateNewID(tx *gorm.DB, key string) (int64, error)
- func (c *ConfigDB) GetConfig() ConfigJSON
- func (c *ConfigDB) GetUser(r *http.Request) *User
- func (c *ConfigDB) GetUserID(r *http.Request) int64
- func (c *ConfigDB) IsCallerOnLAN(r *http.Request) bool
- func (c *ConfigDB) Login(w http.ResponseWriter, r *http.Request)
- func (c *ConfigDB) LoginInternal(w http.ResponseWriter, userID int64, expiresAt time.Time, mode string)
- func (c *ConfigDB) Logout(w http.ResponseWriter, r *http.Request)
- func (c *ConfigDB) NumAdminUsers() (int, error)
- func (c *ConfigDB) PurgeExpiredSessions()
- func (c *ConfigDB) SetConfig(cfg ConfigJSON) (bool, error)
- type ConfigJSON
- type Key
- type RecordInstruction
- type RecordMode
- type RecordingJSON
- type Session
- type SystemConfig
- type User
- type UserPermissions
- type Variable
Constants ¶
const ( LoginModeCookie = "Cookie" LoginModeBearerToken = "BearerToken" LoginModeCookieAndBearerToken = "CookieAndBearerToken" )
const KeyMain = "main"
const SessionCookie = "session"
SYNC-CYCLOPS-SESSION-COOKIE
Variables ¶
This section is empty.
Functions ¶
func IsValidPermission ¶
func MeasureDiscSpaceAvailable ¶
Measure the space available at the given path, or the first parent directory that exists. Returns the amount of space available in bytes.
func NormalizeUsername ¶
func RestartNeeded ¶
func RestartNeeded(c1, c2 *ConfigJSON) bool
func ValidateConfig ¶
func ValidateConfig(c *ConfigJSON) error
Returns an error if there is anything invalid about the config, or nil if everything is OK
func ValidateRecordingConfig ¶
func ValidateRecordingConfig(isDefaults bool, c *RecordingJSON) error
If isDefaults is true, then this is the default recording config for the whole system. If isDefaults is false, then this is the recording config for a specific camera.
Types ¶
type BaseModel ¶
type BaseModel struct {
ID int64 `gorm:"primaryKey" json:"id"`
}
BaseModel is our base class for a GORM model. The default GORM Model uses int, but we prefer int64
type Camera ¶
type Camera struct { BaseModel Model string `json:"model"` // eg HikVision (actually CameraModels enum) Name string `json:"name"` // Friendly name Host string `json:"host"` // Hostname such as 192.168.1.33 Port int `json:"port" gorm:"default:null"` // if 0, then default is 554 Username string `json:"username"` // RTSP username Password string `json:"password"` // RTSP password HighResURLSuffix string `json:"highResURLSuffix" gorm:"default:null"` // eg Streaming/Channels/101 for HikVision. Can leave blank if Model is a known type. LowResURLSuffix string `json:"lowResURLSuffix" gorm:"default:null"` // eg Streaming/Channels/102 for HikVision. Can leave blank if Model is a known type. CreatedAt dbh.IntTime `json:"createdAt" gorm:"autoCreateTime:milli"` UpdatedAt dbh.IntTime `json:"updatedAt" gorm:"autoUpdateTime:milli"` // The long lived name is used to identify the camera in the storage archive. // If necessary, we can make this configurable. // At present, it is equal to the camera ID. But in future, we could allow // the user to override this. For example, if their system goes down, but their // archive is on another disk, and they want to restore all the cameras, and // still have the history intact, and matching up to the new (but same) cameras. // Or perhaps you have to replace a camera, but want to retain the logical identify. LongLivedName string `json:"longLivedName"` }
SYNC-RECORD-CAMERA
func (*Camera) DeepEquals ¶
func (*Camera) EqualsConnection ¶
Compare the current camera config against the new camera config, and return true if the connection details refer to the exact same camera host and config.
type ConfigDB ¶
type ConfigDB struct { Log logs.Log DB *gorm.DB PrivateKey wgtypes.Key PublicKey wgtypes.Key // Addresses allowed from VPN network. Used to detect if user is connecting from LAN or VPN. // Injected by VPN system after it has connected. There can be two: an IPv4 and an IPv6. VpnAllowedIP net.IPNet // contains filtered or unexported fields }
func NewConfigDB ¶
func (*ConfigDB) GenerateNewID ¶
Generate a new ID from the 'next_id' table in the database
func (*ConfigDB) GetConfig ¶
func (c *ConfigDB) GetConfig() ConfigJSON
func (*ConfigDB) GetUser ¶
Returns the user or nil. See GetUserID() for discussion about allowBasic.
func (*ConfigDB) IsCallerOnLAN ¶
Returns true if: 1. We are not using a VPN 2. We are using a VPN, but the caller is not reaching us from it
func (*ConfigDB) LoginInternal ¶
func (*ConfigDB) NumAdminUsers ¶
func (*ConfigDB) PurgeExpiredSessions ¶
func (c *ConfigDB) PurgeExpiredSessions()
type ConfigJSON ¶
type ConfigJSON struct { Recording RecordingJSON `json:"recording"` // Recording settings. We aim to make some settings overridable per-camera, such as recording mode. TempFilePath string `json:"tempFilePath"` // Temporary file path ArcServer string `json:"arcServer"` // Arc server URL ArcApiKey string `json:"arcApiKey"` // Arc API key }
Root system config SYNC-SYSTEM-CONFIG-JSON
type Key ¶
type Key struct { Name string `gorm:"primaryKey"` Value string // normal (not URL-safe) base64 encoded (same as Wireguard) }
Generic key/value pairs in our database. For example, KeyMain, etc.
type RecordInstruction ¶
type RecordMode ¶
type RecordMode string
What causes us to record video
const ( RecordModeAlways RecordMode = "always" RecordModeOnMovement RecordMode = "movement" RecordModeOnDetection RecordMode = "detection" )
type RecordingJSON ¶
type RecordingJSON struct { Mode RecordMode `json:"mode,omitempty"` Path string `json:"path,omitempty"` // Root directory of fsv archive MaxStorageSize string `json:"maxStorageSize,omitempty"` // Maximum storage with optional "gb", "mb", "tb" suffix. If no suffix, then bytes. RecordBeforeEvent int `json:"recordBeforeEvent,omitempty"` // Record this many seconds before an event RecordAfterEvent int `json:"recordAfterEvent,omitempty"` // Record this many seconds after an event }
Recording config SYNC-SYSTEM-RECORDING-CONFIG-JSON
func (*RecordingJSON) RecordAfterEventDuration ¶
func (r *RecordingJSON) RecordAfterEventDuration() time.Duration
func (*RecordingJSON) RecordBeforeEventDuration ¶
func (r *RecordingJSON) RecordBeforeEventDuration() time.Duration
type SystemConfig ¶
type SystemConfig struct { Key string `gorm:"primaryKey"` Value *dbh.JSONField[ConfigJSON] }
type User ¶
type User struct { BaseModel Username string `json:"username"` UsernameNormalized string `json:"username_normalized"` Permissions string `json:"permissions"` Name string `json:"name" gorm:"default:null"` Password []byte `json:"-" gorm:"default:null"` }
SYNC-RECORD-USER
func (*User) HasPermission ¶
func (u *User) HasPermission(p UserPermissions) bool
type UserPermissions ¶
type UserPermissions string
UserPermissions are single characters that are present in the user's Permissions field
const ( UserPermissionAdmin UserPermissions = "a" UserPermissionViewer UserPermissions = "v" )