Forum

Custom Index Page

Luc
22 July 2009, 12:34
Not just the CSS, but the whole page.

I am not content with Hiawatha's Index page. It's not just the looks, I want more functionality. I want to use, say, a CGI script that hides certain files, demands password, counts and displays the files and folders, provides statistics, logs and reports access etc.

Hiawatha lets me do that, but in a convoluted way: a .hiawatha file inside the directory specifying index.cgi as the StartFile. It's up to me to build and place the index.cgi file there. The problem is that I will have to do that to every directory. And sub directories. Each one individually. And even more if some program (a dynamic site) creates more directories.

I can have a cron job probe the whole directory structure and copy the master index.cgi template file over to every "empty" (without a StartFile) directory, but that's too much hassle. There has to be a better way.

Suggested solution: instead of the IndexStyle option, an IndexFile option, pointing to a be-all-end-all file that will act as Index file for any (without a StartFile) directory or sub directory. All I need is some environment variable like REQUEST_URI to tell me which directory the program should inspect and report/display/output.

TIA
Hugo Leisink
22 July 2009, 12:59
You can do that already. Use the UrlToolkit for it.
VirtualHost {
...
UseToolkit = show_index
}

UrlToolkit {
ToolkitID = show_index
RequestURI isfile Return
Match .* Rewrite /index.cgi
}

Let the index.cgi read the REQUEST_URI environment variable to show to requested directory content.
Luc
22 July 2009, 21:04
VirtualHost { eh? That has been a bit of a problem I am having with Hiawatha: things that only apply to virtual hosts. I have no virtual hosts when building and testing on my desktop machine, localhost. My desktop setup is only aware of directories.

[link deleted because of stupid robot]

[link deleted because of stupid robot]

In order to test your suggestion, I will have to finish the whole thing without knowing if it works then upload the site and test it online. If something isn't right, I'll have to debug and fix remotely, which is a lot slower.


Another approach: can I call that rewrite function in the overall server setup? I mean, outside of any VirtualHost section? Apparently I can, but your code (used in the overall setup) makes ALL my pages return 404. I was suspicious of your regex and tried this instead:

UrlToolkit {
ToolkitID = show_index
RequestURI isfile Return
Match ^/(.*)/?$ Rewrite /$1/index-dir.cgi
}


Now it works a little. It works in the "domains" top level, i.e. it actually replaces the true index.cgi output, e.g.:

http://localhost/domain-1.net -> displays show_index output

http://localhost/domain-1.net/index.cgi -> displays the site's content as expected

http://localhost/domain-1.net/some_folder/ -> 404

Hugo Leisink
25 July 2009, 15:30
I used this UrlToolkit:
UrlToolkit {
ToolkitID = show_index
RequestURI isfile Return
Match .* Rewrite /index.php
}


I used this PHP code to show the index:
<?php
$dir = $_SERVER["REQUEST_URI"];
if (strpos($dir, "..") !== false) {
$dir = "/";
}
$dir = $_SERVER["DOCUMENT_ROOT"].$dir;

if (($dp = @opendir($dir)) == false) {
exit("Directory ".$dir." not found");
}

print "<ul>\n";
while (($file = readdir($dp)) != false) {
print "<li><a href=\"".$file."\">".$file."</a></li>\n";
}
print "</ul>\n";

closedir($dp);
?>


It worked perfectly.
This topic has been closed.