diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/blagh/app.rc | 142 | ||||
-rw-r--r-- | apps/blagh/atom.tpl | 58 | ||||
-rwxr-xr-x | apps/blagh/convert.rc | 20 | ||||
-rw-r--r-- | apps/blagh/jsonfeed.tpl | 35 | ||||
-rw-r--r-- | apps/blagh/new_post.tpl | 11 | ||||
-rw-r--r-- | apps/blagh/rss20.tpl | 43 | ||||
-rwxr-xr-x | apps/bridge/app.rc | 103 | ||||
-rwxr-xr-x | apps/bridge/comments_list.tpl | 13 | ||||
-rwxr-xr-x | apps/bridge/foot.tpl | 37 | ||||
-rwxr-xr-x | apps/dirdir/app.rc | 40 | ||||
-rwxr-xr-x | apps/dirdir/edit.tpl | 25 | ||||
-rwxr-xr-x | apps/dirdir/sidebar_controls.tpl | 3 | ||||
-rw-r--r-- | apps/duckduckgo/HOWTO | 20 | ||||
-rwxr-xr-x | apps/duckduckgo/app.rc | 30 | ||||
-rw-r--r-- | apps/duckduckgo/footer.inc.sample | 3 | ||||
-rwxr-xr-x | apps/hello/app.rc | 10 | ||||
-rwxr-xr-x | apps/paste/app.rc | 45 | ||||
-rwxr-xr-x | apps/wman/app.rc | 89 | ||||
-rwxr-xr-x | apps/wman/man_page.tpl | 3 | ||||
-rwxr-xr-x | apps/wman/page_list.tpl | 11 | ||||
-rwxr-xr-x | apps/wman/search.tpl | 20 | ||||
-rwxr-xr-x | apps/wman/section_list.tpl | 11 |
22 files changed, 772 insertions, 0 deletions
diff --git a/apps/blagh/app.rc b/apps/blagh/app.rc new file mode 100644 index 0000000..c63689d --- /dev/null +++ b/apps/blagh/app.rc @@ -0,0 +1,142 @@ +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 blagh_init { + if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*) { + blagh_uri=`{echo $req_path | sed 's,(/[bB]log/).*,\1,'} + blagh_dirs=( . ) + } + + # Should not match sub-dirs! + if(! ~ $#blagh_dirs 0) { + # && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs} + 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=`{datei|sed 's,-,/,g'} + if not + post_date=$post_arg_date + ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>' + } + + if(~ $req_path $blagh_uri) { + handler_body_main=blagh_body + u=$blagh_uri'index' + extraHeaders=$"extraHeaders ^ \ +'<link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" /> +<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" /> +<link rel="alternate" type="application/json" title="JSON" href="'$"blagh_uri'feed.json" />' + } + 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^feed.json) + blagh_setup_feed_handlers jsonfeed.tpl 'application/json; 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 # Should we allow tempalte override? +} + +fn blagh_body { + if (! ~ $"blogTitle '') + echo '<h1>'$"blogTitle'</h1>' + + # Direct links to feeds are disabled because they are not very useful, add clutter and might waste pagerank. + # An user can add this on their own using handlers_body_head anyway. + #echo '<div style="text-align:right">(<a href="index.rss">RSS Feed</a>|<a href="index.atom">Atom Feed</a>)</div>' + + # XXX Not sure why this fixes issues with blog setup, probably bug in fltr_cache! + 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!'} + sed '1s!.*^') ('^$l(1)^')!' < $p/index.md + echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed. + } | $formatter + # XXX BUG! Markdown [references] break because multiple markdown documents are merged. Should format each blog post independently. + # TODO: use fltr_cache directly, that can fix the previous bug plus provide a perf boost by caching title generation. +} + +fn get_post_list { + # /./->/|/ done to sort -t| and order by date + # Note: $paths in blagh_dirs should not contain '/./' or '|' + ls -F $*^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/ >[2]/dev/null | sed -n '/'^$forbidden_uri_chars^'/d; s,/\./,/|/,; /\/$/p' | sort -r '-t|' +1 | sed -e 's,/+\|/+,/,' -e $conf_max_posts_per_page^'q' +} + +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^'''') # XXX Should make semantic check. + + if(~ $#_status 0) { + umask 002 # Let group write + if(! ~ $"bpid '') + bpid=`{echo -n '-'^$bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'} + + ddir=$blagh_root^$bpdate^'/' + n=`{ls $ddir >[2]/dev/null |wc -l} + + mkdir -p $ddir/$"n^$"bpid/ + { + if(! ~ $"bptitle '') { + echo $bptitle + echo '=========================================' + } + # TODO: Enable metadata + #echo '* Posted:' `{date} + #if(! ~ $#logged_user 0) + # echo '* Author: '$logged_user + echo + echo $bptext + }> $ddir/$"n^$"bpid/index.md + + # Experimental support for http://pubsubhubbub.googlecode.com/ + 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 + hget -d -h -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub >[1=2] & + } + } + status=$_status +} + +fn strip_title_from_md_file { + sed '1N; /^.*\n===*$/N; /.*\n===*\n$/d' +} diff --git a/apps/blagh/atom.tpl b/apps/blagh/atom.tpl new file mode 100644 index 0000000..97c665f --- /dev/null +++ b/apps/blagh/atom.tpl @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8"?> + +%{ +# See for more info:http://www.tbray.org/ongoing/When/200x/2005/07/27/Atomic-RSS +fn statpost { + f = $1 + + post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!'}}^'/' + title=`{read $f/index.md} + by=`{ls -m $f | sed 's/^\[//g; s/].*$//g' >[2]/dev/null} + ifs=() { summary=`{cat $f/index.md | strip_title_from_md_file | ifs=$difs {$formatter} } } +} +# rfc3339 date when feed was last updated. +fupdated = `{ndate -a `{date `{mtime `{ls $blagh_root$blagh_dirs/[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/[0-9] | tail -1} | awk '{print $1}'}}} +%} + +<feed xmlns="http://www.w3.org/2005/Atom" + xmlns:thr="http://purl.org/syndication/thread/1.0"> + +% if(! ~ $"conf_blog_pubsubdub_hub '') { +% echo '<link rel="hub" href="'$conf_blog_pubsubdub_hub'" />' +% } + + <link rel="self" href="%($base_url^$req_path%)"/> + <id>%($base_url^$req_path%)</id> + <icon><![CDATA[/favicon.ico]]></icon> + + <title><![CDATA[%($siteTitle%)]]></title> + <subtitle><![CDATA[%($siteSubTitle%)]]></subtitle> + + <updated>%($fupdated%)</updated> + <link href="."/> + +% for(f in `{get_post_list $blagh_root$blagh_dirs}) { +% statpost $f + + <entry> +% # Maybe we should be smarter, see: http://diveintomark.org/archives/2004/05/28/howto-atom-id, example: <id>tag:intertwingly.net,2004:2899</id> + <id>%($post_uri%)</id> + <link href="%($post_uri%)"/> + <title><![CDATA[%($title%)]]></title> +% # <link rel="replies" href="2899.atom" thr:count="0"/> + <author><name><![CDATA[%($by%)]]></name></author> + + <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"> + <![CDATA[%($summary%)]]> + </div></content> + +% # rfc3339 date when entry was last updated. +% eupdated=`{ndate -a `{date `{mtime $f | awk '{print $1}'}}} + <updated>%($eupdated%)</updated> + </entry> + +% } + +</feed> + +% exit diff --git a/apps/blagh/convert.rc b/apps/blagh/convert.rc new file mode 100755 index 0000000..0640805 --- /dev/null +++ b/apps/blagh/convert.rc @@ -0,0 +1,20 @@ +#!/usr/bin/env rc + +path=($PLAN9/bin/ $path) + +for(p in *.md) { + echo + echo '=========================' + echo p $p + pp=`{echo $p | sed 's/^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])[\-_](.*).md$/\1 \2 \3 \4/' } + echo pp $pp + + d=$pp(1)^'/'^$pp(2)^'/'^$pp(3)^'/'^$pp(4)^'/' + + mkdir -p $d + echo $pp(4) | sed -e 's/^[0-9]_//; s/_/ /g;' > $d/index.md + echo '=================================' >> $d/index.md + echo >> $d/index.md + cat $p >> $d/index.md + +} diff --git a/apps/blagh/jsonfeed.tpl b/apps/blagh/jsonfeed.tpl new file mode 100644 index 0000000..fd97ed4 --- /dev/null +++ b/apps/blagh/jsonfeed.tpl @@ -0,0 +1,35 @@ +{ +"version": "https://jsonfeed.org/version/1", +"title": "%($siteTitle%)", +"home_page_url": "%($"base_url%)", +"feed_url": "%($"base_url^$"req_path%)", +"items": [ +%{ +fn statpost { + f = $1 + post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!'}}^'/' + title=`{read $f/index.md} + #ifs=() { summary=`{cat $f/index.md | crop_text 1024 ... | $formatter } } + ifs=() { summary=`{cat $f/index.md | strip_title_from_md_file | ifs=$difs {$formatter| sed 's/"/\\"/g' | tr -d '\012' } } } +} +%} +% #for(f in `{get_post_list $blagh_root$blagh_dirs}) { +% +% postlist=`{get_post_list $blagh_root$blagh_dirs} +% postcount=0 +% for(f in $postlist) { +% statpost $f + { + "id": "%($post_uri%)", + "url": "%($post_uri%)", + "title": "%($title%)", + "content_html": "%($summary%)" + } +% postcount = `{echo $postcount 1+p | dc} +% if (! ~ $#postlist $postcount) { echo , } +% } +] +} + +% exit + diff --git a/apps/blagh/new_post.tpl b/apps/blagh/new_post.tpl new file mode 100644 index 0000000..bd521c4 --- /dev/null +++ b/apps/blagh/new_post.tpl @@ -0,0 +1,11 @@ +<div> +% notices_handler +<form method="POST"><fieldset> + <legend>Submit a new blog post</legend> + <textarea cols="94" rows=16" name="body">%($"post_arg_body%)</textarea><br /> + <label>Title: <input size="64" type="text" name="title" value="%($"post_arg_title%)" /></label> + <label>Id: <input size="8" type="text" name="id" value="%($"post_arg_id%)" /></label> + <label>Date: <input size="10" maxlength="10" type="text" name="date" value="%($"post_date%)" /></label> + <input type="submit" value="Post" /> +</fieldset></form> +</div> diff --git a/apps/blagh/rss20.tpl b/apps/blagh/rss20.tpl new file mode 100644 index 0000000..0cba818 --- /dev/null +++ b/apps/blagh/rss20.tpl @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> + +%{ +fn statpost { + f = $1 + post_uri = `{echo $f | sed 's,^'$sitedir',,'} + title=`{read $f/index.md} + post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!'}}^'/' + by=`{ls -m $f | sed 's/^\[//g; s/].*$//g' >[2]/dev/null} + ifs=() {summary=`{ cat $f/index.md |strip_title_from_md_file| ifs=$difs {$formatter | escape_html} }} +} + +%} + +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> + <channel> + <atom:link href="%($base_url^$req_path%)" rel="self" type="application/rss+xml" /> + <title><![CDATA[%($siteTitle%)]]></title> + <link>%($base_url^$req_path%)</link> + <description><![CDATA[%($blogDesc%)]]></description> + <language>en-us</language> + <generator><![CDATA[Tom Duff's rc, and Kris Maglione's clever hackery]]></generator> +%{ + # <webMaster>uriel99+rss@gmail.com (Uriel)</webMaster> + # rfc2822 last time channel content changed. + lbd=`{ndate -m `{date `{mtime `{ls $blagh_root$blagh_dirs/[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/[0-9] | tail -1} | awk '{print $1}'}}} + echo '<lastBuildDate>'$"lbd'</lastBuildDate>' + # rfc2822 publication date for content in the channel. + pubdate=`{ndate -m} + for(f in `{get_post_list $blagh_root$blagh_dirs}){ + statpost $f +%} + <item> + <title><![CDATA[%($title%)]]></title> + <author><![CDATA[%($by%)@noreply.cat-v.org (%($by%))]]></author> + <link>%($post_uri%)</link> + <guid isPermaLink="true">%($post_uri%)</guid> + <pubDate>%($pubdate%)</pubDate> + <description> %($summary%) </description> + </item> +% } + </channel> +</rss> diff --git a/apps/bridge/app.rc b/apps/bridge/app.rc new file mode 100755 index 0000000..40477ba --- /dev/null +++ b/apps/bridge/app.rc @@ -0,0 +1,103 @@ +comment_file_types=(md html) + +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 bridge_init { + if(~ $#enable_comments 1 && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|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 '<hr><p>To post a comment you need to <a href="/_users/login">login</a> first.</p>' + } +} + +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 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' + # XXX: This doesn't work because we then do a redirect. + 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' # Anonymous + 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} # FIXME Obvious race + mkdir -m 775 -p $dir && + echo $u > $dir/user && + echo $current_date_time > $dir/posted && + echo $post_arg_comment_text > $dir/body + _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 +} diff --git a/apps/bridge/comments_list.tpl b/apps/bridge/comments_list.tpl new file mode 100755 index 0000000..03e0ddc --- /dev/null +++ b/apps/bridge/comments_list.tpl @@ -0,0 +1,13 @@ +<hr> +<h2>Comments</h2> + +% for(c in `{ls $comments_dir/}) { +% if(test -s $c/body) { + <div class="comment"> + <h5>By: <i>%(`{cat $c/user}%)</i></b> (%(`{cat $c/posted}%)) + </h5> +% cat $c/body | escape_html | sed 's,$,<br>,' + <hr></div> +% } +% } + diff --git a/apps/bridge/foot.tpl b/apps/bridge/foot.tpl new file mode 100755 index 0000000..0dad21d --- /dev/null +++ b/apps/bridge/foot.tpl @@ -0,0 +1,37 @@ +<hr> + +% notices_handler +<form action="" method="post"> + <textarea name="comment_text" id="comment_text" cols="80" rows="16">%($"saved_comment_text%)</textarea> + <br> + <input type="submit" name="bridge_post" value="Post a comment"> + +% if(~ $#logged_user 0) { +% if(~ $#allow_new_user_comments 1) { + <label>New user name: + <input type="text" name="comment_user" value="%($"post_arg_comment_user%)"> + </label> + + <label>Password: + <input type="password" name="comment_passwd" value=""> + </label> + + <label>Repeat password: + <input type="password" name="comment_passwd2" value=""> + </label> + <div style="font-size: 70%"> + Enter your desired user name/password and after your comment has been reviewed by an admin it will be posted and your account will be enabled. If you are already registered please <a href="/_users/login">login</a> before posting. + </div> +% } +% if not if(~ $#bridge_anon_comments 1) { + <label>Is <a href="http://glenda.cat-v.org">Glenda a cute bunny</a>? + <select name='ima_robot'> + <option value="yes">No</option> + <option value="not">Yes</option> + <option value="foobar">I hate bunnies!</option> + <option value="robot">I'm a robot!</option> + </select> + </label> +% } +% } +</form> diff --git a/apps/dirdir/app.rc b/apps/dirdir/app.rc new file mode 100755 index 0000000..1aa9cbd --- /dev/null +++ b/apps/dirdir/app.rc @@ -0,0 +1,40 @@ +fn conf_enable_wiki { + enable_wiki=yes + wiki_editors_groups=$* + conf_enable_app dirdir +} + +fn dirdir_init { + if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups) { + lp=$local_path + # werc.rc doesn't append /index when $local_path doesn't exist + # maybe it should, but for now we can fix it up here. + 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 save_page { + dirdir_verdir=$dirdir_dir/^`{date -n}^/ + mkdir -p $dirdir_verdir + umask 002 + + # XXX Use a tmp file and mv(1) to ensure updates are atomic? + echo $logged_user > $dirdir_verdir/author + echo $post_arg_edit_text > $dirdir_verdir/data + echo $post_arg_edit_text > $dirdir_file + + post_redirect $base_url^$req_path + #notify_notes='Saved <a href="'$"req_path'">'$"req_path'</a>!' +} diff --git a/apps/dirdir/edit.tpl b/apps/dirdir/edit.tpl new file mode 100755 index 0000000..1a5b206 --- /dev/null +++ b/apps/dirdir/edit.tpl @@ -0,0 +1,25 @@ +<div> + <h1>Editing: <a href="%($req_path%)">%($req_path%)</a></h1> + <br> + <form action="" method="POST"> + <textarea name="edit_text" id="edit_text" cols="80" rows="43">%{ +# FIXME Extra trailing new lines get added to the content somehow, should avoid it. + if(~ $#post_arg_edit_text 0 && test -f $dirdir_file) + cat $dirdir_file | escape_html + if not + echo -n $post_arg_edit_text | escape_html + + %}</textarea> + <br> + <input type="submit" name="dirdir_save" value="Save"> + <input type="submit" name="dirdir_preview" value="Preview"> + <small>DirDir documents are written using <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.</small> + </form> +</div> + +% if(! ~ $"post_arg_dirdir_preview '') { + <h2>Preview:</h2> + <div id="preview"> +% echo $post_arg_edit_text | $formatter + </div> +% } diff --git a/apps/dirdir/sidebar_controls.tpl b/apps/dirdir/sidebar_controls.tpl new file mode 100755 index 0000000..a897fc1 --- /dev/null +++ b/apps/dirdir/sidebar_controls.tpl @@ -0,0 +1,3 @@ +<form action="" method="POST"> +<input type="submit" name="dirdir_edit" value="Edit page" /> +</form> diff --git a/apps/duckduckgo/HOWTO b/apps/duckduckgo/HOWTO new file mode 100644 index 0000000..8bb952c --- /dev/null +++ b/apps/duckduckgo/HOWTO @@ -0,0 +1,20 @@ +The default path for site search is /_search/. Assuming you want to keep +that default, you could enable site search like so: + + +mkdir -p /www/werc/sites/MYSITE/_search/_werc/ +echo 'conf_enable_duckduckgo' > /www/werc/sites/MYSITE/_search/_werc/config +mkdir -p /www/werc/sites/MYSITE/_werc/lib/ +cp /www/werc/apps/duckduckgo/footer.inc.sample /www/werc/sites/MYSITE/_werc/lib/footer.inc + +Searches will POST to /_search/ and from there get redirected to Duck Duck +Go with a site:$SERVER_NAME prefix. To have the search path URL be some- +thing different, you'll have to edit line 23 of app.rc to point to the new +path. + +TODO: +* Make it automatically work no matter which directory the app is enabled in. +* OR make the search path a configuration option. +* Provide a template for non-footer deployment +* Enable the search path itself to serve a search form to GET requests + diff --git a/apps/duckduckgo/app.rc b/apps/duckduckgo/app.rc new file mode 100755 index 0000000..72dd0ec --- /dev/null +++ b/apps/duckduckgo/app.rc @@ -0,0 +1,30 @@ +fn conf_enable_duckduckgo { + enable_duckduckgo=yes + conf_enable_app duckduckgo + pageTitle='Site Search' +} + + +fn duckduckgo_init { + get_post_args q + if (! ~ $#q 0) { + redirect_string = 'https://duckduckgo.com/?q=site:'$SERVER_NAME^'+'^$"q + http_redirect $redirect_string '302 Found' + } + if not { + handler_body_main='duckduckgo_body' + } +} + +fn duckduckgo_body { + echo ' +<h1>Site search</h1> +<h2>using DuckDuckGo</h2> +<form action="/_search/" method="POST"> +<label for="searchtext">Site search:</label> +<input type="text" id="searchtext" name="q" placeholder="Search text..."> +<input type="submit" value="Search"> +</form>' + +} + diff --git a/apps/duckduckgo/footer.inc.sample b/apps/duckduckgo/footer.inc.sample new file mode 100644 index 0000000..4dd671d --- /dev/null +++ b/apps/duckduckgo/footer.inc.sample @@ -0,0 +1,3 @@ +<div><a href="http://werc.cat-v.org">Powered by werc</a></div> + +<div><form action="/_search/" method="POST"><label for="searchtext">Site search:</label> <input type="text" id="searchtext" name="q" placeholder="Enter search text..."><input type="submit" display="Search"></form></div> diff --git a/apps/hello/app.rc b/apps/hello/app.rc new file mode 100755 index 0000000..e6faaa8 --- /dev/null +++ b/apps/hello/app.rc @@ -0,0 +1,10 @@ +fn hello_init { + if(~ $req_path /hello) { + handler_body_main='hello_body' + pageTitle='Hi title!' + } +} + +fn hello_body { + echo 'Hello world!' +} diff --git a/apps/paste/app.rc b/apps/paste/app.rc new file mode 100755 index 0000000..af0c76d --- /dev/null +++ b/apps/paste/app.rc @@ -0,0 +1,45 @@ +fn conf_enable_wercpaste { + paste_url=$conf_wd + if (~ $#paste_dir 0) { paste_dir=`{pwd} } + conf_enable_app wercpaste +} + +fn wercpaste_init { + if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste + now=`{ date -n } + cksum=`{ echo $"post_arg_paste | sum | awk '{ print $1 }' } + if (~ $cksum '1715a8eb' ) { # empty paste; discard + post_redirect $base_url^$paste_url + } + if not { # save and redirect + # TODO: stop using echo + # env var size limit is 16kb, this thing dies with larger input. + echo $"post_arg_paste > $paste_dir^/^$now^.^$cksum + # uncomment the following line to redirect to the pasted file + #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 + } + } + if not { # show a paste if there is one + if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { + echo 'Content-type: text/plain'; echo ''; exec cat $werc_root/$local_path + } + } + +# drop a textbox + if (~ $REQUEST_METHOD GET ) { handler_body_main='begforpaste' } + +} + +fn begforpaste { + echo '<article class="pastebox"> + <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> + ' +} diff --git a/apps/wman/app.rc b/apps/wman/app.rc new file mode 100755 index 0000000..8f0a150 --- /dev/null +++ b/apps/wman/app.rc @@ -0,0 +1,89 @@ +fn conf_enable_wman { + wman_tmac=an + wman_base_uri=$conf_wd + wman_man_path=$* + if(~ $#wman_man_path 0) + wman_man_path=$wman_base_uri + conf_enable_app wman +} + +wman_junk_filter='/(\/(INDEX|\.cvsignore|_.*)|\.9p|\.html)$/d; s!/man([0-9]+/[^/]+)$!/\1!; ' +fn wman_ls_pages { + ls $* \ + | sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!' \ + | sort -u +} +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 + # Hack to handle 0intro files. + 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^*) { + #^*/[a-z0-9]*[a-z]* $wman_base_uri^*/*[a-z]*[a-z0-9] $wman_base_uri^*/[a-z]) + if(echo $req_path | grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\+\.]+$') + if(test -f $wman_page_file) # Check for 404 + 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]*) # Correct badly capitalized links + perm_redirect $wman_base_uri^$p(1)^/^`{echo $p(2) |tr 'A-Z' 'a-z'} + } + + # Search + 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_get_section_desc { + cat $wman_man_path/^$"wman_cp^$1/0intro* >[2]/dev/null| sed '1,2d; s!intro \\- [Ii]ntroduction to !!; 3q;' +} + +fn wman_page_gen { + #troff -manhtml $1| troff2html -t 'Plan 9 from User Space' + troff -N -m$wman_tmac $1 | wman_out_filter +} + +fn wman_out_filter { + wman_default_out_filter +} + +fn wman_default_out_filter { + # col -x syntax is the same for UNIX and Plan 9. + escape_html \ + | sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!<a href="../\2/\1">&</a>!g' \ + | awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}' \ + | col -x +} + + diff --git a/apps/wman/man_page.tpl b/apps/wman/man_page.tpl new file mode 100755 index 0000000..945e23a --- /dev/null +++ b/apps/wman/man_page.tpl @@ -0,0 +1,3 @@ +<pre> +% wman_page_gen $wman_page_file +</pre> diff --git a/apps/wman/page_list.tpl b/apps/wman/page_list.tpl new file mode 100755 index 0000000..b98600d --- /dev/null +++ b/apps/wman/page_list.tpl @@ -0,0 +1,11 @@ +% d=`{wman_get_section_desc $wman_cat} +<h1>Manual pages - Section %($wman_cat%): %($"d%)</h1> + +<ul style="float:left"> +%{ +wman_ls_pages $wman_cat_path \ + | awk -F/ '{ print "<li><a href=\""$(NF)"\">"$(NF)"</a></li>" } + NR%20 == 0 { print "</ul><ul style=\"float: left\">" }' +%} +</ul> + diff --git a/apps/wman/search.tpl b/apps/wman/search.tpl new file mode 100755 index 0000000..a6c59e4 --- /dev/null +++ b/apps/wman/search.tpl @@ -0,0 +1,20 @@ +<form action="" method="POST"> +<fieldset> + <input type="text" name="wman_search" value="%($"s%)" /> + <input type="submit" name="go" value="Feel Lucky" /> + <input type="submit" value="Search" /> + +% if(! ~ $"post_arg_wman_search '') { +% if(~ $"wman_search_results '') { + No matches found for <i>'%($post_arg_wman_search%)'</i>. +% } +% if not { + <ul> +% echo $wman_search_results|awk -F/ '$(NF-1) ~ "^[0-9]+$" {printf "<li><a href=\"'$wman_base_uri'%s/%s\" />%s(%s)</a></li>", $(NF-1),$NF, $NF, $(NF-1)}' + </ul> +% } +% } + +</fieldset> +</form> + diff --git a/apps/wman/section_list.tpl b/apps/wman/section_list.tpl new file mode 100755 index 0000000..299d613 --- /dev/null +++ b/apps/wman/section_list.tpl @@ -0,0 +1,11 @@ +<h1>Manual Sections</h1> + +<ul style="text-transform: capitalize;"> +% for(c in $wman_cat_list) { + <li><a href="%($c%)/"><b>Section: %($c%)</b></a> +% wman_get_section_desc $c +% if(~ $status '' '|') +% echo '(<a href="'$c'/intro">intro</a>)' + </li> +% } +</ul> |