swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit b122fe90ce1b56809974d252ebd76e0654d46259
parent 6ab05161d241a2d74e7da866135d39f89cdce6b6
Author: uriel@soma <unknown>
Date:   Tue,  3 Mar 2009 13:15:46 +0000

Further cleanup and simplification of redirect code.
Diffstat:
Mbin/cgilib.rc | 2+-
Mbin/werc.rc | 22++++++++++++----------
Mbin/wercconf.rc | 6++----
3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/bin/cgilib.rc b/bin/cgilib.rc @@ -6,7 +6,7 @@ fn dprintv { { for(v in $*) { echo -n $v^'#'^$#$v^'=' $$v '; ' }; echo } >[1=2] fn escape_html { sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' $* } fn http_redirect { - if(~ $1 http:* https:*) + if(~ $1 http://* https://*) t=$1 if not if(~ $1 /*) t=$"base_url^$1 diff --git a/bin/werc.rc b/bin/werc.rc @@ -40,6 +40,7 @@ fn werc_exec_request { # Note: $REQUEST_URI is not officially in CGI 1.1, but seems to be de-facto req_path=`{echo -n $REQUEST_URI | sed 's/\?.*//; s!//+!/!g; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'} + req_url=$base_url^$req_path local_path=$sitedir$req_path ifs='/' { args=`{echo -n $req_path} } @@ -85,18 +86,19 @@ fn werc_exec_request { if(~ $#perm_redir_to 1) perm_redirect $perm_redir_to - f=();t=() + p=(); for(i in $perm_redir_patterns) { - if(~ $#f 0) - f=$i + if(~ $#p 0) + p=$i if not { - t=$i - # TODO: should handle absolute and relative urls differently. - from=$base_url^$req_path - to=`{ echo $from | sed 's!'$f'!'$t'!' } - if(! ~ $to $from) - perm_redirect $to - f=() + # If target is absolute, require patern matches whole string + if(~ $i http://* https://) + p='^'$p + t=`{ echo $req_path | sed 's!'$p'!'$i'!' } + + if(! ~ $"t '' && ! ~ $t $req_path) + perm_redirect $t + p=() } } diff --git a/bin/wercconf.rc b/bin/wercconf.rc @@ -2,15 +2,13 @@ fn conf_perm_redirect { if(~ $#* 1) perm_redir_to=$1 - if not { + if not perm_redir_patterns=($perm_redir_patterns $1 $2) - conf_hide_paths $1 # XXX Will hide paths even if replacement string is the same as matched sctring. - } } fn conf_hide_paths { for(i in $*) - dirfilter=$dirfilter^'/'^`{echo $sitedir'/'$i|sed 's!/+!\\/!g'}^'/d; ' + dirfilter=$dirfilter^'/'^`{echo $sitedir$conf_wd$i|sed 's!/+!\\/!g'}^'/d; ' } # Usually will be called from within conf_enable_foo