shithub: werc

Download patch

ref: 1b1c4d39147771fb55b0c362ef231028461e3a82
parent: 936474fa205627a7ef7a2350c470ca670f03cf08
parent: eafc5b1bbbde364c1abeb48e3cafbdf409a8931c
author: sl <[email protected]>
date: Sun Apr 19 11:23:15 EDT 2009

Merge

--- a/.hgtags
+++ b/.hgtags
@@ -31,3 +31,5 @@
 bd4f06765424900ed3e897967917187c7450108d LATEST-RELEASE
 381fb71e8445b4659ff27811df6ffe2661ed7656 1.0.0-rc1
 0164a4b8c410abd369bd7e42a9a4f70c2e21b97b LATEST-RELEASE
+dd1b3d521ca78bb3a891c9161bb5f82289aaa98b 1.0.0-rc2
+b45ddd3941d923c32b4cbdb96c298323e19ff053 LATEST-RELEASE
--- a/apps/blagh/app.rc
+++ b/apps/blagh/app.rc
@@ -35,10 +35,10 @@
 <link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />'
         }
         if not if(~ $req_path $blagh_uri^index.atom)
-            blagh_setup_feed_handlers atom.tpl
+            blagh_setup_feed_handlers atom.tpl 'application/atom+xml'
 
         if not if(~ $req_path $blagh_uri^index.rss)
-            blagh_setup_feed_handlers rss20.tpl
+            blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8'
 
         if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0) {
             handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} )
@@ -56,6 +56,7 @@
 fn blagh_setup_feed_handlers {
     handler_body_main=NOT_USED_by_blagh_feeds
     res_tail=()
+    http_content_type=$2
     headers=()
     master_template=apps/blagh/$1 # Should we allow tempalte override?
 }
--- a/apps/blagh/atom.tpl
+++ b/apps/blagh/atom.tpl
@@ -1,5 +1,3 @@
-Content-Type: application/atom+xml
-
 <?xml version="1.0" encoding="utf-8"?>
 
 %{
--- a/apps/blagh/rss20.tpl
+++ b/apps/blagh/rss20.tpl
@@ -1,5 +1,3 @@
-Content-Type: text/xml; charset=utf-8
-
 <?xml version="1.0" encoding="UTF-8"?>
 
 %{
--- a/apps/dirdir/app.rc
+++ b/apps/dirdir/app.rc
@@ -8,32 +8,15 @@
     if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups) {
         dirdir_file=$local_path.md
         dirdir_dir=$dirdir_file^'_werc/dirdir/'
-            
-        if(test -f $local_path.md) {
-            if(~ $#post_arg_dirdir_save 1 && ! ~ $"post_arg_edit_text '')
-                save_page
+ 
+        if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview)
+            handler_body_main=(tpl_handler `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl})
 
-            if not if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview)
-                handler_body_main=(tpl_handler \
-                    `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl})
-
-            if not if(! ~ $REQUEST_METHOD POST)
-                ll_add handlers_bar_left tpl_handler \
-                    apps/dirdir/sidebar_controls.tpl
-        }
-
-        if not if(~ 1 $#post_arg_dirdir_edit)
-            handler_body_main=(tpl_handler \
-                `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl})
-
-        if not if(~ 1 $#post_arg_dirdir_save) {
-            mkdir -p `{basename -d $local_path}
+        if not if(! ~ '' $"post_arg_dirdir_save $"post_arg_edit_text)
             save_page
-        }
-        if not if(~ $"handler_body_main  '')
-            ll_add handlers_bar_left tpl_handler \
-                apps/dirdir/sidebar_controls.tpl
 
+        if not if(~ $"handler_body_main  '' || {~ $REQUEST_METHOD GET && test -f $local_path.md})
+            ll_add handlers_bar_left tpl_handler apps/dirdir/sidebar_controls.tpl
     }
 }
 
--- a/bin/cgilib.rc
+++ b/bin/cgilib.rc
@@ -157,6 +157,13 @@
     $_l=$*(2-)
     $1=( $$1 $_l )
 }
+# Add to the head: dangerous if you shrink list by hand!
+fn ll_addh {
+    _l=$1^_^$#$1
+    $_l=$*(2-)
+    $1=( $_l $$1 )
+}
+
 
 NEW_LINE='
 '
--- a/bin/werc.rc
+++ b/bin/werc.rc
@@ -19,6 +19,7 @@
 
 headers=lib/headers.tpl
 res_tail='</body></html>'
+http_content_type='text/html'
 ll_add handlers_bar_left nav_tree
 werc_apps=( apps/* )
 werc_root=`{pwd}
@@ -88,20 +89,16 @@
 
     if(~ $#perm_redir_to 1)
         perm_redirect $perm_redir_to
-    p=();
-    for(i in $perm_redir_patterns) {
-        if(~ $#p 0)
-            p=$i
-        if not {
-            # If target is absolute, require patern matches whole string
-            if(~ $i http://* https://)
-                p='^'$p 
-            t=`{ echo $req_path | sed 's!'$p'!'$i'!' }
+    for(l in $perm_redir_patterns) {
+        p=$$l
+        r=$p(1)
+        # If target is absolute, then patern must match whole string
+        if(~ $p(2) http://* https://)
+            r='^'$r 
+        t=`{ echo $req_path | sed 's!'^$r^'!'^$p(2)^'!' } # Malicious danger!
 
-            if(! ~ $"t '' && ! ~ $t $req_path)
-                perm_redirect $t
-            p=() 
-        } 
+        if(! ~ $"t '' $req_path)
+            perm_redirect $t
     }
 
     # Set Page title
@@ -112,9 +109,17 @@
 
     setup_handlers
 
+    for(h in $extraHttpHeaders)
+        echo $h
+    echo 'Content-Type: '^$http_content_type
+    if(~ $REQUEST_METHOD HEAD)
+        exit
+    echo # End of HTTP headers
+
     if(! ~ $#debug 0)
         dprint $"SERVER_NAME^$"REQUEST_URI - $"HTTP_USER_AGENT - $"REQUEST_METHOD - $"handler_body_main - $"master_template
 
+    
     template $headers $master_template | awk_buffer
     echo $res_tail
 }
--- a/bin/wercconf.rc
+++ b/bin/wercconf.rc
@@ -3,7 +3,7 @@
     if(~ $#* 1)
         perm_redir_to=$1
     if not
-        perm_redir_patterns=($1 $2 $perm_redir_patterns)
+        ll_addh perm_redir_patterns $1 $2
 }
 
 fn conf_hide_paths {
--- a/bin/werclib.rc
+++ b/bin/werclib.rc
@@ -14,6 +14,7 @@
 fn template { awk -f bin/template.awk $* | rc $rcargs }
 
 # Auth code
+# TODO: check http://cookies.lcs.mit.edu/pubs/webauth:tr.pdf
 allowed_user_chars='[a-zA-Z0-9_]'
 # Cookie format: WERC_USER: name:timestamp:hash(name.timestamp.password)
 # login_user can't be used from a template because it sets a cookie 
--- a/lib/default_master.tpl
+++ b/lib/default_master.tpl
@@ -1,4 +1,3 @@
-
 <div id="header">
     <div class="superHeader">
 % cat `{ get_lib_file top_bar.inc }
--- a/lib/headers.tpl
+++ b/lib/headers.tpl
@@ -1,8 +1,3 @@
-% for(h in $extraHttpHeaders) echo $h
-Content-Type: text/html
-% if(~ $REQUEST_METHOD HEAD)
-%   exit
-
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -11,7 +6,13 @@
 
     <title>%($pageTitle%)</title>
 
+    <link rel="stylesheet" href="/pub/style/style.css" type="text/css" media="screen, handheld" title="default" />
+    <link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
+% if(test -f $sitedir/_werc/pub/style.css)
+%    echo '    <link rel="stylesheet" href="/_werc/pub/style.css" type="text/css" media="screen" title="default" />'
+
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
     <meta name="author" content="k" />
 
 % if(! ~ $#meta_description 0)
@@ -18,11 +19,6 @@
 %   echo '    <meta name="description" content="'$"meta_description'" />'
 % if(! ~ $#meta_keywords 0)
 %   echo '    <meta name="keywords" content="'$"meta_keywords'" />'
-
-    <link rel="stylesheet" href="/pub/style/style.css" type="text/css" media="screen, handheld" title="default" />
-    <link rel="shortcut icon" href="/favicon.ico" type="image/vnd.microsoft.icon" />
-% if(test -f $sitedir/_werc/pub/style.css)
-%    echo '    <link rel="stylesheet" href="/_werc/pub/style.css" type="text/css" media="screen" title="default" />'
 
 % h = `{get_lib_file headers.inc}
 % if(! ~ $#h 0)