changelog shortlog tags branches changeset file revisions annotate raw help

Mercurial > hg > werc / apps/paste/app.rc

revision 670: 60cda9132c99
parent 657: fb460a671d19
     1.1--- a/apps/paste/app.rc	Thu Feb 11 16:25:11 2016 -0500
     1.2+++ b/apps/paste/app.rc	Wed Feb 17 12:19:07 2016 -0500
     1.3@@ -1,33 +1,47 @@
     1.4-fn conf_enable_paste {
     1.5-        paste_url=$conf_wd
     1.6-        paste_dir=`{pwd}
     1.7-        conf_enable_app paste
     1.8+fn conf_enable_wercpaste {
     1.9+	paste_url=$conf_wd
    1.10+	if (~ $#paste_dir 0) { paste_dir=`{pwd} }
    1.11+	conf_enable_app wercpaste
    1.12 }
    1.13 
    1.14-fn paste_init {
    1.15-        if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste 
    1.16-                now=`{ date -n }
    1.17-                cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' }
    1.18-                if (~ $cksum '1715a8eb' ) { # empty paste; discard
    1.19-                        post_redirect $base_url^$paste_url
    1.20-                }
    1.21-                if not {  # save and redirect
    1.22-                        # TODO: stop using echo
    1.23-                        echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum
    1.24-#cat<<EOF > $paste_dir^/^$now^.^$cksum
    1.25-#$"post_arg_paste
    1.26-#EOF
    1.27-                        #post_redirect $base_url^$paste_url^$now^.^$cksum
    1.28-                        echo 'Content-type: text/plain'; echo ''; exec echo $base_url^$paste_url^$now^.^$cksum
    1.29-                }
    1.30-        } 
    1.31-        if not { # show a paste if there is one
    1.32-                if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { 
    1.33-                                echo 'Content-type: text/plain'; echo ''; exec cat $werc_root/$local_path
    1.34-                        } 
    1.35-        }
    1.36+fn wercpaste_init {
    1.37+	if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste 
    1.38+		now=`{ date -n }
    1.39+		cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' }
    1.40+		if (~ $cksum '1715a8eb' ) { # empty paste; discard
    1.41+			post_redirect $base_url^$paste_url
    1.42+		}
    1.43+		if not {  # save and redirect
    1.44+			# TODO: stop using echo
    1.45+			# env var size limit is 16kb, this thing dies with larger input.
    1.46+			echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum
    1.47+			# uncomment the following line to redirect to the pasted file
    1.48+			#post_redirect $base_url^$paste_url^$now^.^$cksum
    1.49+			# uncomment the following line instead to just return the url
    1.50+			echo 'Content-type: text/plain'; echo ''; exec echo $base_url^$paste_url^$now^.^$cksum
    1.51+		}
    1.52+	} 
    1.53+	if not { # show a paste if there is one
    1.54+		if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { 
    1.55+				echo 'Content-type: text/plain'; echo ''; exec cat $werc_root/$local_path
    1.56+			} 
    1.57+	}
    1.58 
    1.59-# if we haven't done anything by now, we don't care.  we just exit and let
    1.60-# werc handle it from here.
    1.61+# drop a textbox 
    1.62+	if (~ $REQUEST_METHOD GET ) { handler_body_main='begforpaste' }
    1.63+
    1.64 }
    1.65 
    1.66+fn begforpaste {
    1.67+	echo '<h1>Pastebin</h1>
    1.68+	<article>
    1.69+	<h3 style="text-align: center">pasted data is not publically indexed</h3>
    1.70+	<form action="'$paste_url'" method="post" style="margin:2em">
    1.71+	<textarea name="paste" cols="120" rows="20" required style="display: block; margin: 0 auto 0 auto" ></textarea><br>
    1.72+	<input type="submit" name="submit" value="SUBMIT" style="display: block; margin: 0 auto 0 auto" ><br><br>
    1.73+	<span style="display: none"><input type="text" name="url" value="url" > (do not change) </span>
    1.74+	</form>
    1.75+	</article>
    1.76+	'
    1.77+}
    1.78+