Skip to content

Commit

Permalink
Merge pull request #2947 from aleksandrychev/ENT-12151/master
Browse files Browse the repository at this point in the history
ENT-12151: Added possibility to configure Mission Portal web server ports
  • Loading branch information
craigcomstock authored Nov 4, 2024
2 parents 0022069 + 58de119 commit bbec246
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
47 changes: 47 additions & 0 deletions cfe_internal/enterprise/CFE_hub_specific.cf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ bundle common cfe_internal_hub_vars

policy_server::

"http_port" -> { "ENT-12151" }
string => ifelse( isvariable("cfe_internal_hub_vars.http_port"), "$(cfe_internal_hub_vars.http_port)", "80" ),
comment => "Mission portal's webserver HTTP port. Default 80";

"https_port" -> { "ENT-12151" }
string => ifelse( isvariable("cfe_internal_hub_vars.https_port"), "$(cfe_internal_hub_vars.https_port)", "443" ),
comment => "Mission portal's webserver HTTPS port. Default 443";

"docroot" string => "$(sys.workdir)/httpd/htdocs",
comment => "Root directory of Enterprise Web interface",
handle => "cfe_internal_hub_vars_docroot";
Expand Down Expand Up @@ -91,6 +99,45 @@ bundle common cfe_internal_hub_vars

}

##################################################################
#
# update_cli_rest_server_url_config
# - updates REST server URL port of Mission Portal WebGUI when
# cfe_internal_hub_vars.https_port is changed
#
##################################################################
bundle agent update_cli_rest_server_url_config
{
vars:
# Both share and live versions must be changed at once since httpd will be restarted later in the same agent run.
"mp_config_file" string => "$(cfe_internal_hub_vars.docroot)/application/config/config.php";
"mp_share_config_file" string => "$(sys.workdir)/share/GUI/application/config/config.php";
"regex_test_pattern" string => ".*localhost:$(cfe_internal_hub_vars.https_port).*";

files:
"$(mp_share_config_file)"
edit_line => change_cli_rest_server_url_port,
if => and(
fileexists("$(mp_share_config_file)"),
islessthan(countlinesmatching("$(regex_test_pattern)", "$(mp_share_config_file)"), 1)
);

"$(mp_config_file)"
edit_line => change_cli_rest_server_url_port,
if => and(
fileexists("$(mp_config_file)"),
islessthan(countlinesmatching("$(regex_test_pattern)", "$(mp_config_file)"), 1)
);
}

bundle edit_line change_cli_rest_server_url_port
{
replace_patterns:
"^\s*\$config\['cli_rest_server_url'\]\s*=\s*\"https://localhost(?::(?!$(cfe_internal_hub_vars.https_port))\d{1,5})?/api/\";\s*$"
replace_with => value(" $config['cli_rest_server_url'] = \"https://localhost:$(cfe_internal_hub_vars.https_port)/api/\";"),
comment => "Change port CLI REST server URL port";
}

##################################################################
#
# cfe_internal_update_folders
Expand Down
5 changes: 5 additions & 0 deletions cfe_internal/enterprise/mission_portal.cf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ bundle agent cfe_internal_enterprise_mission_portal
handle => "cfe_internal_management_web_server",
comment => "Manage Apache Web server (on/off)";

"Port Configuration" -> { "CFEngine Enterprise", "Mission Portal" }
usebundle => update_cli_rest_server_url_config,
handle => "cfe_internal_management_update_cli_rest_server_url_config",
comment => "Update the REST server URL port in the Mission Portal when cfe_internal_hub_vars.https_port is changed";

}
bundle agent apachectl_patched_for_upgrade
# @brief Ensure that apacehctl is patched so that it is able to re-start services
Expand Down
8 changes: 4 additions & 4 deletions cfe_internal/enterprise/templates/httpd.conf.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ServerRoot "{{{vars.sys.workdir}}}/httpd"
# ENT-10646 - Listen 80 often causes IPv6 related errors, specifying ipv4 squashes them.
# Unclear why the same is not an issue for 443
# To enable listening on ipv6 add Listen [::]:80
Listen 0.0.0.0:80
Listen 0.0.0.0:{{{vars.cfe_internal_hub_vars.http_port}}}
{{/classes.cfe_enterprise_disable_plain_http}}

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

Listen 443
Listen {{{vars.cfe_internal_hub_vars.https_port}}}

AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
Expand Down Expand Up @@ -183,12 +183,12 @@ LogLevel warn
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

<VirtualHost _default_:443>
<VirtualHost _default_:{{{vars.cfe_internal_hub_vars.https_port}}}>
DocumentRoot "{{{vars.cfe_internal_hub_vars.public_docroot}}}"
Alias "/api" "{{{vars.cfe_internal_hub_vars.docroot}}}/api"
Alias "/api/static" "{{{vars.cfe_internal_hub_vars.docroot}}}/api/static"
Alias "/ldap" "{{{vars.cfe_internal_hub_vars.docroot}}}/ldap"
ServerName {{{vars.sys.fqhost}}}:443
ServerName {{{vars.sys.fqhost}}}:{{{vars.cfe_internal_hub_vars.https_port}}}
# ServerAdmin root@localhost
ErrorLog "{{{vars.cfe_internal_hub_vars.error_log}}}"
LogFormat "%h %l %{username}n %t \"%r\" %>s %b"
Expand Down

0 comments on commit bbec246

Please sign in to comment.