Forum

Setenv not working for error handlers?

Marius Dinu
20 September 2015, 09:34
Hi,
I'm trying to write a script that will output a directory index, as suggested in the other topic. The problem is that I have some aliases. Finding the filesystem paths for those is difficult. True paths are not passed to CGI, only virtual addresses. So I tried sending those paths from hiawatha.conf as environment variables. This didn't work. I don't know if this is a bug or intentional.

hiawatha.conf (relevant parts):
VirtualHost{
WebsiteRoot = /http/1-0
Alias = /guest:/http/1-1
TriggerOnCGIstatus = yes
ErrorHandler = 404:/DirIndex.php
[...]
}

Directory{
Path = /http/1-1
Setenv ShowIndex=yes
Setenv AliasDocRoot=/http/1-1
[...]
}


DirIndex.php
var_dump(get_defined_vars());

Opening http://myserver/guest/ or http://myserver/guest/some-subdir/
does not list AliasDocRoot and ShowIndex variables.
Hugo Leisink
21 September 2015, 20:42
Although the manual page shows otherwise and Hiawatha accepts it, SetEnv in a Directory section is not supported. It looks like a left-over from an experiment, but I forgot to remove it completely. Move the Setenv options to the VirtualHost section.

Another thing you can do is let the CGI script parse your hiawatha.conf file to search for aliases.
Marius Dinu
22 September 2015, 11:41
I wanted to send to the script the true filesystem path of the dir. Sentenv in VirtualHost section will not help me. It would be applied to all dirs, aliased or not, and the path will always be the same.
Allowing cgi access to /etc is also a thing I would like to avoid.

I'll include all aliases in the script and keep it updated manually. I'll write a feature request, too.

Thank you!
Hugo Leisink
22 September 2015, 11:45
Setenv in VirtualHost section can help, if you organize them right.
VirtualHost {
WebsiteRoot = /http/1-0
Alias = /guest:/http/1-1
Setenv Alias_guest = /http/1-1
...
}

Parse any environment variable that starts with Alias_, strip the leading 'Alias' from it and replace any underscore with a slash.
Marius Dinu
22 September 2015, 14:24
Thanks.
This topic has been closed.