package store import "encoding/json" // User is a panel operator account. type User struct { ID int64 `json:"id"` Username string `json:"username"` PassHash string `json:"-"` Role string `json:"role"` TOTPSecret string `json:"-"` TOTPEnabled bool `json:"totp_enabled"` Recovery string `json:"-"` Status int `json:"status"` LastLoginIP string `json:"last_login_ip"` LastLoginAt int64 `json:"last_login_at"` CreatedAt int64 `json:"created_at"` } // Session is a server side login session. type Session struct { ID string UserID int64 IP string UA string CSRF string CreatedAt int64 ExpiresAt int64 LastSeen int64 } // Site options are the per-site security and caching knobs rendered into the // nginx fragments. Stored as JSON so new fields do not need a migration. type SiteOptions struct { HTTPSRedirect bool `json:"https_redirect"` HSTS bool `json:"hsts"` SecurityHead bool `json:"security_headers"` LimitRate int `json:"limit_rate_kb"` ConnPerIP int `json:"conn_per_ip"` ConnPerServer int `json:"conn_per_server"` AntiLeak bool `json:"anti_leech"` AntiLeakHosts []string `json:"anti_leech_hosts"` IPMode string `json:"ip_mode"` // "" | "allow" | "deny" IPList []string `json:"ip_list"` WAF bool `json:"waf"` WAFRate int `json:"waf_rate"` WAFBurst int `json:"waf_burst"` // GatewayPort is the loopback port of the origin server used when the // deep inspection gateway is enabled. 0 means "not allocated yet". GatewayPort int `json:"gateway_port"` Custom string `json:"custom_nginx"` // ListenPort overrides the public HTTP listener (default 80). It lets a // PHP site such as phpMyAdmin be exposed on a dedicated port. ListenPort int `json:"listen_port"` // Docker bindings are written when a proxy site is created from the Docker // page so the container page can list and unbind its domains. DockerContainerID string `json:"docker_container_id,omitempty"` DockerContainerName string `json:"docker_container_name,omitempty"` DockerContainerPort int `json:"docker_container_port,omitempty"` DockerHostPort int `json:"docker_host_port,omitempty"` // Present records which JSON keys the current request actually contained. // It lets Update keep the fields a partial client omitted instead of // silently zeroing security_headers and friends. Never persisted. Present map[string]bool `json:"-"` } // UnmarshalJSON tracks the supplied keys so partial updates can be merged. func (o *SiteOptions) UnmarshalJSON(data []byte) error { type alias SiteOptions var a alias if err := json.Unmarshal(data, &a); err != nil { return err } keys := map[string]json.RawMessage{} if err := json.Unmarshal(data, &keys); err != nil { return err } *o = SiteOptions(a) o.Present = make(map[string]bool, len(keys)) for k := range keys { o.Present[k] = true } return nil } // Site is a managed website or application. type Site struct { ID int64 `json:"id"` Name string `json:"name"` Slug string `json:"slug"` Kind string `json:"kind"` // static | php | go | node | proxy Root string `json:"root"` Port int `json:"port"` PHPVersion string `json:"php_version"` Status string `json:"status"` // running | stopped RunUser string `json:"run_user"` StartCmd string `json:"start_cmd"` Env string `json:"env"` Upstream string `json:"upstream"` Remark string `json:"remark"` SSLEnabled bool `json:"ssl_enabled"` Options SiteOptions `json:"options"` Domains []string `json:"domains"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` // LiveStatus is filled in by the API layer from systemd/nginx and is never // persisted: the Status column only remembers the last explicit action. LiveStatus string `json:"live_status,omitempty"` } // AuditEntry is one recorded mutating operation. type AuditEntry struct { UserID int64 Username string IP string UA string Module string Action string Target string Params string Result string CostMS int64 }