diff --git a/apps/bridge/app.rc b/apps/bridge/app.rc index 21d8e1b..adf3caa 100644 --- a/apps/bridge/app.rc +++ b/apps/bridge/app.rc @@ -1,26 +1,35 @@ fn bridge_init { - if(! ~ $#allowComments 0 && ~ $REQUEST_METHOD POST) { - get_post_args comment_text - d=`{date -n} # FIXME Obvious race - d=$local_path.md_werc/comments/$d/ + if(! ~ $#allowComments 0) { + ll_add handlers_body_foot bridge_body_foot + if(get_post_args comment_text) { + dprint POST COMMNET $"comment_text + d=`{date -n} # FIXME Obvious race + d=$local_path^'_werc/comments/'^$d/ - u=$logged_user - if(~ $#logged_user 0) { - get_post_args comment_user_name comment_user_password - # TODO Should take this path too if the user can login but doesn't - # belong to required group - if(! login_user $comment_user_name $comment_user_password) { - u=$comment_user_name ':' $comment_user_password - d=$d^'_pending' + u=$logged_user + if(~ $#logged_user 0) { + get_post_args comment_user_name comment_user_password + # XXX Should do this too if user not in required group + if(! login_user $comment_user_name $comment_user_password) { + u=$comment_user_name ':' $comment_user_password + d=$d^'_pending' + } + if not + u = $logged_user } - if not - u = $logged_user - } - umask 002 - mkdir -m 775 -p $d - echo $u > $d/user - echo $comment_text > $d/body + umask 002 + mkdir -m 775 -p $d + echo $u > $d/user + echo $comment_text > $d/body + } + if not + dprint SSS $status } } + +fn bridge_body_foot { + template apps/bridge/foot.tpl +} + diff --git a/apps/bridge/foot.tpl b/apps/bridge/foot.tpl new file mode 100644 index 0000000..0af0c84 --- /dev/null +++ b/apps/bridge/foot.tpl @@ -0,0 +1,25 @@ +% cdir = $local_path^'_werc/comments' +% if(test -d $cdir) { +

Comments

+% for(c in `{ls $cdir/}) { +
By: '`{cat $c/user} '
+% cat $c/body | escape_html | sed 's,$,
,' +
+% } +% } + +% get_post_args action +% dprint XXX $"action + +

+
+% if(! check_user) { + User: + Password: + If you are not registered enter your desired user/password and your account will be created when your comment is approved. +% } + + + +
+ diff --git a/bin/werc.rc b/bin/werc.rc index 9da73af..7ecc2ba 100755 --- a/bin/werc.rc +++ b/bin/werc.rc @@ -58,8 +58,6 @@ fn gensidebar { # Handlers -fn set_handler { handler=$* } - fn md_handler { cat $* | $formatter } fn tpl_handler { template $1 } @@ -86,68 +84,48 @@ fn dir_listing_handler { echo '' } -fn select_handler { +fn setup_handlers { if(test -f $local_path.md) - set_handler md_handler $local_path.md - + handler_body_main=(md_handler $local_path.md) if not if(test -f $local_path.tpl) - set_handler tpl_handler $local_path.tpl - + handler_body_main=(tpl_handler $local_path.tpl) if not if(test -f $local_path.html) - set_handler html_handler $local_path.html - + handler_body_main=(html_handler $local_path.html) # Global tpl (eg sitemap.tpl), should take precedence over txt handler! if not if(test -f lib^$req_path^.tpl) - set_handler tpl_handler lib^$req_path^.tpl - + handler_body_main=(tpl_handler lib^$req_path^.tpl) if not if(test -f $local_path.txt) - set_handler txt_handler $local_path.txt + handler_body_main=(txt_handler $local_path.txt) # Apps - if not if(! ~ $#enabled_apps 0 && select_apps) - set_handler app_handler + if(! ~ $#enabled_apps 0) + init_apps # Dir listing - if not if(~ $local_path */index) + if(~ $#handler_body_main 0 && ~ $local_path */index) set_handler dir_listing_handler $local_path - - # Explicit .html urls, unfortunately usually the web server will handle this as static files - if not if(~ $local_path *.html && test -f $local_path) + # Explicit .html urls, the web server might handle this first! + if not if(~ $#handler_body_main 0 && ~ $local_path *.html && test -f $local_path) perm_redirect `{ echo $req_path|sed 's/.html$//' } - # Fallback static file handler - if not if(test -f $local_path) { - m='text/plain' - if(~ $req_path *.css) - m='text/css' - if not if(~ $req_path *.ico) - m='image/x-icon' - if not if(~ $req_path *.png) - m='image/png' - if not if(~ $req_path *.jpg *.jpeg) - m='image/jpeg' - if not if(~ $req_path *.gif) - m='image/gif' - if not if(~ $req_path *.pdf) - m='application/pdf' - - echo 'Content-Type: '^$m - echo - cat $local_path - exit - } - + if not if(~ $#handler_body_main 0 && test -f $local_path) + static_file $local_path # File not found - if not { + if not if(~ $#handler_body_main 0) { set_handler tpl_handler `{get_lib_file 404.tpl} dprint 'NOT FOUND: '$SERVER_NAME^$"REQUEST_URI^' - '^$"HTTP_REFERER^' - '^$"HTTP_USER_AGENT echo 'Status: 404 Not Found' } - } -fn genbody { $handler(1) $handler(2-) } +fn run_handlers { + for(h in $*) + run_handler $$h +} +fn run_handler { + $*(1) $*(2-) +} # Careful, the proper p9p path might not be set until initrc.local is sourced path=(. $PLAN9/bin ./bin/ /bin/ /usr/bin) @@ -226,7 +204,7 @@ if(~ $pageTitle '') if not pageTitle=$"pageTitle^' | '^$"siteTitle^' '^$"siteSubTitle -select_handler +setup_handlers if(! ~ $#debug 0) dprint ' '$"SERVER_NAME^$"REQUEST_URI' - '$"HTTP_USER_AGENT' - '$"REQUEST_METHOD' - '$"handler diff --git a/lib/default_master.tpl b/lib/default_master.tpl index bcf33b8..7165b07 100644 --- a/lib/default_master.tpl +++ b/lib/default_master.tpl @@ -42,39 +42,16 @@ gensidebar % }
-% genbody -% if(! ~ $#allowComments 0) { +% run_handlers $handlers_body_head -%{ -cdir = $local_path.md_werc/comments -if(test -d $cdir) { - echo '

Comments

' - for(c in `{ls $cdir/}) { -%} -
-% echo By: `{cat $c/user} -
-% cat $c/body | escape_html | sed 's,$,
,' -
-%{ - } -} -%} -

-
-% if(! check_user) { - User: Password: - - If you are not registered enter your desired user/password and your account will be created when your comment is approved. -% } - - -
-% } +% run_handler $handler_body_main + +% run_handlers $handlers_body_foot