logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in  RSS Apache Lounge  


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.


Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: How to pass apache variable to external auth.php?
Author
rossbcan



Joined: 15 Aug 2018
Posts: 8

PostPosted: Sun 14 Mar '21 16:24    Post subject: How to pass apache variable to external auth.php? Reply with quote

Is seems possible to set environmental variables in a location block which are visible in php.

My external authentication (php) sees these variables:
print_r($_SERVER)
Quote:

Array
(
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[AUTHTYPE] => PASS
[IP] => 192.168.2.1
[URI] => /Downloads/SecureOffice/r13710/packages_x86_64/Packages.gz
[HTTP_HOST] => redacted.org
[PHP_SELF] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[SCRIPT_NAME] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[SCRIPT_FILENAME] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[PATH_TRANSLATED] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
[DOCUMENT_ROOT] =>
[REQUEST_TIME_FLOAT] => 1615730112.1554
[REQUEST_TIME] => 1615730112
[argv] => Array
(
[0] => /home/e-smith/files/ibays/rossco/license_server/download_auth.php
)

[argc] => 1
)


In my authentication location block, I have this:
"RequestHeader set HTTP_X_FORWARDED_FOR %{HTTP_X_FORWARDED_FOR}e\n";"

...which does not show up as [HTTP_X_FORWARDED_FOR] in php

Q - how do I get fpm variable HTTP_X_FORWARDED_FOR in my php authenticator?
Back to top
tangent



Joined: 16 Aug 2020
Posts: 80
Location: UK

PostPosted: Mon 15 Mar '21 15:54    Post subject: Re: How to pass apache variable to external auth.php? Reply with quote

In your configuration code:
rossbcan wrote:
RequestHeader set HTTP_X_FORWARDED_FOR %{HTTP_X_FORWARDED_FOR}e

you are setting a request header based on the current value of an Apache variable, whereas your question is the other way round. You're wishing to set an Apache variable, based on a request header, to be picked up by your PHP code.

So try the following instead:
Code:
SetEnvIf HTTP-X-Forwarded-For ^(.+)$ HTTP_X_Forwarded_For=$1

Make sure you enable the SetEnvIf module, and note its context is server config, virtual host, directory, and .htaccess - not a location block. I'd put it at the global server level myself.
Back to top
rossbcan



Joined: 15 Aug 2018
Posts: 8

PostPosted: Fri 19 Mar '21 16:06    Post subject: Reply with quote

Thanks tangent;

It seems the issue is that mod_remoteip provides a very sparse list of variables:

https://stackoverflow.com/questions/39022519/ssl-environment-variables-during-external-authorization

...which excludes any useful request headers, so it is pointless to set them.

So; mod_rpaf is the way to go:

https://www.apachelounge.com/viewtopic.php?t=8647

Regards;
Bill
Back to top


Reply to topic   Topic: How to pass apache variable to external auth.php? View previous topic :: View next topic
Post new topic   Forum Index -> Apache