Skip to content

Commit 2e1385b

Browse files
CP-40754 The firewall-port script returns true if port 80 is blocked and false if it is closed, this is captured in set_https_only to update the DB based on the tate of the network not the requested setting should there be a failure
Signed-off-by: jameshensmancitrix <james.hensman@citrix.com>
1 parent 0ac90b0 commit 2e1385b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ocaml/xapi/dbsync_slave.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,20 @@ let refresh_localhost_info ~__context info =
122122
~key:Xapi_globs.host_no_local_storage ~value:"true"
123123
) else
124124
Db.Host.remove_from_other_config ~__context ~self:host
125-
~key:Xapi_globs.host_no_local_storage
126-
125+
~key:Xapi_globs.host_no_local_storage ;
126+
let script_output =
127+
Helpers.call_script !Xapi_globs.firewall_port_config_script ["check"; "80"]
128+
in
129+
try
130+
let network_state = Scanf.sscanf script_output "Port 80 open: %B" Fun.id in
131+
Db.Host.set_https_only ~__context ~self:host ~value:network_state
132+
with _ ->
133+
let message =
134+
Printf.sprintf
135+
"unexpected output from /etc/xapi.d/plugins/firewall-port: %s"
136+
script_output
137+
in
138+
raise Api_errors.(Server_error (internal_error, [message]))
127139
(*************** update database tools ******************)
128140

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

scripts/plugins/firewall-port

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ case "${OP}" in
4747
service iptables save
4848
fi
4949
;;
50+
check)
51+
if [[ -z `iptables -S $CHAIN | grep " $PORT "` ]]
52+
then
53+
echo "Port $PORT open: true"
54+
else
55+
echo "Port $PORT open: false"
56+
fi
57+
;;
5058
*)
51-
echo $"Usage: $0 {open|close} {port} {protocol}" 1>&2
59+
echo $"Usage: $0 {open|close|check} {port} {protocol}" 1>&2
5260
exit 1
5361
;;
5462
esac
63+
5564
exit 0
5665

0 commit comments

Comments
 (0)