I think the important point here is that header.pl is designed for the normal IPFire Web interface, which is accessed through HTTPS on port 444.
// config/cfgroot/header.pl
98: ### Make sure this is an SSL request
99: if ($ENV{'SERVER_ADDR'} && $ENV{'HTTPS'} ne 'on') {
100: print "Status: 302 Moved\r\n";
101: print "Location: https://$ENV{'SERVER_ADDR'}:444/$ENV{'PATH_INFO'}\r\n\r\n";
102: exit 0;
103: }
104:
The HTTPS check in header.pl therefore makes sense for the regular CGI pages: if they are accessed over HTTP, they are redirected to port 444.
However, captive/index.cgi is not a normal Web UI page. It is served by the captive portal on port 1013, and html/redirect.cgi is served on port 81.
Therefore, the HTTPS redirection in header.pl cannot simply be applied to these pages. Including header.pl in captive/index.cgi triggers that redirect and prevents the captive portal page from being displayed.
This is why I had to remove the header.pl include and keep a local copy of escape() as a workaround.
I agree that duplicating the function is not the cleanest solution. But the underlying issue is that header.pl contains code that is specific to the port 444 Web interface and is not suitable for the captive portal.