[hackers] diri: new tip (= 8)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Tue, 30 Jan 2007 14:50:01 +0100

changeset: 8:6b598741a995d17d2450ab72fbfc24366f470911
tag: tip
user: arg_AT_suckless.org
date: Tue Jan 30 14:49:08 2007 +0100
files: remove.rc
description:
added removal of diri files

changeset: 7:a8a3ee3a30a9852de502e26d3c3dc3a7add76261
user: arg_AT_suckless.org
date: Tue Jan 30 14:44:10 2007 +0100
files: show.rc
description:
fixed calling remove.rc from show.rc rendering

changeset: 6:3c9ba12f1da19ee0160916df1783905fa0870580
user: arg_AT_suckless.org
date: Tue Jan 30 14:43:29 2007 +0100
files: edit.rc remove.rc save.rc show.rc
description:
some more changes

diff -r 1cb7a17d4644 edit.rc
--- a/edit.rc Tue Jan 30 14:32:52 2007 +0100
+++ b/edit.rc Tue Jan 30 11:27:04 2007 +0100
@@ -1,12 +1,7 @@
 #!/usr/local/plan9/bin/rc
 . /var/www/dirirc
 
-if(test ! $PATH_INFO || echo $PATH_INFO | grep -v -s '^[a-zA-Z0-9_/]+$') {
- echo 'Location: '^$ADDRESS^'/show.rc
- echo
- exit 0
-}
-if(test -d $DIRIDIR/$PATH_INFO) {
+if(~ $PATH_INFO '^[a-zA-Z0-9_/]+$' || test -d $DIRIDIR/$PATH_INFO) {
         echo 'Location: '^$ADDRESS^'/show.rc'^$PATH_INFO
         echo
         exit 0
@@ -43,13 +38,15 @@ Content-Type: text/html
                 <div id="editor">
                         <h1>
 END
+if(test $PATH_INFO) {
         echo $PATH_INFO
+}
 cat <<END
 </h1>
                         <form action="$ADDRESS/save.rc$PATH_INFO" method="post">
                                 <textarea name='text' id='text' cols='80' rows='43'>
 END
-if(test -f $DIRIDIR^'/'^$PATH_INFO^'.diri') {
+if(test $PATH_INFO && test -f $DIRIDIR^'/'^$PATH_INFO^'.diri') {
         cat $DIRIDIR^'/'^$PATH_INFO^'.diri'
 }
 cat <<END
diff -r 1cb7a17d4644 save.rc
--- a/save.rc Tue Jan 30 14:32:52 2007 +0100
+++ b/save.rc Tue Jan 30 11:27:04 2007 +0100
@@ -1,11 +1,5 @@
 #!/usr/local/plan9/bin/rc
 . /var/www/dirirc
-
-if(test ! $PATH_INFO || echo $PATH_INFO | grep -v -s '^[a-zA-Z0-9_/]+$') {
- echo 'Location: '^$ADDRESS^'/show.rc
- echo
- exit 0
-}
 
 fn escape {
         echo 'Location: '^$ADDRESS^'/show.rc'^$PATH_INFO
@@ -13,7 +7,19 @@ fn escape {
         exit 0
 }
 
-if(test -d $DIRIDIR/$PATH_INFO)
+fn mkdirr {
+ ifs='/
+'
+ paths=`{echo $1}
+ prefix=''
+ for(dir in $paths) {
+ if(test ! -d $DIRIDIR^'/'^$prefix^'/'^$dir)
+ mkdir $DIRIDIR^'/'^$prefix^'/'^$dir
+ prefix=$prefix^'/'^$dir
+ }
+}
+
+if(~ $PATH_INFO '^[a-zA-Z0-9_/]+$' || test -d $DIRIDIR/$PATH_INFO)
         escape
 
 for(i in `{sed 's/\&/ /g'})
@@ -24,10 +30,13 @@ if not
 if not
         escape
 
-if(! ~ $password $HASHPASSWD || test ! $text)
+if(! ~ $password $HASHPASSWD)
         escape
 
-/bin/mkdir -p `{basename -d $PATH_INFO}
+if(! test $text)
+ escape
+
+mkdirr `{basename -d $PATH_INFO}
 if(test -f $DIRIDIR^'/'^$PATH_INFO^'.diri')
         mv $DIRIDIR^'/'^$PATH_INFO^'.diri' $DIRIDIR^'/'^$PATH_INFO^'.'^`{date -n}
 echo $text | $URLDECODE > $DIRIDIR^'/'^$PATH_INFO^'.diri'
diff -r 1cb7a17d4644 show.rc
--- a/show.rc Tue Jan 30 14:32:52 2007 +0100
+++ b/show.rc Tue Jan 30 12:00:02 2007 +0100
@@ -27,19 +27,26 @@ fn menu {
 }
 
 fn catpage {
- if(test -f $DIRIDIR^'/'^$PATH_INFO)
- cat $DIRIDIR^'/'^$PATH_INFO
- if not {
- if(test -d $DIRIDIR^'/'^$PATH_INFO) {
- file=`{find $DIRIDIR^'/'^$PATH_INFO -type f | grep '/[a-zA-Z0-9_]+$' | sort | sed 1q}
+ if(test $PATH_INFO) {
+ if(test -f $DIRIDIR^'/'^$PATH_INFO)
+ cat $DIRIDIR^'/'^$PATH_INFO
+ if not {
+ if(test -d $DIRIDIR^'/'^$PATH_INFO) {
+ file=`{find $DIRIDIR^'/'^$PATH_INFO -type f | grep '/[a-zA-Z0-9_]+$' | sort | sed 1q}
+ if(test $file && test -f $file)
+ cat $file
+ }
+ }
+ }
+ if not {
+ file=`{find $DIRIDIR -type f | grep '/[a-zA-Z0-9_]+$' | sort | sed 1q}
                         if(test $file && test -f $file)
                                 cat $file
- }
         }
 }
 
-if(test $PATH_INFO && echo $PATH_INFO | grep -v -s '^[a-zA-Z0-9_/]+$') {
- echo 'Location: '^$ADDRESS^'/show.rc
+if(test $PATH_INFO && ~ $PATH_INFO '^[a-zA-Z0-9_/]+$') {
+ echo 'Location: '^$ADDRESS^'/show.rc'
         echo
         exit 0
 }
@@ -50,8 +57,6 @@ ifs='/
 '
 if(test $PATH_INFO)
         paths=`{echo $PATH_INFO}
-if not
- PATH_INFO=''
 ifs=$tmp
 
 cat <<END
@@ -108,7 +113,7 @@ cat <<END
 cat <<END
                 </div>
                 <div id="page">
- <div id="content" style="max-width: 60em;">
+ <div id="content" style="max-width: 50em;">
 END
 catpage
 cat <<END
diff -r 1cb7a17d4644 remove.rc
--- a/remove.rc Tue Jan 30 14:32:52 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-#!/usr/local/plan9/bin/rc
-. /var/www/dirirc
-
-if(test ! $PATH_INFO || echo $PATH_INFO | grep -v -s '^[a-zA-Z0-9_/]+$') {
- echo 'Location: '^$ADDRESS^'/show.rc
- echo
- exit 0
-}
-
-fn escape {
- echo 'Location: '^$ADDRESS^'/show.rc'^$PATH_INFO
- echo
- exit 0
-}
-
-for(i in `{sed 's/\&/ /g'})
- eval $i
-
-if(test $password) {
- password=`{echo -n $password | $URLDECODE | $HASHCMD}
- if(! ~ $password $HASHPASSWD || test ! $text)
- escape
- if(test -e $DIRIDIR^'/'^$PATH_INFO)
- /bin/rm -rf $DIRIDIR^'/'^$PATH_INFO
- echo 'Location: '^$ADDRESS^'/show.rc'
- echo
- exit 0
-}
-cat <<END
-Content-Type: text/html
-
-<html>
- <head>
- <title>$TITLE</title>
- <meta name="author" content="Anselm R. Garbe">
- <meta name="searchtitle" content="dwm wmii suck less">
- <meta name="keywords" content="x11 dwm wmi wmii dmenu slock suck less window manager xlib">
- <meta name="description" content="dynamic window manager improved 2">
- <meta name="revisit-after" content="2 days">
- <meta name="audience" content="all">
- <meta name="content-language" content="en">
- <meta name="copyright" content="(C)opyright 2006-2007 by Anselm R. Garbe">
- <meta name="robots" content="noindex,nofollow">
- <style type="text/css">
- body { background-color: #555; color: #ddd; font-family: sans-serif; margin: 0px 0px 0px 0px; max-width: 80em; }
- img { border: 0px; /* top right bartom left */ }
- a { color: #9cf; }
- input { background-color: #333; border: 1px solid #555; color: #ddd; }
- div#editor{ background-color: #333; border: 0px; color: #ddd; padding: 2%; width: 96%; }
- div#bar { background-color: #222; border: 0px; clear: both; padding: 5px 1% 5px 0px; text-align: right; width: 99%; }
- </style>
- </head>
- <body>
- <div id="bar">
- <i>$SLOGAN</i>
- </div>
- <div id="editor">
- <h1>
-END
- echo $PATH_INFO
-cat <<END
-</h1>
- <form action="$ADDRESS/remove.rc$PATH_INFO" method="post">
- <p>Please confirm removing '$PATH_INFO' through entering the password.</p>
- <p align="right">
- <b>Password:</b> <input type='password' name='password' size='20'/>
- <input type='submit' value='Save'/><br />
- </p>
- </form>
- </div>
- <div id="bar">
- <small>&copy Copyright 2007 Anselm R. Garbe Impressum</small>
- </div>
- </body>
-</html>
-END
Received on Tue Jan 30 2007 - 14:50:01 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:46 UTC