Added webcheck to db

This commit is contained in:
Magnus Root 2026-05-14 17:06:12 +03:00
parent 853ada564b
commit 7ff9a15945
4 changed files with 11 additions and 5 deletions

View file

@ -75,7 +75,7 @@ func setupContainers(config Config, clientTitle string, clientInfo *ClientInfo,
ptafConfig = clientInfo.PTAFConfig.String ptafConfig = clientInfo.PTAFConfig.String
} }
changed, err := generateNginxConf(nginxConfPath, config, ptafConfig, existingPodIP, clientInfo.Debug, getPtafFallbackCode(*clientInfo)) changed, err := generateNginxConf(nginxConfPath, config, ptafConfig, existingPodIP, clientInfo.Debug, getPtafFallbackCode(*clientInfo), clientInfo.WorkerProcesses)
if err != nil { if err != nil {
return fmt.Errorf("ошибка генерации nginx.conf: %w", err) return fmt.Errorf("ошибка генерации nginx.conf: %w", err)
} }

View file

@ -400,7 +400,10 @@ func reloadAngie() {
} }
// generateNginxConf генерирует основной nginx.conf для PTAF // generateNginxConf генерирует основной nginx.conf для PTAF
func generateNginxConf(filePath string, config Config, ptafConfig string, existingPodIP string, debug bool, ptafFallbackCode string) (bool, error) { func generateNginxConf(filePath string, config Config, ptafConfig string, existingPodIP string, debug bool, ptafFallbackCode string, workerProcesses int) (bool, error) {
if workerProcesses <= 0 {
workerProcesses = 4
}
var randomIP string var randomIP string
if existingPodIP != "" { if existingPodIP != "" {
randomIP = existingPodIP randomIP = existingPodIP
@ -538,7 +541,7 @@ http {
include /opt/ptaf/conf/conf.d/*.conf; include /opt/ptaf/conf/conf.d/*.conf;
} }
`, config.WorkerProcesses, randomIP, ptafLogLevel, debugEnv, hostname, errorLogLevel, config.WorkerConnections, clientTitle, ptafFallbackCode, ptafConfig) `, workerProcesses, randomIP, ptafLogLevel, debugEnv, hostname, errorLogLevel, config.WorkerConnections, clientTitle, ptafFallbackCode, ptafConfig)
return writeFileIfChanged(filePath, content) return writeFileIfChanged(filePath, content)
} }

6
db.go
View file

@ -99,7 +99,7 @@ func getClientInfoByInstance(db *sql.DB, instance string) ([]ClientInfo, error)
query := ` query := `
SELECT containers_count, ptaf_config, client_title, fluent_bit_port, waf_instance, SELECT containers_count, ptaf_config, client_title, fluent_bit_port, waf_instance,
docker_image, docker_image_download, debug, shm_size, ptaf_fallback_code, docker_image, docker_image_download, debug, shm_size, ptaf_fallback_code,
sp_antiddos, real_ip_networks sp_antiddos, real_ip_networks, worker_processes
FROM client_info FROM client_info
WHERE waf_instance = $1 WHERE waf_instance = $1
` `
@ -130,6 +130,7 @@ func getClientInfoByInstance(db *sql.DB, instance string) ([]ClientInfo, error)
&ci.PtafFallbackCode, &ci.PtafFallbackCode,
&ci.SpAntiddos, &ci.SpAntiddos,
pq.Array(&ci.RealIPNetworks), pq.Array(&ci.RealIPNetworks),
&ci.WorkerProcesses,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("ошибка сканирования строки: %w", err) return nil, fmt.Errorf("ошибка сканирования строки: %w", err)
@ -216,7 +217,7 @@ func getClientInfoByClientTitle(db *sql.DB, clientTitle string) (*ClientInfo, er
query := ` query := `
SELECT containers_count, ptaf_config, client_title, fluent_bit_port, waf_instance, SELECT containers_count, ptaf_config, client_title, fluent_bit_port, waf_instance,
docker_image, docker_image_download, debug, shm_size, ptaf_fallback_code, docker_image, docker_image_download, debug, shm_size, ptaf_fallback_code,
sp_antiddos, real_ip_networks sp_antiddos, real_ip_networks, worker_processes
FROM client_info FROM client_info
WHERE client_title = $1 WHERE client_title = $1
` `
@ -236,6 +237,7 @@ func getClientInfoByClientTitle(db *sql.DB, clientTitle string) (*ClientInfo, er
&clientInfo.PtafFallbackCode, &clientInfo.PtafFallbackCode,
&clientInfo.SpAntiddos, &clientInfo.SpAntiddos,
pq.Array(&clientInfo.RealIPNetworks), pq.Array(&clientInfo.RealIPNetworks),
&clientInfo.WorkerProcesses,
) )
if err != nil { if err != nil {
if strings.Contains(err.Error(), "does not exist") { if strings.Contains(err.Error(), "does not exist") {

View file

@ -55,6 +55,7 @@ type ClientInfo struct {
PtafFallbackCode sql.NullString // Код ответа ptaf_fallback: число или 'pass' (дефолт: 418) PtafFallbackCode sql.NullString // Код ответа ptaf_fallback: число или 'pass' (дефолт: 418)
SpAntiddos bool // Использовать антиддос сети для set_real_ip (дефолт true) SpAntiddos bool // Использовать антиддос сети для set_real_ip (дефолт true)
RealIPNetworks []string // Кастомные сети для set_real_ip если SpAntiddos = false RealIPNetworks []string // Кастомные сети для set_real_ip если SpAntiddos = false
WorkerProcesses int // Количество worker процессов nginx (дефолт 4)
} }
// Структуры для API ответов // Структуры для API ответов