Skip to content

Commit eb9d139

Browse files
committed
modified: internal/service/install_config.go
1 parent 8221cd0 commit eb9d139

6 files changed

Lines changed: 319 additions & 161 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ sudo cp docs/install.example.json /etc/ols-cli/install.json
141141
sudo ols install
142142
```
143143

144-
`install.json` also supports `owasp_crs_version` (for example, `"owasp_crs_version": "4.21.0"`), which is used when enabling OWASP via `site create/update --enable-owasp`.
144+
`install.json` also supports:
145+
- `owasp_crs_version` (for example, `"4.21.0"`) for OWASP CRS setup during `ols install`
146+
- `vh_recaptcha_type` and `vh_recaptcha_reg_conn_limit` (defaults: `1` and `500`) used when enabling vhost reCAPTCHA via `site create/update --enable-recaptcha`
147+
148+
By default, `ols install` prepares server-level security blocks as:
149+
- `module mod_security` with `ls_enabled 0`
150+
- `lsrecaptcha` with `enabled 1` and `type 0`
145151

146152
Override config values with flags when needed:
147153

docs/install.example.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"https_port": 443,
77
"ssl_cert_file": "/usr/local/lsws/admin/conf/webadmin.crt",
88
"ssl_key_file": "/usr/local/lsws/admin/conf/webadmin.key",
9-
"owasp_crs_version": "4.21.0"
9+
"owasp_crs_version": "4.21.0",
10+
"vh_recaptcha_type": 1,
11+
"vh_recaptcha_reg_conn_limit": 500
1012
}

internal/service/install_config.go

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,46 @@ import (
1717
const defaultInstallConfigPath = "/etc/ols-cli/install.json"
1818

1919
type RuntimeInstallConfig struct {
20-
PHPVersion string `json:"php_version"`
21-
DatabaseEngine string `json:"database"`
22-
ConfigureListeners *bool `json:"configure_listeners,omitempty"`
23-
HTTPPort int `json:"http_port"`
24-
HTTPSPort int `json:"https_port"`
25-
SSLCertFile string `json:"ssl_cert_file"`
26-
SSLKeyFile string `json:"ssl_key_file"`
27-
OWASPCRSVersion string `json:"owasp_crs_version"`
20+
PHPVersion string `json:"php_version"`
21+
DatabaseEngine string `json:"database"`
22+
ConfigureListeners *bool `json:"configure_listeners,omitempty"`
23+
HTTPPort int `json:"http_port"`
24+
HTTPSPort int `json:"https_port"`
25+
SSLCertFile string `json:"ssl_cert_file"`
26+
SSLKeyFile string `json:"ssl_key_file"`
27+
OWASPCRSVersion string `json:"owasp_crs_version"`
28+
VHRecaptchaType int `json:"vh_recaptcha_type"`
29+
VHRecaptchaReqLimit int `json:"vh_recaptcha_reg_conn_limit"`
2830
}
2931

3032
type resolvedInstallPlan struct {
31-
ConfigPath string
32-
PHPVersion string
33-
DatabaseEngine string
34-
DatabasePackage string
35-
ConfigureListeners bool
36-
HTTPPort int
37-
HTTPSPort int
38-
SSLCertFile string
39-
SSLKeyFile string
40-
OWASPCRSVersion string
33+
ConfigPath string
34+
PHPVersion string
35+
DatabaseEngine string
36+
DatabasePackage string
37+
ConfigureListeners bool
38+
HTTPPort int
39+
HTTPSPort int
40+
SSLCertFile string
41+
SSLKeyFile string
42+
OWASPCRSVersion string
43+
VHRecaptchaType int
44+
VHRecaptchaReqLimit int
4145
}
4246

4347
func defaultRuntimeInstallConfig(lswsRoot string) RuntimeInstallConfig {
4448
enabled := true
4549
return RuntimeInstallConfig{
46-
PHPVersion: "85",
47-
DatabaseEngine: "mariadb",
48-
ConfigureListeners: &enabled,
49-
HTTPPort: 80,
50-
HTTPSPort: 443,
51-
SSLCertFile: filepath.Join(lswsRoot, "admin", "conf", "webadmin.crt"),
52-
SSLKeyFile: filepath.Join(lswsRoot, "admin", "conf", "webadmin.key"),
53-
OWASPCRSVersion: defaultOWASPCRSVersion,
50+
PHPVersion: "85",
51+
DatabaseEngine: "mariadb",
52+
ConfigureListeners: &enabled,
53+
HTTPPort: 80,
54+
HTTPSPort: 443,
55+
SSLCertFile: filepath.Join(lswsRoot, "admin", "conf", "webadmin.crt"),
56+
SSLKeyFile: filepath.Join(lswsRoot, "admin", "conf", "webadmin.key"),
57+
OWASPCRSVersion: defaultOWASPCRSVersion,
58+
VHRecaptchaType: defaultVHRecaptchaType,
59+
VHRecaptchaReqLimit: defaultVHRecaptchaReqLimit,
5460
}
5561
}
5662

@@ -112,6 +118,12 @@ func mergeRuntimeInstallConfig(base, override RuntimeInstallConfig) RuntimeInsta
112118
if v := strings.TrimSpace(override.OWASPCRSVersion); v != "" {
113119
base.OWASPCRSVersion = v
114120
}
121+
if override.VHRecaptchaType > 0 {
122+
base.VHRecaptchaType = override.VHRecaptchaType
123+
}
124+
if override.VHRecaptchaReqLimit > 0 {
125+
base.VHRecaptchaReqLimit = override.VHRecaptchaReqLimit
126+
}
115127
return base
116128
}
117129

@@ -172,6 +184,14 @@ func resolveInstallPlan(opts InstallOptions, info platform.Info, lswsRoot string
172184
if owaspCRSVersion == "" {
173185
owaspCRSVersion = defaultOWASPCRSVersion
174186
}
187+
vhRecaptchaType := cfg.VHRecaptchaType
188+
if vhRecaptchaType <= 0 {
189+
vhRecaptchaType = defaultVHRecaptchaType
190+
}
191+
vhRecaptchaReqLimit := cfg.VHRecaptchaReqLimit
192+
if vhRecaptchaReqLimit <= 0 {
193+
vhRecaptchaReqLimit = defaultVHRecaptchaReqLimit
194+
}
175195

176196
if err := validatePort(httpPort, "http_port"); err != nil {
177197
return resolvedInstallPlan{}, err
@@ -195,16 +215,18 @@ func resolveInstallPlan(opts InstallOptions, info platform.Info, lswsRoot string
195215
}
196216

197217
return resolvedInstallPlan{
198-
ConfigPath: cfgPath,
199-
PHPVersion: phpVersion,
200-
DatabaseEngine: dbEngine,
201-
DatabasePackage: dbPackage,
202-
ConfigureListeners: configureListeners,
203-
HTTPPort: httpPort,
204-
HTTPSPort: httpsPort,
205-
SSLCertFile: sslCertFile,
206-
SSLKeyFile: sslKeyFile,
207-
OWASPCRSVersion: owaspCRSVersion,
218+
ConfigPath: cfgPath,
219+
PHPVersion: phpVersion,
220+
DatabaseEngine: dbEngine,
221+
DatabasePackage: dbPackage,
222+
ConfigureListeners: configureListeners,
223+
HTTPPort: httpPort,
224+
HTTPSPort: httpsPort,
225+
SSLCertFile: sslCertFile,
226+
SSLKeyFile: sslKeyFile,
227+
OWASPCRSVersion: owaspCRSVersion,
228+
VHRecaptchaType: vhRecaptchaType,
229+
VHRecaptchaReqLimit: vhRecaptchaReqLimit,
208230
}, nil
209231
}
210232

internal/service/install_config_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func TestResolveInstallPlanDefaults(t *testing.T) {
3939
if plan.OWASPCRSVersion != defaultOWASPCRSVersion {
4040
t.Fatalf("expected default owasp crs version %s, got %s", defaultOWASPCRSVersion, plan.OWASPCRSVersion)
4141
}
42+
if plan.VHRecaptchaType != defaultVHRecaptchaType {
43+
t.Fatalf("expected default vh recaptcha type %d, got %d", defaultVHRecaptchaType, plan.VHRecaptchaType)
44+
}
45+
if plan.VHRecaptchaReqLimit != defaultVHRecaptchaReqLimit {
46+
t.Fatalf("expected default vh recaptcha request limit %d, got %d", defaultVHRecaptchaReqLimit, plan.VHRecaptchaReqLimit)
47+
}
4248
}
4349

4450
func TestResolveInstallPlanOverrides(t *testing.T) {
@@ -88,7 +94,9 @@ func TestLoadRuntimeInstallConfigIncludesOWASPCRSVersion(t *testing.T) {
8894
"https_port": 443,
8995
"ssl_cert_file": "/usr/local/lsws/admin/conf/webadmin.crt",
9096
"ssl_key_file": "/usr/local/lsws/admin/conf/webadmin.key",
91-
"owasp_crs_version": "4.22.0"
97+
"owasp_crs_version": "4.22.0",
98+
"vh_recaptcha_type": 2,
99+
"vh_recaptcha_reg_conn_limit": 650
92100
}`
93101
if err := os.WriteFile(configPath, []byte(content), 0o644); err != nil {
94102
t.Fatalf("write config: %v", err)
@@ -101,6 +109,12 @@ func TestLoadRuntimeInstallConfigIncludesOWASPCRSVersion(t *testing.T) {
101109
if cfg.OWASPCRSVersion != "4.22.0" {
102110
t.Fatalf("expected owasp_crs_version 4.22.0, got %s", cfg.OWASPCRSVersion)
103111
}
112+
if cfg.VHRecaptchaType != 2 {
113+
t.Fatalf("expected vh_recaptcha_type 2, got %d", cfg.VHRecaptchaType)
114+
}
115+
if cfg.VHRecaptchaReqLimit != 650 {
116+
t.Fatalf("expected vh_recaptcha_reg_conn_limit 650, got %d", cfg.VHRecaptchaReqLimit)
117+
}
104118
}
105119

106120
func TestResolveInstallPlanDatabaseNone(t *testing.T) {

0 commit comments

Comments
 (0)