0=/dev/stdin

CONTENT_LENGTH=0

DOCUMENT_ROOT=/var/www/sites/suckless.org/

GATEWAY_INTERFACE=CGI/1.1

HTTP_ACCEPT=text/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7

HTTP_ACCEPT_ENCODING=gzip

HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5

HTTP_CACHE_CONTROL=no-cache

HTTP_CONNECTION=close

HTTP_HOST=suckless.org

HTTP_PRAGMA=no-cache

HTTP_USER_AGENT=CCBot/1.0 (+http://www.commoncrawl.org/bot.html)

HTTP_X_CC_ID=ccc01-01

NEW_LINE=



PATH=/usr/local/plan9/bin:.:./bin:./bin/contrib:/bin:/usr/bin

PLAN9=/usr/local/plan9

REDIRECT_STATUS=200

REMOTE_ADDR=38.107.179.209

REMOTE_PORT=54267

REQUEST_METHOD=GET

REQUEST_URI=/wiki/sandbox/test

SCRIPT_FILENAME=/var/www/werc-dev/bin/werc.rc

SCRIPT_NAME=/werc.rc

SERVER_ADDR=0.0.0.0

SERVER_NAME=suckless.org

SERVER_PORT=80

SERVER_PROTOCOL=HTTP/1.1

SERVER_SOFTWARE=lighttpd/1.4.28

_l=perm_redir_patterns_39

allowed_user_chars=[a-zA-Z0-9_]

args=wikisandboxtest

base_url=http://suckless.org

co=wmi/wmi.suckless.org

comment_file_types=mdhtml

conf_wd=/wiki/sandbox/test

current_date_time=SatFeb421:58:17CET2012

difs=



dirclean= s/\.(md|html|txt|tpl)$//;

dirfilter=s/\*$//; s,/+\./+,/,g; s,^\./,,; /\/[._][^\/]/d; /[^a-zA-Z0-9_+\-\/\.,:]/d; /\/index\.(md|html|txt|tpl)$/d; /\/(robots|sitemap)\.txt$/d; /_werc\/?$/d;

fn#auth_user={user_name=$1;user_password=$2;pfile=$werc_root^/etc/users/^$"user_name^/password;if(~ $#user_name 0 || ~ $#user_password 0)status=('Auth: missing user name or pass: '^$"user_name^' / '^$"user_password);if not if(! test -f $pfile)status=('Auth: cant find '^$pfile);if not if(! test -s $pfile || ! ~ $user_password `{cat $pfile})status=('Auth: Pass '^$user_password^' doesnt match '^`{cat $pfile});if not {logged_user=$user_name;logged_password=$user_password;dprint Auth: success;status=()}}



fn#auth_user={user_name=$1;user_password=$2;pfile=$werc_root^/etc/users/^$"user_name^/password;if(~ $#user_name 0 || ~ $#user_password 0)status=('Auth: missing user name or pass: '^$"user_name^' / '^$"user_password);if not if(! test -f $pfile)status=('Auth: cant find '^$pfile);if not if(! test -s $pfile || ! ~ $user_password `{cat $pfile})status=('Auth: Pass '^$user_password^' doesnt match '^`{cat $pfile});if not {logged_user=$user_name;logged_password=$user_password;dprint Auth: success;status=()}}



fn#awk_buffer={awk '{

buf = buf $0"\n"

if(length(buf) > 1400) {

printf "%s", buf

buf = ""

}

}

END { printf "%s", buf }'}



fn#awk_buffer={awk '{

buf = buf $0"\n"

if(length(buf) > 1400) {

printf "%s", buf

buf = ""

}

}

END { printf "%s", buf }'}



fn#blagh_body={if(! ~ $"blogTitle '')echo '

'^$"blogTitle^'

';{for(p in `{get_post_list $blagh_root^$blagh_dirs}){l=`{echo -n $p|sed 's!'^$sitedir^'/?(.*)([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])(/[^/]+/)!\2 /\1\2\3!'};<$p^/index.md sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!';echo}}|$formatter}



fn#blagh_body={if(! ~ $"blogTitle '')echo '

'^$"blogTitle^'

';{for(p in `{get_post_list $blagh_root^$blagh_dirs}){l=`{echo -n $p|sed 's!'^$sitedir^'/?(.*)([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])(/[^/]+/)!\2 /\1\2\3!'};<$p^/index.md sed '1s!.*![&]('^$l(2)^') ('^$l(1)^')!';echo}}|$formatter}



fn#blagh_init={if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*){blagh_uri=`{echo $req_path|sed 's,(/[bB]log/).*,\1,'};blagh_dirs=(.)};if(! ~ $#blagh_dirs 0){blagh_url=$base_url^$blagh_uri;blagh_root=$sitedir^$blagh_uri;if(check_user $conf_blog_editors){editor_mode=on;if(~ $"post_arg_date '')post_date=`{/bin/date +%F|sed 's,-,/,g'};if not post_date=$post_arg_date;ll_add handlers_bar_left echo 'Make a new post'};if(~ $req_path $blagh_uri){handler_body_main=blagh_body;u=$blagh_uri^'index';extraHeaders=$"extraHeaders^'

'};if not if(~ $req_path $blagh_uri^index.atom)blagh_setup_feed_handlers atom.tpl 'application/atom+xml';if not if(~ $req_path $blagh_uri^index.rss)blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8';if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0){handler_body_main=(tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl});if(~ $REQUEST_METHOD POST){if(mkbpost $"post_arg_body $"post_date $"post_arg_title $post_arg_id)post_redirect $blagh_uri;if not notify_errors=$status}}}}



fn#blagh_init={if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*){blagh_uri=`{echo $req_path|sed 's,(/[bB]log/).*,\1,'};blagh_dirs=(.)};if(! ~ $#blagh_dirs 0){blagh_url=$base_url^$blagh_uri;blagh_root=$sitedir^$blagh_uri;if(check_user $conf_blog_editors){editor_mode=on;if(~ $"post_arg_date '')post_date=`{/bin/date +%F|sed 's,-,/,g'};if not post_date=$post_arg_date;ll_add handlers_bar_left echo 'Make a new post'};if(~ $req_path $blagh_uri){handler_body_main=blagh_body;u=$blagh_uri^'index';extraHeaders=$"extraHeaders^'

'};if not if(~ $req_path $blagh_uri^index.atom)blagh_setup_feed_handlers atom.tpl 'application/atom+xml';if not if(~ $req_path $blagh_uri^index.rss)blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8';if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0){handler_body_main=(tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl});if(~ $REQUEST_METHOD POST){if(mkbpost $"post_arg_body $"post_date $"post_arg_title $post_arg_id)post_redirect $blagh_uri;if not notify_errors=$status}}}}



fn#blagh_setup_feed_handlers={handler_body_main=NOT_USED_by_blagh_feeds;res_tail=();http_content_type=$2;headers=();master_template=apps/blagh/^$1}



fn#blagh_setup_feed_handlers={handler_body_main=NOT_USED_by_blagh_feeds;res_tail=();http_content_type=$2;headers=();master_template=apps/blagh/^$1}



fn#bridge_init={if(~ $#enable_comments 1 && ! ~ `{>[2]/dev/null ls $local_path^.^$comment_file_types|wc -l} 0){comments_dir=$sitedir^$req_path^'_werc/comments';if(~ $REQUEST_METHOD GET && test -d $comments_dir)ll_add handlers_body_foot template apps/bridge/comments_list.tpl;if(check_user $groups_allowed_comments || {~ $#logged_user 0 && ~ 1 $#allow_new_user_comments $#bridge_anon_comments}){if(~ $#post_arg_bridge_post 1){ll_add handlers_body_foot template apps/bridge/foot.tpl;if(mk_new_comment $comments_dir)post_redirect $base_url^$req_path;if not saved_comment_text=$post_arg_comment_text};if not if(~ $REQUEST_METHOD GET)ll_add handlers_body_foot template apps/bridge/foot.tpl};if not if(~ $REQUEST_METHOD GET)ll_add handlers_body_foot echo '

To post a comment you need to login first.

'}}



fn#bridge_init={if(~ $#enable_comments 1 && ! ~ `{>[2]/dev/null ls $local_path^.^$comment_file_types|wc -l} 0){comments_dir=$sitedir^$req_path^'_werc/comments';if(~ $REQUEST_METHOD GET && test -d $comments_dir)ll_add handlers_body_foot template apps/bridge/comments_list.tpl;if(check_user $groups_allowed_comments || {~ $#logged_user 0 && ~ 1 $#allow_new_user_comments $#bridge_anon_comments}){if(~ $#post_arg_bridge_post 1){ll_add handlers_body_foot template apps/bridge/foot.tpl;if(mk_new_comment $comments_dir)post_redirect $base_url^$req_path;if not saved_comment_text=$post_arg_comment_text};if not if(~ $REQUEST_METHOD GET)ll_add handlers_body_foot template apps/bridge/foot.tpl};if not if(~ $REQUEST_METHOD GET)ll_add handlers_body_foot echo '

To post a comment you need to login first.

'}}



fn#check_user={get_user;g=($* admin);_status=$status;if(! ~ $"_status '')_status=(Not logged in: $"_status);if not if(! ~ $#* 0 && ! ~ $logged_user $* && ! >[2]/dev/null grep -s '^'^$logged_user^'$' $werc_root^/etc/users/^$g^/members)_status=(User $logged_user not in: $*);status=$_status}



fn#check_user={get_user;g=($* admin);_status=$status;if(! ~ $"_status '')_status=(Not logged in: $"_status);if not if(! ~ $#* 0 && ! ~ $logged_user $* && ! >[2]/dev/null grep -s '^'^$logged_user^'$' $werc_root^/etc/users/^$g^/members)_status=(User $logged_user not in: $*);status=$_status}



fn#conf_enable_app={if(! ~ $1 $enabled_apps)enabled_apps=($enabled_apps $1)}



fn#conf_enable_app={if(! ~ $1 $enabled_apps)enabled_apps=($enabled_apps $1)}



fn#conf_enable_blog={blagh_uri=$conf_wd;blagh_dirs=$*;if(~ $#blagh_dirs 0)blagh_dirs=(.);conf_enable_app blagh;if(~ $"conf_blog_editors '')conf_blog_editors=blog-editors;if(~ $"conf_max_posts_per_page '')conf_max_posts_per_page=32}



fn#conf_enable_blog={blagh_uri=$conf_wd;blagh_dirs=$*;if(~ $#blagh_dirs 0)blagh_dirs=(.);conf_enable_app blagh;if(~ $"conf_blog_editors '')conf_blog_editors=blog-editors;if(~ $"conf_max_posts_per_page '')conf_max_posts_per_page=32}



fn#conf_enable_comments={if(~ $1 -n){allow_new_user_comments=yes;shift};if not if(~ $1 -a){bridge_anon_comments=yes};enable_comments=yes;groups_allowed_comments=$*;conf_enable_app bridge}



fn#conf_enable_comments={if(~ $1 -n){allow_new_user_comments=yes;shift};if not if(~ $1 -a){bridge_anon_comments=yes};enable_comments=yes;groups_allowed_comments=$*;conf_enable_app bridge}



fn#conf_enable_wiki={enable_wiki=yes;wiki_editors_groups=$*;conf_enable_app dirdir}



fn#conf_enable_wiki={enable_wiki=yes;wiki_editors_groups=$*;conf_enable_app dirdir}



fn#conf_enable_wman={wman_base_uri=$conf_wd;wman_man_path=$*;if(~ $#wman_man_path 0)wman_man_path=$wman_base_uri;conf_enable_app wman}



fn#conf_enable_wman={wman_base_uri=$conf_wd;wman_man_path=$*;if(~ $#wman_man_path 0)wman_man_path=$wman_base_uri;conf_enable_app wman}



fn#conf_hide_paths={for(i in $*)dirfilter=$dirfilter^'/'^`{echo $sitedir^$conf_wd^$i|sed 's!/+!\\/!g'}^'/d; '}



fn#conf_hide_paths={for(i in $*)dirfilter=$dirfilter^'/'^`{echo $sitedir^$conf_wd^$i|sed 's!/+!\\/!g'}^'/d; '}



fn#conf_perm_redirect={if(~ $#* 1)perm_redir_to=$1;if not ll_addh perm_redir_patterns $1 $2}



fn#conf_perm_redirect={if(~ $#* 1)perm_redir_to=$1;if not ll_addh perm_redir_patterns $1 $2}



fn#crop_text={m=512;e='...';if(! ~ $#1 0)m=$1;if(! ~ $#2 0)e=$2;awk -v 'max='^$"m -v 'ellipsis='^$e '

{

nc += 1 + length;

if(nc > max) {

print substr($0, 1, nc - max) " " ellipsis

exit

}

print

}'}



fn#crop_text={m=512;e='...';if(! ~ $#1 0)m=$1;if(! ~ $#2 0)e=$2;awk -v 'max='^$"m -v 'ellipsis='^$e '

{

nc += 1 + length;

if(nc > max) {

print substr($0, 1, nc - max) " " ellipsis

exit

}

print

}'}



fn#dir_listing_handler={d=`{basename -d $1};if(~ $#d 0)d='/';echo $d|sed 's,.*//,,g; s,/$,,; s,/, / ,g; s,.*,

&

'}



fn#dir_listing_handler={d=`{basename -d $1};if(~ $#d 0)d='/';echo $d|sed 's,.*//,,g; s,/$,,; s,/, / ,g; s,.*,

&

'}



fn#dirdir_init={if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups){lp=$local_path;if(~ $lp */)lp=$lp^'index';dirdir_file=$lp^.md;dirdir_dir=$dirdir_file^'_werc/dirdir/';if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview)handler_body_main=(tpl_handler `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl});if not if(! ~ '' $"post_arg_dirdir_save $"post_arg_edit_text)save_page;if not if(~ $"handler_body_main '' || {~ $REQUEST_METHOD GET && test -f $local_path^.md})ll_add handlers_bar_left tpl_handler apps/dirdir/sidebar_controls.tpl}}



fn#dirdir_init={if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups){lp=$local_path;if(~ $lp */)lp=$lp^'index';dirdir_file=$lp^.md;dirdir_dir=$dirdir_file^'_werc/dirdir/';if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview)handler_body_main=(tpl_handler `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl});if not if(! ~ '' $"post_arg_dirdir_save $"post_arg_edit_text)save_page;if not if(~ $"handler_body_main '' || {~ $REQUEST_METHOD GET && test -f $local_path^.md})ll_add handlers_bar_left tpl_handler apps/dirdir/sidebar_controls.tpl}}



fn#dprint={>[1=2]>>/var/www/werc-dev/log echo $*}



fn#dprint={>[1=2]>>/var/www/werc-dev/log echo $*}



fn#dprintv={>[1=2]{for(v in $*){echo -n $v^'#'^$#$v^'=' $$v '; '};echo}}



fn#dprintv={>[1=2]{for(v in $*){echo -n $v^'#'^$#$v^'=' $$v '; '};echo}}



fn#escape_html={sed 's/&/\&/g; s//\>/g' $*}



fn#escape_html={sed 's/&/\&/g; s//\>/g' $*}



fn#fltr_cache={a=();tmpf=();proc=$1;shift;if(~ $#* 0){tmpf=/tmp/fmttmp.^$pid;f=$tmpf;score=`{{tee $tmpf || exit 1}|sha1sum}};if not {f=$1;if(~ $f */){score=`{du -an $f|sha1sum || exit 1};a=$f;f=/dev/null};if not {score=`{sha1sum $f || exit 1};score=$score(1)}};cachedir=/tmp/fltr_cache/^$score;>[2]/dev/null mkdir -p $cachedir;if(test -s $cachedir^/^$proc)cat $cachedir^/^$proc;if not if(<$f $proc $a|tee $cachedir^/^$pid)mv $cachedir^/^$pid $cachedir^/^$proc;>[2]/dev/null rm $tmpf $cachedir^/^$pid&}



fn#fltr_cache={a=();tmpf=();proc=$1;shift;if(~ $#* 0){tmpf=/tmp/fmttmp.^$pid;f=$tmpf;score=`{{tee $tmpf || exit 1}|sha1sum}};if not {f=$1;if(~ $f */){score=`{du -an $f|sha1sum || exit 1};a=$f;f=/dev/null};if not {score=`{sha1sum $f || exit 1};score=$score(1)}};cachedir=/tmp/fltr_cache/^$score;>[2]/dev/null mkdir -p $cachedir;if(test -s $cachedir^/^$proc)cat $cachedir^/^$proc;if not if(<$f $proc $a|tee $cachedir^/^$pid)mv $cachedir^/^$pid $cachedir^/^$proc;>[2]/dev/null rm $tmpf $cachedir^/^$pid&}



fn#get_cookie={ifs=';' {co=`{echo $HTTP_COOKIE}};{for(c in $co)echo $c}|sed -n 's/^ ?'^$1^'=//p'}



fn#get_cookie={ifs=';' {co=`{echo $HTTP_COOKIE}};{for(c in $co)echo $c}|sed -n 's/^ ?'^$1^'=//p'}



fn#get_file_title={if(~ $1 *.md)get_md_title $1;if not if(~ $1 *.html)get_html_title $1;if not if(~ $1 */){if(test -f $1^/index.md)get_md_title $1^/index.md;if not if(test -f $1^/index.html)get_html_title $1^/index.html}}



fn#get_file_title={if(~ $1 *.md)get_md_title $1;if not if(~ $1 *.html)get_html_title $1;if not if(~ $1 */){if(test -f $1^/index.md)get_md_title $1^/index.md;if not if(test -f $1^/index.html)get_html_title $1^/index.html}}



fn#get_html_title={t=`{<$1 sed -n '32q; s/^.*<[Tt][Ii][Tt][Ll][Ee]> *([^<]+) *(<\/[Tt][Ii][Tt][Ll][Ee]>.*)?$/\1/p'};if(~ $"t '')t=`{<$1 sed -n -e 's/^(<[^>]+>)*([^<]+).*/\2/p; 32q'|sed 1q};echo $t}



fn#get_html_title={t=`{<$1 sed -n '32q; s/^.*<[Tt][Ii][Tt][Ll][Ee]> *([^<]+) *(<\/[Tt][Ii][Tt][Ll][Ee]>.*)?$/\1/p'};if(~ $"t '')t=`{<$1 sed -n -e 's/^(<[^>]+>)*([^<]+).*/\2/p; 32q'|sed 1q};echo $t}



fn#get_lib_file={if(! ~ $#sitedir 0 && test -f $sitedir^/_werc/lib/^$1)echo -n $sitedir^/_werc/lib/^$1;if not if(! ~ $#masterSite 0 && test -f $sitesdir^/^$masterSite^/_werc/lib/^$1)echo -n $sitesdir^/^$masterSite^/_werc/lib/^$1;if not if(test -f lib/^$1)echo -n lib/^$1;if not if(~ $#* 2)echo -n $2;if not status='Can''t find lib file: '^$1}



fn#get_lib_file={if(! ~ $#sitedir 0 && test -f $sitedir^/_werc/lib/^$1)echo -n $sitedir^/_werc/lib/^$1;if not if(! ~ $#masterSite 0 && test -f $sitesdir^/^$masterSite^/_werc/lib/^$1)echo -n $sitesdir^/^$masterSite^/_werc/lib/^$1;if not if(test -f lib/^$1)echo -n lib/^$1;if not if(~ $#* 2)echo -n $2;if not status='Can''t find lib file: '^$1}



fn#get_md_file_attr={<$1 sed -n '/^\* '^$2^': /p; /^\* '^$2^': /q; /^$/q'}



fn#get_md_file_attr={<$1 sed -n '/^\* '^$2^': /p; /^\* '^$2^': /q; /^$/q'}



fn#get_md_title={<$1 sed -n -e '1N; /^.*\n===*$/N; /.*\n===*\n *$/!b' -e 's/\n==*\n//p'}



fn#get_md_title={<$1 sed -n -e '1N; /^.*\n===*$/N; /.*\n===*\n *$/!b' -e 's/\n==*\n//p'}



fn#get_post_args={load_post_args;_status='No post arg matches';for(n in $*){v=post_arg_^$n;if(! ~ $#$v 0){$n=$$v;_status=()}};status=$_status}



fn#get_post_args={load_post_args;_status='No post arg matches';for(n in $*){v=post_arg_^$n;if(! ~ $#$v 0){$n=$$v;_status=()}};status=$_status}



fn#get_post_list={>[2]/dev/null ls -F $*^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/|sed -n '/'^$forbidden_uri_chars^'/d; s,/\./,/|/,; /\/$/p'|sort -r '-t|' +1|sed -e 's,/+\|/+,/,' -e $conf_max_posts_per_page^'q'}



fn#get_post_list={>[2]/dev/null ls -F $*^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/|sed -n '/'^$forbidden_uri_chars^'/d; s,/\./,/|/,; /\/$/p'|sort -r '-t|' +1|sed -e 's,/+\|/+,/,' -e $conf_max_posts_per_page^'q'}



fn#get_user={if(~ $#logged_user 0){if(~ $#* 2){user_name=$1;user_password=$2};if not if(~ $REQUEST_METHOD POST)get_post_args user_name user_password;if(~ $#user_name 0){ifs=':' {cu=`{ifs=$difs {get_cookie werc_user}|tr -d $NEW_LINE}};if(! ~ $#cu 0){user_name=$cu(1);user_password=$cu(3)}};auth_user $user_name $user_password};if not status=()}



fn#get_user={if(~ $#logged_user 0){if(~ $#* 2){user_name=$1;user_password=$2};if not if(~ $REQUEST_METHOD POST)get_post_args user_name user_password;if(~ $#user_name 0){ifs=':' {cu=`{ifs=$difs {get_cookie werc_user}|tr -d $NEW_LINE}};if(! ~ $#cu 0){user_name=$cu(1);user_password=$cu(3)}};auth_user $user_name $user_password};if not status=()}



fn#hello_body={echo 'Hello world!'}



fn#hello_body={echo 'Hello world!'}



fn#hello_init={if(~ $req_path /hello){handler_body_main='hello_body';pageTitle='Hi title!'}}



fn#hello_init={if(~ $req_path /hello){handler_body_main='hello_body';pageTitle='Hi title!'}}



fn#html_handler={<$1 awk 'gsub(".*<[Bb][Oo][Dd][Yy][^>]*>", "") > 0 {body=2}

gsub("]*>.*", "") > 0 {print; body=body-1}

body==2 {print}

body==0 {buf=buf "\n" $0}

END {if(body<=0) {print buf}}'}



fn#html_handler={<$1 awk 'gsub(".*<[Bb][Oo][Dd][Yy][^>]*>", "") > 0 {body=2}

gsub("]*>.*", "") > 0 {print; body=body-1}

body==2 {print}

body==0 {buf=buf "\n" $0}

END {if(body<=0) {print buf}}'}



fn#http_redirect={if(~ $1 http://* https://*)t=$1;if not if(~ $1 /*)t=$"base_url^$1;if not t=$"base_url^$"req_path^$1;echo 'Status: '^$2^'

Location: '^$t^'



';exit}



fn#http_redirect={if(~ $1 http://* https://*)t=$1;if not if(~ $1 /*)t=$"base_url^$1;if not t=$"base_url^$"req_path^$1;echo 'Status: '^$2^'

Location: '^$t^'



';exit}



fn#link_bar={if(~ $1 -t){echo '

'^$2^'

';shift;shift};echo ''}



fn#link_bar={if(~ $1 -t){echo '

'^$2^'

';shift;shift};echo ''}



fn#ll_add={_l=$1^_^$#$1;$_l=$*(2-);$1=($$1 $_l)}



fn#ll_add={_l=$1^_^$#$1;$_l=$*(2-);$1=($$1 $_l)}



fn#ll_addh={_l=$1^_^$#$1;$_l=$*(2-);$1=($_l $$1)}



fn#ll_addh={_l=$1^_^$#$1;$_l=$*(2-);$1=($_l $$1)}



fn#load_post_args={if(~ $REQUEST_METHOD POST && ~ $#post_args 0){ifs='&

' for(pair in `{cat}){ifs='=' {pair=`{echo -n $pair}};n='post_arg_'^`{echo $pair(1)|tr -cd 'a-zA-Z0-9_'};post_args=($post_args $n);ifs=() {$n=`{echo -n $pair(2)|urldecode|tr -d ' '}}};pair=()};if not status='No POST or post args already loaded'}



fn#load_post_args={if(~ $REQUEST_METHOD POST && ~ $#post_args 0){ifs='&

' for(pair in `{cat}){ifs='=' {pair=`{echo -n $pair}};n='post_arg_'^`{echo $pair(1)|tr -cd 'a-zA-Z0-9_'};post_args=($post_args $n);ifs=() {$n=`{echo -n $pair(2)|urldecode|tr -d ' '}}};pair=()};if not status='No POST or post args already loaded'}



fn#login_user={if(get_user $*)set_cookie werc_user $"logged_user^':0:'^$"logged_password}



fn#login_user={if(get_user $*)set_cookie werc_user $"logged_user^':0:'^$"logged_password}



fn#md_handler={$formatter $1}



fn#md_handler={$formatter $1}



fn#mk_new_comment={_status=();dir=$1;if(~ $"post_arg_comment_text '')_status='Provide a comment!';if not if(~ $#logged_user 0){if(! ~ $#allow_new_user_comments 0){if(validate_new_user $"post_arg_comment_user $post_arg_comment_passwd $post_arg_comment_passwd2){u=$post_arg_comment_user^':'^$post_arg_comment_passwd;dir=$comments_dir^'_pending';notify_notes='Saved comment and registration info, they will be enabled when approved by an admin.'};if not _status=$status};if not if(! ~ $#bridge_anon_comments 0){if(~ $"post_arg_ima_robot 'not')u='Glenda';if not _status='You are a robot!'};if not _status='You need to log in to comment.'};if not if(check_user $groups_allowed_comments)u=$logged_user;if not _status='You are not a member of a group allowed to comment.';if(~ $#_status 0){umask 002;dir=$dir^'/'^`{date -n};mkdir -m 775 -p $dir && >$dir^/user echo $u && >$dir^/posted echo $current_date_time && >$dir^/body echo $post_arg_comment_text;_s=$status;if(! ~ $"_s ''){dprint 'ERROR XXX: Could not create comment: ' $_s;_status='Could not post comment due internal error, sorry.'}};notify_errors=$_status;status=$_status}



fn#mk_new_comment={_status=();dir=$1;if(~ $"post_arg_comment_text '')_status='Provide a comment!';if not if(~ $#logged_user 0){if(! ~ $#allow_new_user_comments 0){if(validate_new_user $"post_arg_comment_user $post_arg_comment_passwd $post_arg_comment_passwd2){u=$post_arg_comment_user^':'^$post_arg_comment_passwd;dir=$comments_dir^'_pending';notify_notes='Saved comment and registration info, they will be enabled when approved by an admin.'};if not _status=$status};if not if(! ~ $#bridge_anon_comments 0){if(~ $"post_arg_ima_robot 'not')u='Glenda';if not _status='You are a robot!'};if not _status='You need to log in to comment.'};if not if(check_user $groups_allowed_comments)u=$logged_user;if not _status='You are not a member of a group allowed to comment.';if(~ $#_status 0){umask 002;dir=$dir^'/'^`{date -n};mkdir -m 775 -p $dir && >$dir^/user echo $u && >$dir^/posted echo $current_date_time && >$dir^/body echo $post_arg_comment_text;_s=$status;if(! ~ $"_s ''){dprint 'ERROR XXX: Could not create comment: ' $_s;_status='Could not post comment due internal error, sorry.'}};notify_errors=$_status;status=$_status}



fn#mkbpost={bptext=$1;bpdate=$2;bptitle=$3;bpid=$4;_status=();if(~ $"bptext '')_status=($_status 'You need to provide a post body.');if(! ~ $"bpdate [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])_status=($_status 'Invalid date: '''^$"bpdate^'''');if(~ $#_status 0){umask 002;if(! ~ $"bpid '')bpid=`{echo -n '-'^$bpid|sed 's/'^$forbidden_uri_chars^'+/_/g; 1q'};ddir=$blagh_root^$bpdate^'/';n=`{>[2]/dev/null ls $ddir|wc -l};mkdir -p $ddir^/^$"n^$"bpid^/;>$ddir^/^$"n^$"bpid^/index.md {if(! ~ $"bptitle ''){echo $bptitle;echo '========================================='};echo;echo $bptext};if(! ~ $"conf_blog_pubsubdub_hub ''){ifs='' {p=`{echo $req_url|sed 's/new_post$/index.atom/'|url_encode}};dprint hget -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub;>[1=2]hget -d -h -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub&}};status=$_status}



fn#mkbpost={bptext=$1;bpdate=$2;bptitle=$3;bpid=$4;_status=();if(~ $"bptext '')_status=($_status 'You need to provide a post body.');if(! ~ $"bpdate [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])_status=($_status 'Invalid date: '''^$"bpdate^'''');if(~ $#_status 0){umask 002;if(! ~ $"bpid '')bpid=`{echo -n '-'^$bpid|sed 's/'^$forbidden_uri_chars^'+/_/g; 1q'};ddir=$blagh_root^$bpdate^'/';n=`{>[2]/dev/null ls $ddir|wc -l};mkdir -p $ddir^/^$"n^$"bpid^/;>$ddir^/^$"n^$"bpid^/index.md {if(! ~ $"bptitle ''){echo $bptitle;echo '========================================='};echo;echo $bptext};if(! ~ $"conf_blog_pubsubdub_hub ''){ifs='' {p=`{echo $req_url|sed 's/new_post$/index.atom/'|url_encode}};dprint hget -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub;>[1=2]hget -d -h -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub&}};status=$_status}



fn#nav_sites={for(m in $sites_menu){ifs=(':') {co=`{echo -n $m}};if(~ 'http://'^$co(2) $base_url)echo '
  • '^$co(1)^'
  • ';if not echo '
  • '^$co(1)^'
  • '}}



    fn#nav_sites={for(m in $sites_menu){ifs=(':') {co=`{echo -n $m}};if(~ 'http://'^$co(2) $base_url)echo '
  • '^$co(1)^'
  • ';if not echo '
  • '^$co(1)^'
  • '}}



    fn#nav_tree={if(! ~ $#sideBarNavTitle 0)echo '

    '^$"sideBarNavTitle^':

    ';style_color1='#dddddd';style_color2='#eeeeee';style_color='';for(reqp in $req_paths_list){if(~ $style_color $style_color2)style_color=$style_color1;if not style_color=$style_color2;>[2]/dev/null ls -F $sitedir^/./^$reqp|{sed $dirfilter^'/\/[^_.\/][^\/]*(\.(md|txt|html|tpl)|\/)$/!d; s!^'^$sitedir^'!!; '^$dirclean}|sort -u|awk -F/ '

    function p(x, y, s) { for(i=0; i < x-y; i+=1) print s }

    BEGIN { lNF=2; printed=0; style_color=ENVIRON["style_color"]; }

    {

    d = ""

    if(match($0, "/$"))

    d = "/"

    sub("/$", "") # Strip trailing / for dirs so NF is consistent



    lNF = NF



    bname = $NF d

    path = $0 d

    gsub(/[\-_]/, " ", bname)



    # To avoid false matches add trailing / even for plain files to act as delimiter

    pa = path

    gsub(/[^\/]$/, "&/", pa)



    if(printed == 0) {

    print "
      ";

      printed++;

      }

      if(index(ENVIRON["req_path"] "/", pa) == 1)

      print "
    • " bname "
    • "

      else

      print "
    • " bname "
    • "

      }

      END { if(printed > 0) print "
    " }'}}



    fn#nav_tree={if(! ~ $#sideBarNavTitle 0)echo '

    '^$"sideBarNavTitle^':

    ';style_color1='#dddddd';style_color2='#eeeeee';style_color='';for(reqp in $req_paths_list){if(~ $style_color $style_color2)style_color=$style_color1;if not style_color=$style_color2;>[2]/dev/null ls -F $sitedir^/./^$reqp|{sed $dirfilter^'/\/[^_.\/][^\/]*(\.(md|txt|html|tpl)|\/)$/!d; s!^'^$sitedir^'!!; '^$dirclean}|sort -u|awk -F/ '

    function p(x, y, s) { for(i=0; i < x-y; i+=1) print s }

    BEGIN { lNF=2; printed=0; style_color=ENVIRON["style_color"]; }

    {

    d = ""

    if(match($0, "/$"))

    d = "/"

    sub("/$", "") # Strip trailing / for dirs so NF is consistent



    lNF = NF



    bname = $NF d

    path = $0 d

    gsub(/[\-_]/, " ", bname)



    # To avoid false matches add trailing / even for plain files to act as delimiter

    pa = path

    gsub(/[^\/]$/, "&/", pa)



    if(printed == 0) {

    print "
      ";

      printed++;

      }

      if(index(ENVIRON["req_path"] "/", pa) == 1)

      print "
    • " bname "
    • "

      else

      print "
    • " bname "
    • "

      }

      END { if(printed > 0) print "
    " }'}}



    fn#notices_handler={for(type in notify_errors notify_notes notify_success)for(n in $$type)echo '
    '^$"n^'
    '}



    fn#notices_handler={for(type in notify_errors notify_notes notify_success)for(n in $$type)echo '
    '^$"n^'
    '}



    fn#perm_redirect={http_redirect $1 '301 Moved Permanantly'}



    fn#perm_redirect={http_redirect $1 '301 Moved Permanantly'}



    fn#post_redirect={http_redirect $1 '303 See Other'}



    fn#post_redirect={http_redirect $1 '303 See Other'}



    fn#run_handler={$*(1) $*(2-)}



    fn#run_handler={$*(1) $*(2-)}



    fn#run_handlers={for(h in $*)run_handler $$h}



    fn#run_handlers={for(h in $*)run_handler $$h}



    fn#save_page={dirdir_verdir=$dirdir_dir^/^`{date -n}^/;mkdir -p $dirdir_verdir;umask 002;>$dirdir_verdir^/author echo $logged_user;>$dirdir_verdir^/data echo $post_arg_edit_text;>$dirdir_file echo $post_arg_edit_text;post_redirect $base_url^$req_path}



    fn#save_page={dirdir_verdir=$dirdir_dir^/^`{date -n}^/;mkdir -p $dirdir_verdir;umask 002;>$dirdir_verdir^/author echo $logged_user;>$dirdir_verdir^/data echo $post_arg_edit_text;>$dirdir_file echo $post_arg_edit_text;post_redirect $base_url^$req_path}



    fn#select_mime={m='text/plain';if(~ $1 *.css)m='text/css';if not if(~ $1 *.ico)m='image/x-icon';if not if(~ $1 *.png)m='image/png';if not if(~ $1 *.jpg *.jpeg)m='image/jpeg';if not if(~ $1 *.gif)m='image/gif';if not if(~ $1 *.pdf)m='application/pdf';echo $m}



    fn#select_mime={m='text/plain';if(~ $1 *.css)m='text/css';if not if(~ $1 *.ico)m='image/x-icon';if not if(~ $1 *.png)m='image/png';if not if(~ $1 *.jpg *.jpeg)m='image/jpeg';if not if(~ $1 *.gif)m='image/gif';if not if(~ $1 *.pdf)m='application/pdf';echo $m}



    fn#set_cookie={name=$1;val=$2;extraHttpHeaders=($extraHttpHeaders 'Set-cookie: '^$"name^'='^$"val^'; path=/;')}



    fn#set_cookie={name=$1;val=$2;extraHttpHeaders=($extraHttpHeaders 'Set-cookie: '^$"name^'='^$"val^'; path=/;')}



    fn#setup_404_handler={handler_body_main=(tpl_handler `{get_lib_file 404.tpl});echo 'Status: 404 Not Found';dprint 'NOT FOUND: '^$SERVER_NAME^$"REQUEST_URI^' - '^$"HTTP_REFERER^' - '^$"HTTP_USER_AGENT}



    fn#setup_404_handler={handler_body_main=(tpl_handler `{get_lib_file 404.tpl});echo 'Status: 404 Not Found';dprint 'NOT FOUND: '^$SERVER_NAME^$"REQUEST_URI^' - '^$"HTTP_REFERER^' - '^$"HTTP_USER_AGENT}



    fn#setup_handlers={if(test -f $local_path^.md){local_file=$local_path^.md;handler_body_main=(md_handler $local_file)};if not if(test -f $local_path^.tpl){local_file=$local_path^.tpl;handler_body_main=(tpl_handler $local_file)};if not if(test -f $local_path^.html){local_file=$local_path^.html;handler_body_main=(html_handler $local_file)};if not if(test -f tpl^$req_path^.tpl)handler_body_main=(tpl_handler tpl^$req_path^.tpl);if not if(test -f $local_path^.txt){local_file=$local_path^.txt;handler_body_main=(txt_handler $local_file)};if(! ~ $#enabled_apps 0)for(a in $enabled_apps)$a^'_init';if(! ~ $#handler_body_main 0){};if not if(~ $local_path */index){handler_body_main=(dir_listing_handler $req_path);if(test -f $sitedir^$req_path^'_header.md')ll_add handlers_body_head md_handler $sitedir^$req_path^'_header.md';if(test -f $sitedir^$req_path^'_footer.md')ll_add handlers_body_foot md_handler $sitedir^$req_path^'_footer.md'};if not if(~ $local_path *.html && test -f $local_path)perm_redirect `{echo $req_path|sed 's/.html$//'};if not if(test -f $local_path)static_file $local_path;if not if(~ $req_path /pub/* && test -f .^$req_path)static_file .^$req_path;if not setup_404_handler}



    fn#setup_handlers={if(test -f $local_path^.md){local_file=$local_path^.md;handler_body_main=(md_handler $local_file)};if not if(test -f $local_path^.tpl){local_file=$local_path^.tpl;handler_body_main=(tpl_handler $local_file)};if not if(test -f $local_path^.html){local_file=$local_path^.html;handler_body_main=(html_handler $local_file)};if not if(test -f tpl^$req_path^.tpl)handler_body_main=(tpl_handler tpl^$req_path^.tpl);if not if(test -f $local_path^.txt){local_file=$local_path^.txt;handler_body_main=(txt_handler $local_file)};if(! ~ $#enabled_apps 0)for(a in $enabled_apps)$a^'_init';if(! ~ $#handler_body_main 0){};if not if(~ $local_path */index){handler_body_main=(dir_listing_handler $req_path);if(test -f $sitedir^$req_path^'_header.md')ll_add handlers_body_head md_handler $sitedir^$req_path^'_header.md';if(test -f $sitedir^$req_path^'_footer.md')ll_add handlers_body_foot md_handler $sitedir^$req_path^'_footer.md'};if not if(~ $local_path *.html && test -f $local_path)perm_redirect `{echo $req_path|sed 's/.html$//'};if not if(test -f $local_path)static_file $local_path;if not if(~ $req_path /pub/* && test -f .^$req_path)static_file .^$req_path;if not setup_404_handler}



    fn#static_file={echo 'Content-Type: '^`{select_mime $1};echo;cat $1;exit}



    fn#static_file={echo 'Content-Type: '^`{select_mime $1};echo;cat $1;exit}



    fn#strip_title_from_md_file={sed '1N; /^.*\n===*$/N; /.*\n===*\n$/d'}



    fn#strip_title_from_md_file={sed '1N; /^.*\n===*$/N; /.*\n===*\n$/d'}



    fn#template={awk -f bin/template.awk $*|rc $rcargs}



    fn#template={awk -f bin/template.awk $*|rc $rcargs}



    fn#tpl_handler={template $*}



    fn#tpl_handler={template $*}



    fn#txt_handler={echo '
    ';<$1 sed 's//\>/g'|fmt -l 82 -j;echo '
    '}



    fn#txt_handler={echo '
    ';<$1 sed 's//\>/g'|fmt -l 82 -j;echo '
    '}



    fn#url_encode={awk '

    BEGIN {

    # We assume an awk implementation that is just plain dumb.

    # We will convert an character to its ASCII value with the

    # table ord[], and produce two-digit hexadecimal output

    # without the printf("%02X") feature.



    EOL = "%0A" # "end of line" string (encoded)

    split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ")

    hextab [0] = 0

    for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0

    if ("'^$"EncodeEOL^'" == "yes") EncodeEOL = 1; else EncodeEOL = 0

    }

    {

    encoded = ""

    for ( i=1; i<=length ($0); ++i ) {

    c = substr ($0, i, 1)

    if ( c ~ /[a-zA-Z0-9.-]/ ) {

    encoded = encoded c # safe character

    } else if ( c == " " ) {

    encoded = encoded "+" # special handling

    } else {

    # unsafe character, encode it as a two-digit hex-number

    lo = ord [c] % 16

    hi = int (ord [c] / 16);

    encoded = encoded "%" hextab [hi] hextab [lo]

    }

    }

    if ( EncodeEOL ) {

    printf ("%s", encoded EOL)

    } else {

    print encoded

    }

    }

    END {

    #if ( EncodeEOL ) print ""

    }

    ' $*}



    fn#url_encode={awk '

    BEGIN {

    # We assume an awk implementation that is just plain dumb.

    # We will convert an character to its ASCII value with the

    # table ord[], and produce two-digit hexadecimal output

    # without the printf("%02X") feature.



    EOL = "%0A" # "end of line" string (encoded)

    split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ")

    hextab [0] = 0

    for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0

    if ("'^$"EncodeEOL^'" == "yes") EncodeEOL = 1; else EncodeEOL = 0

    }

    {

    encoded = ""

    for ( i=1; i<=length ($0); ++i ) {

    c = substr ($0, i, 1)

    if ( c ~ /[a-zA-Z0-9.-]/ ) {

    encoded = encoded c # safe character

    } else if ( c == " " ) {

    encoded = encoded "+" # special handling

    } else {

    # unsafe character, encode it as a two-digit hex-number

    lo = ord [c] % 16

    hi = int (ord [c] / 16);

    encoded = encoded "%" hextab [hi] hextab [lo]

    }

    }

    if ( EncodeEOL ) {

    printf ("%s", encoded EOL)

    } else {

    print encoded

    }

    }

    END {

    #if ( EncodeEOL ) print ""

    }

    ' $*}



    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

    }

    printf "%s", decoded

    }

    '}



    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

    }

    printf "%s", decoded

    }

    '}



    fn#user_controls={echo User: $"logged_user}



    fn#user_controls={echo User: $"logged_user}



    fn#validate_new_user={usr=$1;pass=$2;pass2=$3;_status=();if(~ $"usr '' || ! echo $usr|sed 1q|grep -s '^'^$allowed_user_chars^'+$')_status='Requested user name is invalid, must match: '^$allowed_user_chars^'+';if not if(test -d etc/users/^$usr)_status='Sorry, user name '''^$usr^''' already taken, please pick a different one.';if(~ $"pass '' || ! ~ $"pass $"pass2)_status=($_status 'Provided passwords don''t match.');status=$_status}



    fn#validate_new_user={usr=$1;pass=$2;pass2=$3;_status=();if(~ $"usr '' || ! echo $usr|sed 1q|grep -s '^'^$allowed_user_chars^'+$')_status='Requested user name is invalid, must match: '^$allowed_user_chars^'+';if not if(test -d etc/users/^$usr)_status='Sorry, user name '''^$usr^''' already taken, please pick a different one.';if(~ $"pass '' || ! ~ $"pass $"pass2)_status=($_status 'Provided passwords don''t match.');status=$_status}



    fn#werc_exec_request={site=$SERVER_NAME;base_url=http://^$site;sitedir=$sitesdir^/^$site;master_template=`{get_lib_file default_master.tpl};current_date_time=`{date};req_path=`{echo -n $REQUEST_URI|sed 's/\?.*//; s!//+!/!g; s/%5[Ff]/_/g; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'};req_url=$base_url^$req_path;local_path=$sitedir^$req_path;local_file='';ifs='/' {args=`{echo -n $req_path}};if(~ $REQUEST_METHOD POST){load_post_args;login_user};if(~ $req_path */index)perm_redirect `{echo $req_path|sed 's,/index$,/,'};if(~ $local_path */){if(test -d $local_path)local_path=$local_path^'index';if not if(>/dev/null >[2]/dev/null ls `{basename -d $local_path}^*)perm_redirect `{echo $req_path|sed 's,/+$,,'}};if not if(~ $req_path *^'.' *^',' *^';' *^':')perm_redirect `{echo $req_path|sed 's/[.,;:)]$//'};if not if(test -d $local_path)perm_redirect $req_path^'/';if(! ~ $#args 0)ifs=$NEW_LINE {pageTitle=`{echo $args|sed -e 's/ / - /g' -e 's/([a-z])-([a-z])/\1 \2/g' -e 's/_/ /g'}};cd $sitedir;req_paths_list='/';conf_wd='/';if(test -f _werc/config). _werc/config;for(i in $args){conf_wd=$conf_wd^$i;req_paths_list=($req_paths_list $conf_wd);if(test -d $i){conf_wd=$conf_wd^'/';cd $i;if(test -f _werc/config). _werc/config}};cd $werc_root;if(~ $#perm_redir_to 1)perm_redirect $perm_redir_to;for(l in $perm_redir_patterns){p=$$l;r=$p(1);if(~ $p(2) http://* https://)r='^'^$r;t=`{echo $req_path|sed 's!'^$r^'!'^$p(2)^'!'};if(! ~ $"t '' $req_path)perm_redirect $t};setup_handlers;if(! ~ $local_file ''){t=`{get_file_title $local_file};if(! ~ $"t '')pageTitle=$t};if(~ $"pageTitle '')pageTitle=$"siteTitle^' '^$"siteSubTitle;for(h in $extraHttpHeaders)echo $h;echo 'Content-Type: '^$http_content_type;echo;if(! ~ $#debug 0)dprint $"SERVER_NAME^$"REQUEST_URI - $"HTTP_USER_AGENT - $"REQUEST_METHOD - $"handler_body_main - $"master_template;if(~ $REQUEST_METHOD HEAD)exit;template $headers $master_template|awk_buffer;echo $res_tail}



    fn#werc_exec_request={site=$SERVER_NAME;base_url=http://^$site;sitedir=$sitesdir^/^$site;master_template=`{get_lib_file default_master.tpl};current_date_time=`{date};req_path=`{echo -n $REQUEST_URI|sed 's/\?.*//; s!//+!/!g; s/%5[Ff]/_/g; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'};req_url=$base_url^$req_path;local_path=$sitedir^$req_path;local_file='';ifs='/' {args=`{echo -n $req_path}};if(~ $REQUEST_METHOD POST){load_post_args;login_user};if(~ $req_path */index)perm_redirect `{echo $req_path|sed 's,/index$,/,'};if(~ $local_path */){if(test -d $local_path)local_path=$local_path^'index';if not if(>/dev/null >[2]/dev/null ls `{basename -d $local_path}^*)perm_redirect `{echo $req_path|sed 's,/+$,,'}};if not if(~ $req_path *^'.' *^',' *^';' *^':')perm_redirect `{echo $req_path|sed 's/[.,;:)]$//'};if not if(test -d $local_path)perm_redirect $req_path^'/';if(! ~ $#args 0)ifs=$NEW_LINE {pageTitle=`{echo $args|sed -e 's/ / - /g' -e 's/([a-z])-([a-z])/\1 \2/g' -e 's/_/ /g'}};cd $sitedir;req_paths_list='/';conf_wd='/';if(test -f _werc/config). _werc/config;for(i in $args){conf_wd=$conf_wd^$i;req_paths_list=($req_paths_list $conf_wd);if(test -d $i){conf_wd=$conf_wd^'/';cd $i;if(test -f _werc/config). _werc/config}};cd $werc_root;if(~ $#perm_redir_to 1)perm_redirect $perm_redir_to;for(l in $perm_redir_patterns){p=$$l;r=$p(1);if(~ $p(2) http://* https://)r='^'^$r;t=`{echo $req_path|sed 's!'^$r^'!'^$p(2)^'!'};if(! ~ $"t '' $req_path)perm_redirect $t};setup_handlers;if(! ~ $local_file ''){t=`{get_file_title $local_file};if(! ~ $"t '')pageTitle=$t};if(~ $"pageTitle '')pageTitle=$"siteTitle^' '^$"siteSubTitle;for(h in $extraHttpHeaders)echo $h;echo 'Content-Type: '^$http_content_type;echo;if(! ~ $#debug 0)dprint $"SERVER_NAME^$"REQUEST_URI - $"HTTP_USER_AGENT - $"REQUEST_METHOD - $"handler_body_main - $"master_template;if(~ $REQUEST_METHOD HEAD)exit;template $headers $master_template|awk_buffer;echo $res_tail}



    fn#wman_get_section_desc={>[2]/dev/null cat $wman_man_path^/^$"wman_cp^$1^/0intro*|sed '1,2d; s!intro \\- [Ii]ntroduction to !!; 3q;'}



    fn#wman_get_section_desc={>[2]/dev/null cat $wman_man_path^/^$"wman_cp^$1^/0intro*|sed '1,2d; s!intro \\- [Ii]ntroduction to !!; 3q;'}



    fn#wman_init={ifs=$ifs^'/' {p=`{echo $req_path|sed 's!^'^$wman_base_uri^'!!'}};wman_cat=$p(1);wman_page=$p(2);if(~ $#wman_unix_mode 1){wman_cp='man';wman_pe=.^$"wman_cat};if(! ~ $"wman_cat ''){wman_cat_path=$wman_man_path^/^$"wman_cp^$p(1);if(! ~ $"wman_page ''){wman_page_file=$wman_page^$"wman_pe;if(~ $wman_page intro && test -f $wman_cat_path^/0^$"wman_page_file)wman_page_file=0^$"wman_page_file;wman_page_file=$wman_cat_path^/^$"wman_page_file;x=`{echo $"req_path|sed 's%.*/([^/]+)/'^$"wman_cat^'/'^$"wman_page^'%\1%; s%_% %g'};pageTitle=$wman_page^' page from Section '^$wman_cat^' of the '^$"x^' manual'}};wman_cat_list=`{ls -F $wman_man_path^/*/|sed -e $wman_junk_filter -e 's!.*/([^/]+)/[^/]+$!\1!; /[0-9]+/!d'|sort -un};synth_paths=($wman_base_uri^$wman_cat_list^'/');if(~ $req_path $wman_base_uri && ~ $"handler_body_main '')handler_body_main=(tpl_handler apps/wman/section_list.tpl);if not if(~ $req_path $wman_base_uri^*){if(echo $req_path|grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\+\.]+$')if(test -f $wman_page_file)handler_body_main=(tpl_handler apps/wman/man_page.tpl);if not if(~ $req_path $wman_base_uri^*/)handler_body_main=(tpl_handler apps/wman/page_list.tpl);if not if(~ $p(2) [A-Z]* [0-9][A-Z]*)perm_redirect $wman_base_uri^$p(1)^/^`{echo $p(2)|tr 'A-Z' 'a-z'}};ll_add handlers_body_head tpl_handler apps/wman/search.tpl;if(! ~ $"post_arg_wman_search ''){s=`{echo $post_arg_wman_search|sed 's/[^a-zA-Z0-9\-\.]+//g; s/\.+/./g; 1q'};ifs='' {wman_search_results=`{wman_ls_pages $wman_man_path^/*/*^$"s^*}};if(! ~ $"post_arg_go '' && ~ `{echo -n $wman_search_results|wc -l} 1)post_redirect $wman_base_uri^`{echo $wman_search_results|awk -F/ '{print $(NF-1)"/"$NF}'}}}



    fn#wman_init={ifs=$ifs^'/' {p=`{echo $req_path|sed 's!^'^$wman_base_uri^'!!'}};wman_cat=$p(1);wman_page=$p(2);if(~ $#wman_unix_mode 1){wman_cp='man';wman_pe=.^$"wman_cat};if(! ~ $"wman_cat ''){wman_cat_path=$wman_man_path^/^$"wman_cp^$p(1);if(! ~ $"wman_page ''){wman_page_file=$wman_page^$"wman_pe;if(~ $wman_page intro && test -f $wman_cat_path^/0^$"wman_page_file)wman_page_file=0^$"wman_page_file;wman_page_file=$wman_cat_path^/^$"wman_page_file;x=`{echo $"req_path|sed 's%.*/([^/]+)/'^$"wman_cat^'/'^$"wman_page^'%\1%; s%_% %g'};pageTitle=$wman_page^' page from Section '^$wman_cat^' of the '^$"x^' manual'}};wman_cat_list=`{ls -F $wman_man_path^/*/|sed -e $wman_junk_filter -e 's!.*/([^/]+)/[^/]+$!\1!; /[0-9]+/!d'|sort -un};synth_paths=($wman_base_uri^$wman_cat_list^'/');if(~ $req_path $wman_base_uri && ~ $"handler_body_main '')handler_body_main=(tpl_handler apps/wman/section_list.tpl);if not if(~ $req_path $wman_base_uri^*){if(echo $req_path|grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\+\.]+$')if(test -f $wman_page_file)handler_body_main=(tpl_handler apps/wman/man_page.tpl);if not if(~ $req_path $wman_base_uri^*/)handler_body_main=(tpl_handler apps/wman/page_list.tpl);if not if(~ $p(2) [A-Z]* [0-9][A-Z]*)perm_redirect $wman_base_uri^$p(1)^/^`{echo $p(2)|tr 'A-Z' 'a-z'}};ll_add handlers_body_head tpl_handler apps/wman/search.tpl;if(! ~ $"post_arg_wman_search ''){s=`{echo $post_arg_wman_search|sed 's/[^a-zA-Z0-9\-\.]+//g; s/\.+/./g; 1q'};ifs='' {wman_search_results=`{wman_ls_pages $wman_man_path^/*/*^$"s^*}};if(! ~ $"post_arg_go '' && ~ `{echo -n $wman_search_results|wc -l} 1)post_redirect $wman_base_uri^`{echo $wman_search_results|awk -F/ '{print $(NF-1)"/"$NF}'}}}



    fn#wman_ls_pages={ls $*|sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!'|sort -u}



    fn#wman_ls_pages={ls $*|sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!'|sort -u}



    fn#wman_page_gen={troff -N -man $1|escape_html|sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!&!g'|awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}'}



    fn#wman_page_gen={troff -N -man $1|escape_html|sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!&!g'|awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}'}



    forbidden_uri_chars=[^a-zA-Z0-9_+\-\/\.,:]

    formatter=fltr_cachemarkdown

    handler_body_main=tpl_handler/var/www/sites/suckless.org/wiki/sandbox/test.tpl

    handlers_bar_left=handlers_bar_left_0

    handlers_bar_left_0=nav_tree

    headers=lib/headers.tpl

    home=/

    http_content_type=text/html

    ifs=



    local_file=/var/www/sites/suckless.org/wiki/sandbox/test.tpl

    local_path=/var/www/sites/suckless.org/wiki/sandbox/test

    masterSite=default.suckless.org

    master_template=lib/default_master.tpl

    p=^/gsoc\.htmlhttp://suckless.org/project_ideas

    pageTitle=wiki - sandbox - test

    path=/usr/local/plan9/bin../bin./bin/contrib/bin/usr/bin

    perm_redir_patterns=perm_redir_patterns_39perm_redir_patterns_38perm_redir_patterns_37perm_redir_patterns_36perm_redir_patterns_35perm_redir_patterns_34perm_redir_patterns_33perm_redir_patterns_32perm_redir_patterns_31perm_redir_patterns_30perm_redir_patterns_29perm_redir_patterns_28perm_redir_patterns_27perm_redir_patterns_26perm_redir_patterns_25perm_redir_patterns_24perm_redir_patterns_23perm_redir_patterns_22perm_redir_patterns_21perm_redir_patterns_20perm_redir_patterns_19perm_redir_patterns_18perm_redir_patterns_17perm_redir_patterns_16perm_redir_patterns_15perm_redir_patterns_14perm_redir_patterns_13perm_redir_patterns_12perm_redir_patterns_11perm_redir_patterns_10perm_redir_patterns_9perm_redir_patterns_8perm_redir_patterns_7perm_redir_patterns_6perm_redir_patterns_5perm_redir_patterns_4perm_redir_patterns_3perm_redir_patterns_2perm_redir_patterns_1perm_redir_patterns_0

    perm_redir_patterns_0=^/gsoc\.htmlhttp://suckless.org/project_ideas

    perm_redir_patterns_10=^/common/other_projects(.*)http://suckless.org/other_projects\1

    perm_redir_patterns_11=^/common/patches(.*)http://suckless.org/devel/patches\1

    perm_redir_patterns_12=^/common/project_ideas(.*)http://suckless.org/project_ideas\1

    perm_redir_patterns_13=^/common/style_guide(.*)http://suckless.org/devel/style_guide\1

    perm_redir_patterns_14=^/common/$http://suckless.org/manifest

    perm_redir_patterns_15=^/common$http://suckless.org/manifest

    perm_redir_patterns_16=^/dwm/index.htmlhttp://dwm.suckless.org

    perm_redir_patterns_17=^/dwm/(.*)\.htmlhttp://dwm.suckless.org/\1

    perm_redir_patterns_18=^/dwm/(.*)http://dwm.suckless.org/\1

    perm_redir_patterns_19=^/dwm$http://dwm.suckless.org

    perm_redir_patterns_1=^/gsoc$http://suckless.org/project_ideas

    perm_redir_patterns_20=^/wmii/index.htmlhttp://wmii.suckless.org

    perm_redir_patterns_21=^/wmii/(.*)\.htmlhttp://wmii.suckless.org/\1

    perm_redir_patterns_22=^/wmii/(.*)http://wmii.suckless.org/\1

    perm_redir_patterns_23=^/wmii$http://wmii.suckless.org

    perm_redir_patterns_24=^/libs/index.htmlhttp://libs.suckless.org

    perm_redir_patterns_25=^/libs/(.*)\.htmlhttp://libs.suckless.org/\1

    perm_redir_patterns_26=^/libs/(.*)http://libs.suckless.org/\1

    perm_redir_patterns_27=^/libs$http://libs.suckless.org

    perm_redir_patterns_28=^/programs/index.htmlhttp://tools.suckless.org

    perm_redir_patterns_29=^/programs/(.*)\.htmlhttp://tools.suckless.org/\1

    perm_redir_patterns_2=^/gsoc/i$http://suckless.org/project_ideas

    perm_redir_patterns_30=^/programs/(.*)http://tools.suckless.org/\1

    perm_redir_patterns_31=^/programs$http://tools.suckless.org

    perm_redir_patterns_32=^/wmi/index.htmlhttp://wmi.suckless.org

    perm_redir_patterns_33=^/wmi/(.*)\.htmlhttp://wmi.suckless.org/\1

    perm_redir_patterns_34=^/wmi/(.*)http://wmi.suckless.org/\1

    perm_redir_patterns_35=^/wmi$http://wmi.suckless.org

    perm_redir_patterns_36=^/wiki/dwm$http://dwm.suckless.org

    perm_redir_patterns_37=^/wiki/wmii$http://wmii.suckless.org

    perm_redir_patterns_38=^/index.htmlhttp://suckless.org

    perm_redir_patterns_39=^/(.*)\.htmlhttp://suckless.org/\1

    perm_redir_patterns_3=^/common/broken_programs(.*)http://suckless.org/misc/broken_programs\1

    perm_redir_patterns_4=^/common/bugs(.*)http://suckless.org/devel/bugs\1

    perm_redir_patterns_5=^/common/community(.*)http://suckless.org/community\1

    perm_redir_patterns_6=^/common/cool_programs(.*)http://suckless.org/misc/cool_programs\1

    perm_redir_patterns_7=^/common/donations(.*)http://suckless.org/donations\1

    perm_redir_patterns_8=^/common/dynamic_window_management(.*)http://suckless.org/manifest/dynamic_window_management\1

    perm_redir_patterns_9=^/common/faq(.*)http://suckless.org/devel/faq\1

    pid=12673

    plan9port=/usr/local/plan9

    prompt=% 

    r=^^/gsoc\.html

    rcname=rc

    req_path=/wiki/sandbox/test

    req_paths_list=//wiki/wiki/sandbox/wiki/sandbox/test

    req_url=http://suckless.org/wiki/sandbox/test

    res_tail=

    site=suckless.org

    siteSubTitle=Dedicated to software that sucks less

    siteTitle=suckless.org

    sitedir=/var/www/sites/suckless.org

    sites_menu=home/:suckless.orgcode:hg.suckless.orgdownload:dl.suckless.orgman/:man.suckless.orgdwm/:dwm.suckless.orglibs/:libs.suckless.orgst/:st.suckless.orgstali/:sta.lisurf/:surf.suckless.orgtools/:tools.suckless.orgwmi/:wmi.suckless.org

    sitesdir=/var/www/sites

    status=

    style_color1=#dddddd

    style_color2=#eeeeee

    style_color=#dddddd

    werc_apps=apps/blaghapps/bridgeapps/dirdirapps/helloapps/wman

    werc_root=/var/www/werc-dev

    wman_junk_filter=/(\/(INDEX|\.cvsignore)|\.9p|\.html)$/d; s!/man([0-9]+/[^/]+)$!/\1!;