What globals_server keywords does Squiz populate?


(Douglas (@finnatic at @waikato)) #1

In https://matrix.squiz.net/manuals/keyword-replacements/chapters/global-keywords the manual says:

A PHP server variable where <variable> is the PHP session variable that you want to return server information from (ref: PHP $_SERVER Manual).

For example, the global keyword replacement %globals_server_http_user_agent% will return the header of the current request (e.g. Mozilla/4.5 [en] (X11; U;Linux 2.2.9 i586 ) ). Please note that the server information available will vary depending on the setup of your web server.

We have a couple of variables populated by the HTTP authentication method we use locally (Shibboleth with ADFS as an IDP) - and I can’t get them to display through use of globals_server_ keywords.

Is there a list somewhere that anyone has? Is there a script in particular I should look at?


(John gill) #2

core/include/general.inc is what you’re looking for.

By my read it should be able to lookup anything in $_SERVER with the exception HTTP_COOKIE, but I’m not about to win any PHP competitions so don’t put too much stock in that.

Maybe code somewhere else is sanitising $_SERVER before it gets to the keyword substitution.


(Chiranjivi Upreti) #3

This is the line where Matrix sets the value for the %gobals_server_*% keyword:
https://github.com/squizlabs/Matrix/blob/5dcd40abca29a108fde3d59974ddb4393d6653fb/core/include/general.inc#L3054

if (0 === strpos($keyword, 'globals_server_')) {
					$sub_keyword = strtoupper(substr($keyword, 15));
					if($sub_keyword !== 'HTTP_COOKIE') {
						$replacements[$full_keyword] = array_get_index($_SERVER, $sub_keyword, '');
						if (!is_scalar($replacements[$full_keyword])) {
							$replacements[$full_keyword] = '';
						}
					}
				}

Looking at the code apparently Matrix filters out the $_SERVER vars that has non-scalar value, and (as pointed by JohnGill above) “HTTP_COOKIE” var value.

If the server var you are trying get is populated with a non-scalar value, then that would explain why it is coming out as empty in %globals_server_*% output.

Though I am not sure why Matrix filters out non-scalar values for this specific global keyword.

This keyword was added way back in the time when Matrix keyword replacement didn’t supported array replacements, so I guessing that is why we have this non-scalar filter check there.


(Douglas (@finnatic at @waikato)) #4

Thanks for that pointer Chiranjivi.

I’ve pulled that code out to a test script and have identified both shibboleth set global variables are scalar, and both can be found in $_SERVER using copies of the code.

Looking further at the Matrix source, I also noticed the show / hide server variables option that are output alongside the HTTP Authentication Variable setting in System Config.

All my missing globals_server keywords (adgroup, upn, username), set by the shibboleth setup on the server are listed in that display… so they’re available when Matrix renders the admin interface, but not when Squiz renders a standard page with the matching globals_server keyword or when viewing that standard page in Edit+ preview mode.

I’m inclined to consult our Shibboleth experts, but if there’s anything anyone can point out about the differences between _admin and the standard Matrix rendering engine that could be useful.