{
    # vim: ft=perl:

    $haveSSL = (exists ${modSSL}{status} and ${modSSL}{status} eq "enabled") ?  'yes' : 'no';
    $plainTextAccess = ${'httpd-admin'}{PermitPlainTextAccess} || 'no';
    $adminPort2 = ${'smanager'}{TCPPort} || '982';
    $adminAccess = ${'smanager'}{access} || 'private';

    $OUT = '';

    foreach $place ('smanager')
    {
        if (($port eq $httpPort) && ($haveSSL eq 'yes') && ($plainTextAccess ne 'yes'))
        {
            $OUT .= '    RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$' . "\n";
            $OUT .= "    RewriteRule ^/$place(/.*|\$)    https://%{HTTP_HOST}/$place\$1 [L,R]\n";
            $OUT .= "\n";
        }
        $OUT .= "    RewriteRule ^/$place\$   https://%{HTTP_HOST}/$place/ [L,R]\n\n";

        $OUT .= "    ProxyRequests Off\n";
        $OUT .= "    ProxyPreserveHost On\n";
        $OUT .= "    ProxyPass /$place http://127.0.0.1:$adminPort2 keepalive=On\n";
        $OUT .= "    ProxyPassReverse /$place http://127.0.0.1:$adminPort2\n";
        if ($port eq $httpsPort)
        {
            # mod_auth_tkt needs to know the protocol to write  307 redirection
            $OUT .= "    RequestHeader set X-Forwarded-Proto \"https\"\n";
        }

        $OUT .= "    <Location '/$place'>\n";
        if ($port eq $httpPort)
        {
            $OUT .= '        Require ip 127.0.0.1' . "\n";
        }
        elsif (($haveSSL eq 'yes') && ($port eq $httpsPort) && ($adminAccess eq 'public'))
        {
            $OUT .= "#       public access requested in conf db\n";
            $OUT .= "        Require all granted\n";
        } else {
            $OUT .= "#       private access by default\n";
            $OUT .= "        Require ip $localAccess $externalSSLAccess\n";
        }

		# CSP header - re-instate formatted structure       
        $OUT .= qq{        Header always set Content-Security-Policy "}
              . " script-src 'self' 'unsafe-eval' 'unsafe-hashes' "
              . " 'sha256-T5nv1LP9Xxdv7I1tsdTYprjvwoZyVEvfe8Y4TLx59pk=' "  # tognav
              . " 'sha256-TxVHbw3t1mXreukND/yBI+H+CscZDpyxPoNoBrRhmSE=' "  # swapClass
              . " 'sha256-30Xxu25YbRvjbQ2ngJ8EyneSz0No788PqjM9XbQh+qM=' "  # togglePassword...
              . " ; "
              . " style-src 'self' 'unsafe-hashes' ;"
              . qq{"\n};
                                          
        $OUT .= "    </Location>\n";
        $OUT .= "   <LocationMatch \"/$place/.+\.(html|cgi)\$\">\n";
        $OUT .= "                   Header set Cache-Control no-store\n";
        $OUT .= "   </LocationMatch>\n";
    }
    return $OUT;
}
