miaopanel
1package store
2
3import "encoding/json"
4
5// User is a panel operator account.
6type User struct {
7 ID int64 `json:"id"`
8 Username string `json:"username"`
9 PassHash string `json:"-"`
10 Role string `json:"role"`
11 TOTPSecret string `json:"-"`
12 TOTPEnabled bool `json:"totp_enabled"`
13 Recovery string `json:"-"`
14 Status int `json:"status"`
15 LastLoginIP string `json:"last_login_ip"`
16 LastLoginAt int64 `json:"last_login_at"`
17 CreatedAt int64 `json:"created_at"`
18}
19
20// Session is a server side login session.
21type Session struct {
22 ID string
23 UserID int64
24 IP string
25 UA string
26 CSRF string
27 CreatedAt int64
28 ExpiresAt int64
29 LastSeen int64
30}
31
32// Site options are the per-site security and caching knobs rendered into the
33// nginx fragments. Stored as JSON so new fields do not need a migration.
34type SiteOptions struct {
35 HTTPSRedirect bool `json:"https_redirect"`
36 HSTS bool `json:"hsts"`
37 SecurityHead bool `json:"security_headers"`
38 LimitRate int `json:"limit_rate_kb"`
39 ConnPerIP int `json:"conn_per_ip"`
40 ConnPerServer int `json:"conn_per_server"`
41 AntiLeak bool `json:"anti_leech"`
42 AntiLeakHosts []string `json:"anti_leech_hosts"`
43 IPMode string `json:"ip_mode"` // "" | "allow" | "deny"
44 IPList []string `json:"ip_list"`
45 WAF bool `json:"waf"`
46 WAFRate int `json:"waf_rate"`
47 WAFBurst int `json:"waf_burst"`
48 // GatewayPort is the loopback port of the origin server used when the
49 // deep inspection gateway is enabled. 0 means "not allocated yet".
50 GatewayPort int `json:"gateway_port"`
51 Custom string `json:"custom_nginx"`
52 // ListenPort overrides the public HTTP listener (default 80). It lets a
53 // PHP site such as phpMyAdmin be exposed on a dedicated port.
54 ListenPort int `json:"listen_port"`
55 // Docker bindings are written when a proxy site is created from the Docker
56 // page so the container page can list and unbind its domains.
57 DockerContainerID string `json:"docker_container_id,omitempty"`
58 DockerContainerName string `json:"docker_container_name,omitempty"`
59 DockerContainerPort int `json:"docker_container_port,omitempty"`
60 DockerHostPort int `json:"docker_host_port,omitempty"`
61 // Present records which JSON keys the current request actually contained.
62 // It lets Update keep the fields a partial client omitted instead of
63 // silently zeroing security_headers and friends. Never persisted.
64 Present map[string]bool `json:"-"`
65}
66
67// UnmarshalJSON tracks the supplied keys so partial updates can be merged.
68func (o *SiteOptions) UnmarshalJSON(data []byte) error {
69 type alias SiteOptions
70 var a alias
71 if err := json.Unmarshal(data, &a); err != nil {
72 return err
73 }
74 keys := map[string]json.RawMessage{}
75 if err := json.Unmarshal(data, &keys); err != nil {
76 return err
77 }
78 *o = SiteOptions(a)
79 o.Present = make(map[string]bool, len(keys))
80 for k := range keys {
81 o.Present[k] = true
82 }
83 return nil
84}
85
86// Site is a managed website or application.
87type Site struct {
88 ID int64 `json:"id"`
89 Name string `json:"name"`
90 Slug string `json:"slug"`
91 Kind string `json:"kind"` // static | php | go | node | proxy
92 Root string `json:"root"`
93 Port int `json:"port"`
94 PHPVersion string `json:"php_version"`
95 Status string `json:"status"` // running | stopped
96 RunUser string `json:"run_user"`
97 StartCmd string `json:"start_cmd"`
98 Env string `json:"env"`
99 Upstream string `json:"upstream"`
100 Remark string `json:"remark"`
101 SSLEnabled bool `json:"ssl_enabled"`
102 Options SiteOptions `json:"options"`
103 Domains []string `json:"domains"`
104 CreatedAt int64 `json:"created_at"`
105 UpdatedAt int64 `json:"updated_at"`
106 // LiveStatus is filled in by the API layer from systemd/nginx and is never
107 // persisted: the Status column only remembers the last explicit action.
108 LiveStatus string `json:"live_status,omitempty"`
109}
110
111// AuditEntry is one recorded mutating operation.
112type AuditEntry struct {
113 UserID int64
114 Username string
115 IP string
116 UA string
117 Module string
118 Action string
119 Target string
120 Params string
121 Result string
122 CostMS int64
123}