paste: remove some code smell, roll index.html into app.rc

This commit is contained in:
Kurt H Maier 2016-02-17 12:19:07 -05:00
parent 721ac39234
commit 8b7a43f481

View file

@ -1,33 +1,47 @@
fn conf_enable_paste { fn conf_enable_wercpaste {
paste_url=$conf_wd paste_url=$conf_wd
paste_dir=`{pwd} if (~ $#paste_dir 0) { paste_dir=`{pwd} }
conf_enable_app paste conf_enable_app wercpaste
} }
fn paste_init { fn wercpaste_init {
if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste
now=`{ date -n } now=`{ date -n }
cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' } cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' }
if (~ $cksum '1715a8eb' ) { # empty paste; discard if (~ $cksum '1715a8eb' ) { # empty paste; discard
post_redirect $base_url^$paste_url post_redirect $base_url^$paste_url
} }
if not { # save and redirect if not { # save and redirect
# TODO: stop using echo # TODO: stop using echo
echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum # env var size limit is 16kb, this thing dies with larger input.
#cat<<EOF > $paste_dir^/^$now^.^$cksum echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum
#$"post_arg_paste # uncomment the following line to redirect to the pasted file
#EOF #post_redirect $base_url^$paste_url^$now^.^$cksum
#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 echo 'Content-type: text/plain'; echo ''; exec echo $base_url^$paste_url^$now^.^$cksum
} }
} }
if not { # show a paste if there is one if not { # show a paste if there is one
if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) {
echo 'Content-type: text/plain'; echo ''; exec cat $werc_root/$local_path 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 '<h1>Pastebin</h1>
<article>
<h3 style="text-align: center">pasted data is not publically indexed</h3>
<form action="'$paste_url'" method="post" style="margin:2em">
<textarea name="paste" cols="120" rows="20" required style="display: block; margin: 0 auto 0 auto" ></textarea><br>
<input type="submit" name="submit" value="SUBMIT" style="display: block; margin: 0 auto 0 auto" ><br><br>
<span style="display: none"><input type="text" name="url" value="url" > (do not change) </span>
</form>
</article>
'
} }