Experimental comments system
This commit is contained in:
parent
272840da52
commit
3d3df98d31
3 changed files with 91 additions and 8 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
fn dprint { echo $* >[1=2] }
|
fn dprint { echo $* >[1=2] }
|
||||||
|
|
||||||
|
fn escape_html { sed 's/&/\&/g; s/</\</g; s/>/\>/g' $* }
|
||||||
|
|
||||||
fn perm_redirect {
|
fn perm_redirect {
|
||||||
echo 'Status: 301 Moved Permanantly
|
echo 'Status: 301 Moved Permanantly
|
||||||
Location: '^$1^'
|
Location: '^$1^'
|
||||||
|
|
@ -16,7 +18,7 @@ fn get_post_args {
|
||||||
pair = `{echo -n $pair | sed 's/=/\&/'} \
|
pair = `{echo -n $pair | sed 's/=/\&/'} \
|
||||||
ifs=() \
|
ifs=() \
|
||||||
if(~ $pair(1) $*)
|
if(~ $pair(1) $*)
|
||||||
$pair(1) = `{urldecode $pair(2)}
|
$pair(1) = `{echo $pair(2) | urldecode | tr -d '
'}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,9 +38,54 @@ fn template { template.awk $* | rc $rcargs }
|
||||||
|
|
||||||
# .rec parsing
|
# .rec parsing
|
||||||
fn parse_rec {
|
fn parse_rec {
|
||||||
for(i in `{sed 's/% *//; /^$/q' < $1}) {
|
ifs='
|
||||||
v = `{echo $i | sed 's/^/rec_/; s/=.*//;'}
|
' for(i in `{sed 's/% *//g; /^$/q' < $1}) {
|
||||||
$v = `{echo $i | sed
|
v = `{echo -n $i | sed 's/^/rec_/; s/=.*//;'}
|
||||||
|
$v = `{echo -n $i | sed 's/^[^=]*=//'}
|
||||||
}
|
}
|
||||||
rec_data = `{sed -n '/^$/,$p' < $1}
|
ifs=() rec_data = `{sed -n '/^[^%]./,$p' < $1}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn urldecode {
|
||||||
|
awk '
|
||||||
|
BEGIN {
|
||||||
|
hextab ["0"] = 0; hextab ["8"] = 8;
|
||||||
|
hextab ["1"] = 1; hextab ["9"] = 9;
|
||||||
|
hextab ["2"] = 2; hextab ["A"] = hextab ["a"] = 10
|
||||||
|
hextab ["3"] = 3; hextab ["B"] = hextab ["b"] = 11;
|
||||||
|
hextab ["4"] = 4; hextab ["C"] = hextab ["c"] = 12;
|
||||||
|
hextab ["5"] = 5; hextab ["D"] = hextab ["d"] = 13;
|
||||||
|
hextab ["6"] = 6; hextab ["E"] = hextab ["e"] = 14;
|
||||||
|
hextab ["7"] = 7; hextab ["F"] = hextab ["f"] = 15;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
decoded = ""
|
||||||
|
i = 1
|
||||||
|
len = length ($0)
|
||||||
|
while ( i <= len ) {
|
||||||
|
c = substr ($0, i, 1)
|
||||||
|
if ( c == "%" ) {
|
||||||
|
if ( i+2 <= len ) {
|
||||||
|
c1 = substr ($0, i+1, 1)
|
||||||
|
c2 = substr ($0, i+2, 1)
|
||||||
|
if ( hextab [c1] == "" || hextab [c2] == "" ) {
|
||||||
|
print "WARNING: invalid hex encoding: %" c1 c2 | "cat >&2"
|
||||||
|
} else {
|
||||||
|
code = 0 + hextab [c1] * 16 + hextab [c2] + 0
|
||||||
|
c = sprintf ("%c", code)
|
||||||
|
i = i + 2
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print "WARNING: invalid % encoding: " substr ($0, i, len - i)
|
||||||
|
}
|
||||||
|
} else if ( c == "+" ) {
|
||||||
|
c = " "
|
||||||
|
}
|
||||||
|
decoded = decoded c
|
||||||
|
++i
|
||||||
|
}
|
||||||
|
print decoded
|
||||||
|
}
|
||||||
|
'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/local/plan9/bin/rc
|
#!/usr/local/plan9/bin/rc
|
||||||
. cgilib.rc
|
. ./cgilib.rc
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]'
|
forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.]'
|
||||||
|
|
@ -176,6 +176,8 @@ fn quote_html {
|
||||||
fn debug_handler {
|
fn debug_handler {
|
||||||
echo '<pre>'
|
echo '<pre>'
|
||||||
env | quote_html
|
env | quote_html
|
||||||
|
echo ---------------------
|
||||||
|
umask
|
||||||
echo '</pre>'
|
echo '</pre>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,6 +189,17 @@ fn select_handler {
|
||||||
set_handler blog_post_handler $body.md
|
set_handler blog_post_handler $body.md
|
||||||
if not
|
if not
|
||||||
set_handler md_handler $body.md
|
set_handler md_handler $body.md
|
||||||
|
|
||||||
|
if (! ~ $#allowComments 0 && ~ $REQUEST_METHOD POST) {
|
||||||
|
get_post_args comment_user_name comment_text
|
||||||
|
ddir = $body.md_werc/comments/
|
||||||
|
umask 002
|
||||||
|
mkdir -m 775 -p $ddir
|
||||||
|
d = `{date -n} # Obvious race
|
||||||
|
{ echo '% user_name='^$comment_user_name'
|
||||||
|
|
||||||
|
'^$comment_text } > $ddir/$d.rec
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if not if (~ $body */_debug)
|
if not if (~ $body */_debug)
|
||||||
set_handler debug_handler
|
set_handler debug_handler
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,29 @@
|
||||||
|
|
||||||
% genbody
|
% genbody
|
||||||
|
|
||||||
|
% if (! ~ $#allowComments 0) {
|
||||||
|
|
||||||
|
%{
|
||||||
|
cdir = $body.md_werc/comments
|
||||||
|
if (test -d $cdir) {
|
||||||
|
echo '<hr /><h2>Comments</h2>'
|
||||||
|
for(c in `{ls $cdir}) {
|
||||||
|
parse_rec $c
|
||||||
|
|
||||||
|
echo '<div>'
|
||||||
|
echo User: $rec_user_name '<br />'
|
||||||
|
echo $rec_data | escape_html | sed 's,$,<br />,'
|
||||||
|
echo '<hr /></div>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
<form action="" method="post">
|
||||||
|
<input type="text" name="comment_user_name" value="Anonimous glenda" /><input type="submit" name="post_comment" value="Post a comment" />
|
||||||
|
<textarea name="comment_text" id="comment_text" cols="80" rows="16"></textarea>
|
||||||
|
</form>
|
||||||
|
% }
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue