shithub: werc

Download patch

ref: 5ad6bbe39c971499948adf752e665ed8f1d745d9
parent: 6976b1fac34633a9d47e4b7dada6037c66c61502
author: uriel <uriel@engel.se.cat-v.org>
date: Mon Oct 13 21:59:10 EDT 2008

More minnor comment and code formatting changes

--- a/bin/cgilib.rc
+++ b/bin/cgilib.rc
@@ -1,5 +1,8 @@
 # Useful functions
 
+NEW_LINE = '
+'
+
 fn dprint { echo $* >[1=2] }
 
 fn escape_html { sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' $* }
@@ -88,4 +91,62 @@
     print decoded
 }
 '
+}
+
+# Auth code
+# Cookie format: WERC_USER: name:timestamp:hash(name.timestamp.password)
+
+fn auth_user {
+    group = $1
+    user_name = $2
+    user_pass = $3
+
+    pfile = etc/users/$user_name/password
+    grep -s '^'^$user_name^'$' etc/groups/$group && test -f $pfile && ~ $user_pass `{cat $pfile}
+}
+
+
+fn make_blog_post {
+    bdir = $1
+    title = $2
+
+    date=`{/bin/date +%F}
+
+    n = 1
+    for(f in $bdir/$date-*) {
+        i = `{echo $f | sed -n 's|^.*/'$date'-([0-9]+)_.*|\1|p'}
+        if(! ~ $#i 0 && test $i -ge $n)
+		n = `{hoc -e $i'+1'}
+    }
+    title = `{echo $"title | sed 's/[ 	]+/_/g; 1q'}
+
+    $bdir/$"date^'-'^$"n^_$"title.md
+
+}
+
+
+# --------
+
+app_blog_methods = ( _post index.rss )
+fn app_blog__post {
+
+}
+
+app_blog___default {
+    if (~ $blog
+    call_app blogpost
+}
+
+# --
+app_blogpost_methods = ( comment  _edit )
+
+fn app_blogpost_comment {
+    call_app comments
+}_
+
+# --
+app_comments_methods = ( _post _edit )
+
+fn app_comments___default {
+
 }
--- a/bin/controller.rc
+++ b/bin/controller.rc
@@ -203,7 +203,6 @@
         extraHeaders=$"extraHeaders ^ \
     	'<link rel="alternate" type="application/rss+xml" title="RSS" href="'$rssuri'" />
 '
-
         set_handler blog_dir_handler $blogDirs
     }
 
@@ -229,7 +228,6 @@
 
 
 fn genbody {
-    # Actually execute request
     $handler $handler_args
 }