Skip to content

Commit bed29a2

Browse files
committed
CP-308800: Dynamic control http firewall service
Signed-off-by: Bengang Yuan <[email protected]>
1 parent b9b6e49 commit bed29a2

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

ocaml/xapi/dbsync_slave.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,13 @@ let refresh_localhost_info ~__context info =
134134
) else
135135
Db.Host.remove_from_other_config ~__context ~self:host
136136
~key:Xapi_globs.host_no_local_storage ;
137-
let script_output =
138-
Helpers.call_script !Xapi_globs.firewall_port_config_script ["check"; "80"]
137+
let module F =
138+
( val Firewall.firewall_provider !Xapi_globs.firewall_backend
139+
: Firewall.FIREWALL
140+
)
139141
in
140-
try
141-
let network_state = Scanf.sscanf script_output "Port 80 open: %B" Fun.id in
142-
Db.Host.set_https_only ~__context ~self:host ~value:network_state
143-
with _ ->
144-
Helpers.internal_error
145-
"unexpected output from /etc/xapi.d/plugins/firewall-port: %s"
146-
script_output
142+
let enabled = F.is_firewall_service_enabled ~service:Firewall.Http in
143+
Db.Host.set_https_only ~__context ~self:host ~value:(not enabled)
147144
(*************** update database tools ******************)
148145

149146
(** Record host memory properties in database *)

ocaml/xapi/xapi_host.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,13 +3116,17 @@ let cc_prep () =
31163116
true
31173117

31183118
let set_https_only ~__context ~self ~value =
3119-
let state = match value with true -> "close" | false -> "open" in
31203119
match cc_prep () with
31213120
| false ->
3122-
ignore
3123-
@@ Helpers.call_script
3124-
!Xapi_globs.firewall_port_config_script
3125-
[state; "80"] ;
3121+
let status =
3122+
match value with true -> Firewall.Disabled | false -> Firewall.Enabled
3123+
in
3124+
let module F =
3125+
( val Firewall.firewall_provider !Xapi_globs.firewall_backend
3126+
: Firewall.FIREWALL
3127+
)
3128+
in
3129+
F.update_firewall_status ~service:Firewall.Http ~status ;
31263130
Db.Host.set_https_only ~__context ~self ~value
31273131
| true when value = Db.Host.get_https_only ~__context ~self ->
31283132
(* the new value is the same as the old value *)

0 commit comments

Comments
 (0)