From 5bf3790c9e40c6117581e207634b6481a3eaa5e4 Mon Sep 17 00:00:00 2001 From: khm Date: Wed, 17 Feb 2016 12:19:07 -0500 Subject: [PATCH] paste: remove some code smell, roll index.html into app.rc --- apps/paste/app.rc | 70 ++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/apps/paste/app.rc b/apps/paste/app.rc index ecbb352..8b91ff9 100755 --- a/apps/paste/app.rc +++ b/apps/paste/app.rc @@ -1,33 +1,47 @@ -fn conf_enable_paste { - paste_url=$conf_wd - paste_dir=`{pwd} - conf_enable_app paste +fn conf_enable_wercpaste { + paste_url=$conf_wd + if (~ $#paste_dir 0) { paste_dir=`{pwd} } + conf_enable_app wercpaste } -fn paste_init { - if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste - now=`{ date -n } - cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' } - if (~ $cksum '1715a8eb' ) { # empty paste; discard - post_redirect $base_url^$paste_url - } - if not { # save and redirect - # TODO: stop using echo - echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum -#cat< $paste_dir^/^$now^.^$cksum -#$"post_arg_paste -#EOF - #post_redirect $base_url^$paste_url^$now^.^$cksum - echo 'Content-type: text/plain'; echo ''; exec echo $base_url^$paste_url^$now^.^$cksum - } - } - if not { # show a paste if there is one - if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { - echo 'Content-type: text/plain'; echo ''; exec cat $werc_root/$local_path - } - } +fn wercpaste_init { + if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste + now=`{ date -n } + cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' } + if (~ $cksum '1715a8eb' ) { # empty paste; discard + post_redirect $base_url^$paste_url + } + if not { # save and redirect + # TODO: stop using echo + # env var size limit is 16kb, this thing dies with larger input. + echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum + # uncomment the following line to redirect to the pasted file + #post_redirect $base_url^$paste_url^$now^.^$cksum + # uncomment the following line instead to just return the url + echo 'Content-type: text/plain'; echo ''; exec echo $base_url^$paste_url^$now^.^$cksum + } + } + if not { # show a paste if there is one + if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { + echo 'Content-type: text/plain'; echo ''; exec cat $werc_root/$local_path + } + } + +# drop a textbox + if (~ $REQUEST_METHOD GET ) { handler_body_main='begforpaste' } -# if we haven't done anything by now, we don't care. we just exit and let -# werc handle it from here. +} + +fn begforpaste { + echo '

Pastebin

+
+

pasted data is not publically indexed

+
+
+

+ (do not change) +
+
+ ' }