Skip to content

Commit bbec246

Browse files
Merge pull request #2947 from aleksandrychev/ENT-12151/master
ENT-12151: Added possibility to configure Mission Portal web server ports
2 parents 0022069 + 58de119 commit bbec246

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

cfe_internal/enterprise/CFE_hub_specific.cf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ bundle common cfe_internal_hub_vars
4040

4141
policy_server::
4242

43+
"http_port" -> { "ENT-12151" }
44+
string => ifelse( isvariable("cfe_internal_hub_vars.http_port"), "$(cfe_internal_hub_vars.http_port)", "80" ),
45+
comment => "Mission portal's webserver HTTP port. Default 80";
46+
47+
"https_port" -> { "ENT-12151" }
48+
string => ifelse( isvariable("cfe_internal_hub_vars.https_port"), "$(cfe_internal_hub_vars.https_port)", "443" ),
49+
comment => "Mission portal's webserver HTTPS port. Default 443";
50+
4351
"docroot" string => "$(sys.workdir)/httpd/htdocs",
4452
comment => "Root directory of Enterprise Web interface",
4553
handle => "cfe_internal_hub_vars_docroot";
@@ -91,6 +99,45 @@ bundle common cfe_internal_hub_vars
9199

92100
}
93101

102+
##################################################################
103+
#
104+
# update_cli_rest_server_url_config
105+
# - updates REST server URL port of Mission Portal WebGUI when
106+
# cfe_internal_hub_vars.https_port is changed
107+
#
108+
##################################################################
109+
bundle agent update_cli_rest_server_url_config
110+
{
111+
vars:
112+
# Both share and live versions must be changed at once since httpd will be restarted later in the same agent run.
113+
"mp_config_file" string => "$(cfe_internal_hub_vars.docroot)/application/config/config.php";
114+
"mp_share_config_file" string => "$(sys.workdir)/share/GUI/application/config/config.php";
115+
"regex_test_pattern" string => ".*localhost:$(cfe_internal_hub_vars.https_port).*";
116+
117+
files:
118+
"$(mp_share_config_file)"
119+
edit_line => change_cli_rest_server_url_port,
120+
if => and(
121+
fileexists("$(mp_share_config_file)"),
122+
islessthan(countlinesmatching("$(regex_test_pattern)", "$(mp_share_config_file)"), 1)
123+
);
124+
125+
"$(mp_config_file)"
126+
edit_line => change_cli_rest_server_url_port,
127+
if => and(
128+
fileexists("$(mp_config_file)"),
129+
islessthan(countlinesmatching("$(regex_test_pattern)", "$(mp_config_file)"), 1)
130+
);
131+
}
132+
133+
bundle edit_line change_cli_rest_server_url_port
134+
{
135+
replace_patterns:
136+
"^\s*\$config\['cli_rest_server_url'\]\s*=\s*\"https://localhost(?::(?!$(cfe_internal_hub_vars.https_port))\d{1,5})?/api/\";\s*$"
137+
replace_with => value(" $config['cli_rest_server_url'] = \"https://localhost:$(cfe_internal_hub_vars.https_port)/api/\";"),
138+
comment => "Change port CLI REST server URL port";
139+
}
140+
94141
##################################################################
95142
#
96143
# cfe_internal_update_folders

cfe_internal/enterprise/mission_portal.cf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ bundle agent cfe_internal_enterprise_mission_portal
1515
handle => "cfe_internal_management_web_server",
1616
comment => "Manage Apache Web server (on/off)";
1717

18+
"Port Configuration" -> { "CFEngine Enterprise", "Mission Portal" }
19+
usebundle => update_cli_rest_server_url_config,
20+
handle => "cfe_internal_management_update_cli_rest_server_url_config",
21+
comment => "Update the REST server URL port in the Mission Portal when cfe_internal_hub_vars.https_port is changed";
22+
1823
}
1924
bundle agent apachectl_patched_for_upgrade
2025
# @brief Ensure that apacehctl is patched so that it is able to re-start services

cfe_internal/enterprise/templates/httpd.conf.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ServerRoot "{{{vars.sys.workdir}}}/httpd"
1010
# ENT-10646 - Listen 80 often causes IPv6 related errors, specifying ipv4 squashes them.
1111
# Unclear why the same is not an issue for 443
1212
# To enable listening on ipv6 add Listen [::]:80
13-
Listen 0.0.0.0:80
13+
Listen 0.0.0.0:{{{vars.cfe_internal_hub_vars.http_port}}}
1414
{{/classes.cfe_enterprise_disable_plain_http}}
1515

1616
PidFile "{{{vars.mission_portal_apache_from_stage.httpd_pid_file}}}"
@@ -135,7 +135,7 @@ LogLevel warn
135135
# This content used to be included from an external file
136136
# /var/cfengine/httpd/conf/extra/httpd-ssl.conf
137137

138-
Listen 443
138+
Listen {{{vars.cfe_internal_hub_vars.https_port}}}
139139

140140
AddType application/x-x509-ca-cert .crt
141141
AddType application/x-pkcs7-crl .crl
@@ -183,12 +183,12 @@ LogLevel warn
183183
SSLRandomSeed startup builtin
184184
SSLRandomSeed connect builtin
185185

186-
<VirtualHost _default_:443>
186+
<VirtualHost _default_:{{{vars.cfe_internal_hub_vars.https_port}}}>
187187
DocumentRoot "{{{vars.cfe_internal_hub_vars.public_docroot}}}"
188188
Alias "/api" "{{{vars.cfe_internal_hub_vars.docroot}}}/api"
189189
Alias "/api/static" "{{{vars.cfe_internal_hub_vars.docroot}}}/api/static"
190190
Alias "/ldap" "{{{vars.cfe_internal_hub_vars.docroot}}}/ldap"
191-
ServerName {{{vars.sys.fqhost}}}:443
191+
ServerName {{{vars.sys.fqhost}}}:{{{vars.cfe_internal_hub_vars.https_port}}}
192192
# ServerAdmin root@localhost
193193
ErrorLog "{{{vars.cfe_internal_hub_vars.error_log}}}"
194194
LogFormat "%h %l %{username}n %t \"%r\" %>s %b"

0 commit comments

Comments
 (0)