147 lines
5.7 KiB
Go
147 lines
5.7 KiB
Go
package main
|
||
|
||
import (
|
||
"database/sql"
|
||
|
||
"github.com/lib/pq"
|
||
)
|
||
|
||
// Структура для таблицы instances
|
||
type Instance struct {
|
||
Hostname string
|
||
Instance string
|
||
}
|
||
|
||
// Структура для таблицы apps_settings (бывшая appsSettings)
|
||
type AppsSettings struct {
|
||
L7ResourceID int
|
||
WAFEnabled sql.NullBool
|
||
WAFVendor sql.NullString // Vendor WAF: ptaf, sw и т.д.
|
||
CustomInputHTTPPorts pq.Int64Array // Массив HTTP портов для прослушивания (Angie и контейнер)
|
||
CustomInputHTTPSPorts pq.Int64Array // Массив HTTPS портов для прослушивания (Angie и контейнер)
|
||
CustomOutputHTTPPorts pq.Int64Array // Массив HTTP портов для проксирования к origin
|
||
CustomOutputHTTPSPorts pq.Int64Array // Массив HTTPS портов для проксирования к origin
|
||
UpstreamAngieCustom sql.NullString
|
||
ServerNginxCustom sql.NullString
|
||
ServerAngieCustom sql.NullString
|
||
ClientTitle string
|
||
UpstreamNginxCustom sql.NullString
|
||
LocationAngieCustom sql.NullString
|
||
LocationNginxCustom sql.NullString
|
||
ServerDirectivesAngieCustom sql.NullString // Кастомные server директивы для Angie
|
||
ServerDirectivesNginxCustom sql.NullString // Кастомные server директивы для Nginx
|
||
SNI sql.NullInt64 // 0 = keepalive включен, 1 = keepalive отключен
|
||
Mode sql.NullString // Режим работы ресурса: auto = автоматическое управление, manual = ручное, disabled = отключен
|
||
SSLEnabled sql.NullBool // true = SSL включен (по умолчанию), false = plain HTTP без SSL
|
||
CustomAngieSSL sql.NullString // Кастомные SSL директивы для Angie - полностью заменяют дефолтные если заполнено
|
||
MaxFails sql.NullInt64 // Количество неудачных попыток к origin (дефолт 5)
|
||
FailTimeout sql.NullInt64 // Время в секундах после которого origin снова доступен (дефолт 15)
|
||
CustomSWNginxSSL sql.NullString // Кастомные SSL директивы для SW nginx - полностью заменяют дефолтные если заполнено
|
||
}
|
||
|
||
// Структура для таблицы client_info (бывшая nodes)
|
||
type ClientInfo struct {
|
||
ContainersCount int
|
||
PTAFConfig sql.NullString
|
||
ClientTitle string
|
||
FluentBitPort sql.NullInt64
|
||
WAFInstance string // Instance для связи с apps_settings
|
||
}
|
||
|
||
// Структуры для API ответов
|
||
type OriginResponse struct {
|
||
Data struct {
|
||
Result struct {
|
||
Items []struct {
|
||
ID int `json:"id"`
|
||
IP string `json:"ip"`
|
||
Weight int `json:"weight"`
|
||
Mode string `json:"mode"`
|
||
Comment string `json:"comment"`
|
||
CreatedAt int64 `json:"createdAt"`
|
||
} `json:"items"`
|
||
} `json:"result"`
|
||
} `json:"data"`
|
||
}
|
||
|
||
type AliasResponse struct {
|
||
Data struct {
|
||
Result struct {
|
||
Items []struct {
|
||
ID int `json:"id"`
|
||
Domain string `json:"domain"`
|
||
UseCustomSSL int `json:"useCustomSsl"`
|
||
UseLetsEncrypt int `json:"useLetsencryptSsl"`
|
||
SSLExpireDate int64 `json:"sslExpireDate"`
|
||
CreatedAt int64 `json:"createdAt"`
|
||
L7ResourceID int `json:"l7ResourceId"`
|
||
} `json:"items"`
|
||
} `json:"result"`
|
||
} `json:"data"`
|
||
}
|
||
|
||
type ResourceResponse struct {
|
||
Data struct {
|
||
Result struct {
|
||
L7ResourceID int `json:"l7ResourceId"`
|
||
L7ResourceName string `json:"l7ResourceName"`
|
||
CreatedAt int64 `json:"createdAt"`
|
||
L7ResourceActive int `json:"l7ResourceIsActive"`
|
||
ModifiedAt int64 `json:"modifiedAt"`
|
||
ProtectedIP string `json:"protectedIp"`
|
||
HTTP2Support int `json:"http2Support"`
|
||
GRPCSupport int `json:"grpcSupport"`
|
||
WAFMode int `json:"wafMode"`
|
||
WAFEnabled int `json:"wafEnabled"`
|
||
} `json:"result"`
|
||
} `json:"data"`
|
||
}
|
||
|
||
// Структура для хранения данных о ресурсе
|
||
type ResourceData struct {
|
||
L7ResourceID int
|
||
ServerName string
|
||
Aliases []string
|
||
Origins []OriginItem
|
||
AppsSettings AppsSettings
|
||
}
|
||
|
||
type OriginItem struct {
|
||
IP string
|
||
Weight int
|
||
Mode string
|
||
}
|
||
|
||
// Структура для портов
|
||
type PortMapping struct {
|
||
HTTPPorts map[int]int // map[customPort]dockerPort - для HTTP портов
|
||
HTTPSPorts map[int]int // map[customPort]dockerPort - для HTTPS портов
|
||
}
|
||
|
||
// Структура для отсортированного вывода портов в docker-compose
|
||
type SortedPortMapping struct {
|
||
CustomPort int
|
||
DockerPort int
|
||
}
|
||
|
||
// Структура для сохранения портов ресурса в файл
|
||
type SavedResourcePorts struct {
|
||
L7ResourceID int `json:"l7resourceid"`
|
||
HTTPPorts map[int]int `json:"http_ports"` // map[customPort]dockerPort
|
||
HTTPSPorts map[int]int `json:"https_ports"` // map[customPort]dockerPort
|
||
}
|
||
|
||
// Структура для сохранения всех портов контейнера
|
||
type SavedContainerPorts struct {
|
||
ContainerNum int `json:"container_num"`
|
||
Resources []SavedResourcePorts `json:"resources"`
|
||
}
|
||
|
||
// Структура для кастомного server блока
|
||
type CustomServerBlock struct {
|
||
Port int
|
||
ServerName string
|
||
Aliases []string
|
||
Content string
|
||
IsHTTPS bool
|
||
}
|