From b6c0f2feadcd951e806350e5d6a59d8d81497bff Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 12 Dec 2013 09:17:06 -0500 Subject: [PATCH] web staff : dynamic apache index delivery Generic apache config wasn't working, since different apps create arbitrarily nested URL parameters, which means each app would need its own Apache rewrite configuration to sort them all out. This creates a new OILSWebStopAtIndex EGWeb.pm option which tells the code to check for the presence of an index file at the current directory as it's looking up the directory tree for the requested template. Example w/ stop-at-index enabled. The code will look for these templates in this order: URL -> /eg/staff/circ/patron/142/holds 1. staff/circ/patron/142/holds.tt2 2. staff/circ/patron/142/index.tt2 3. staff/circ/patron/142.tt2 4. staff/circ/patron/index.tt2 -- file exists, all done. Signed-off-by: Bill Erickson --- Open-ILS/examples/apache/eg_vhost.conf.in | 6 +----- Open-ILS/examples/apache_24/eg_vhost.conf.in | 6 +----- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Open-ILS/examples/apache/eg_vhost.conf.in b/Open-ILS/examples/apache/eg_vhost.conf.in index 32ebd26b02..5305d0b7cf 100644 --- a/Open-ILS/examples/apache/eg_vhost.conf.in +++ b/Open-ILS/examples/apache/eg_vhost.conf.in @@ -789,17 +789,13 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] Options -MultiViews + PerlSetVar OILSWebStopAtIndex "true" # map /eg/staff to /eg/staff/index RewriteEngine On RewriteCond %{PATH_INFO} =/staff/ RewriteRule (.*) /eg/staff/index [L,DPI] - # map /eg/staff/foo/bar to /eg/staff/foo/index - RewriteEngine On - RewriteCond %{PATH_INFO} !.*/(index|css|t_*) - RewriteRule (.*)/[^\/]+$ $1/index [L,DPI] - Header append Cache-Control "public" diff --git a/Open-ILS/examples/apache_24/eg_vhost.conf.in b/Open-ILS/examples/apache_24/eg_vhost.conf.in index 1f90e8496e..dfdeb550d0 100644 --- a/Open-ILS/examples/apache_24/eg_vhost.conf.in +++ b/Open-ILS/examples/apache_24/eg_vhost.conf.in @@ -801,17 +801,13 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] Options -MultiViews + PerlSetVar OILSWebStopAtIndex "true" # map /eg/staff to /eg/staff/index RewriteEngine On RewriteCond %{PATH_INFO} =/staff/ RewriteRule (.*) /eg/staff/index [L,DPI] - # map /eg/staff/foo/bar to /eg/staff/foo/index - RewriteEngine On - RewriteCond %{PATH_INFO} !.*/(index|css|t_*) - RewriteRule (.*)/[^\/]+$ $1/index [L,DPI] - Header append Cache-Control "public" diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 2e557db87a..4d00a3f293 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -235,6 +235,7 @@ sub find_template { my $page_args = []; my $as_xml = $r->dir_config('OILSWebForceValidXML'); my $ext = $r->dir_config('OILSWebDefaultTemplateExtension'); + my $at_index = $r->dir_config('OILSWebStopAtIndex'); my @parts = split('/', $path); my $localpath = $path; @@ -253,9 +254,27 @@ sub find_template { if(-r $fpath) { $template = "$localpath.$ext"; last; + } + } + last if $template; + + if ($at_index) { + # no matching template was found in the current directory. + # stop-at-index requested; see if there is an index.ext + # file in the same directory instead. + for my $tpath (@{$ctx->{template_paths}}) { + # replace the final path component with 'index' + $localpath =~ s|/[^/]+$|/index|; + my $fpath = "$tpath/$localpath.$ext"; + $r->log->debug("egweb: looking at possible template $fpath"); + if (-r $fpath) { + $template = "$localpath.$ext"; + last; + } } } last if $template; + push(@args, pop @parts); $localpath = join('/', @parts); } -- 2.11.0