]> git.plutz.net Git - bookman/commitdiff
initial source commit
authorpaul <paul@plutz.net>
Thu, 23 Feb 2012 19:08:38 +0000 (19:08 +0000)
committerpaul <paul@plutz.net>
Thu, 23 Feb 2012 19:08:38 +0000 (19:08 +0000)
svn path=/trunk/; revision=2

bookmarks.css [new file with mode: 0644]
bookmarks.sh [new file with mode: 0644]
error.sh [new file with mode: 0644]
index.cgi [new file with mode: 0644]

diff --git a/bookmarks.css b/bookmarks.css
new file mode 100644 (file)
index 0000000..8f2ee81
--- /dev/null
@@ -0,0 +1,83 @@
+body {
+  text-align: left;
+  background-color: #EEF;
+  color: #000;
+}
+
+.folder {
+  column-width: 16em;
+    -moz-column-width: 16em;
+    -webkit-column-width: 16em;
+  column-gap: .5em;
+    -moz-column-gap: .5em;
+    -webkit-column-gap: .5em;
+  column-rule: 1px solid #BBB;
+    -moz-column-rule: 1px solid #BBB;
+    -webkit-column-rule: 1px solid #BBB;
+
+  background-color: #FFF;
+  overflow: none;
+
+  padding: .1em 1em .5em 1em;
+  margin: 0em 1em 1em 0em ;
+
+  border-width: 1px;
+  border-style: solid;
+  -moz-border-radius: 1em 1em .5em .5em;
+  -webkit-border-radius: 1em 1em .5em .5em;
+  border-radius: 1em 1em .5em .5em;
+}
+
+.fName {
+  width: 100%;
+  margin: 0px 0px .2em 0px;
+  border-style: none none solid none;
+  border-width: 1px;
+  border-color: #999;
+  text-indent: 1.5em;
+  font-weight: bold;
+  font-size: 1.3em;
+  color: #333;
+  -moz-column-span: all;
+  -webkit-column-span: all;
+  column-span: all;
+}
+.fName a {
+  text-decoration: none;
+  font-weight: normal;
+  color: #333;
+}
+.efName {
+  width: 100%;
+  border-style: none none solid none;
+  border-width: 1px;
+  border-color: #999;
+  display: none;
+  -moz-column-span: all;
+  -webkit-column-span: all;
+  column-span: all;
+}
+.efName a {
+  text-decoration: none;
+}
+
+.edButton {
+  width: 4em;
+  margin: 2px;
+  text-decoration: none;
+}
+
+.bmEdit {
+  display: none;
+  margin: .3em 0em .3em 0em;
+  border-style: solid none solid none;
+  border-width: 1px;
+  border-color: #BBB;
+  -moz-break-inside: avoid;
+  -webkit-break-inside: avoid;
+  break-inside: avoid;
+}
+.bmDisplay img {
+  position: relative;
+  top: 4px;
+}
diff --git a/bookmarks.sh b/bookmarks.sh
new file mode 100644 (file)
index 0000000..af020b4
--- /dev/null
@@ -0,0 +1,109 @@
+#!/bin/zsh
+bdir="bookmarks/${REMOTE_USER}"
+icodir=icodir
+alias wget="/usr/bin/wget -T 5 -t 1 -q -U ''"
+
+if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
+  (head -c "${CONTENT_LENGTH}" | sed 's:&:\n:g'; echo) >$bdir/$(date +%s)
+fi
+
+moveName="$(echo -en "$(sed -rn '/mn=.+&mc=.+/{s:(^|.+&)mn=(.+)(&.+|$):\2:;s:\+: :g;s:%:\\x:g;p}' <<<"$QUERY_STRING")")"
+moveCont="$(echo -en "$(sed -rn '/mn=.+&mc=.+/{s:(^|.+&)mc=(.+)(&.+|$):\2:;s:\+: :g;s:%:\\x:g;p}' <<<"$QUERY_STRING")")"
+[ -n "$moveName" -a -n "$moveCont" ] && move=true || move=false
+
+[ -d "$bdir" ] || mkdir -p "$bdir"
+names=$(sed -rn 's:^name=(.*)$:\1:pg' $bdir/$(ls $bdir |tail -n1))
+hidecmd=$(for each in $(echo $names); do echo "try{hide('e_$each');}catch(e){};"; done)
+showcmd=$(for each in $(echo $names); do echo "try{show('d_$each');}catch(e){};"; done)
+
+delFolder=false
+delBookmark=false
+
+echo "
+<form action='index.cgi' method='post' accept-charset='utf-8'>
+  <div style='display:none;'>
+  qs $QUERY_STRING
+  mn $moveName
+  mc $moveCont
+"
+
+cat $bdir/$(ls $bdir |tail -n1) |while read line; do
+  case "$line" in
+    deleteFolder=*) delFolder=true
+       ;;
+    deleteBookmark=*) delBookmark=true
+       ;;
+    folder=*) echo '<!-- FOLDER -->'
+       fId=$(sed 's:^folder=::' <<<"$line")
+       [ -z "$fId" ] && fId='###'
+       fName="$(echo -ne "$(sed 's:+: :g;s:%:\\x:g' <<<"$fId")")"
+       $delFolder || echo "
+         <input type='hidden' name='title' value='New Bookmark'>
+         <input type='submit' name='content' value='New Bookmark'>
+       </div><div class='folder'>
+         <div class='fName' id='fName_$fId'>
+           <a href='#' onclick='javascript:hide(\"fName_$fId\");show(\"efName_$fId\")'>&rarr;</a>$fName
+         </div><div class='efName' id='efName_$fId'>
+           <a href='#' onclick='javascript:hide(\"efName_$fId\");show(\"fName_$fId\")'>&larr;</a>
+           <input type='submit' value='Rename'><input type='submit' name='deleteFolder' value='Remove'>
+           <input type='text' name='folder' value='$fName'>
+         </div>
+       "
+       delFolder=false
+       $move && echo "
+         <div class='moveButton'>
+           <input type='hidden' name='title' value='$moveName'>
+           <button type='submit' name='content' value='$moveCont'>Move Here</button>
+         </div>
+       "
+       ;;
+    title=*) 
+       bmId=$(sed 's:^title=::' <<<"$line")
+       [ -z "$bmId" ] && bmId='###'
+       bmName="$(echo -ne "$(sed 's:+: :g;s:%:\\x:g' <<<"$bmId")")"
+       ;;
+    content=*)
+       bmLink="$(echo -ne "$(sed 's:^content=::;s:+: :g;s:%:\\x:g' <<<"$line")")"
+       bmBase="$(sed -r 's:^(https?\://[^/]+)/?.*$:\1:' <<<"$bmLink")"
+       bmFav="$(sed -r 's:^(https?\://[^/]+)/?.*$:\1/favicon.ico:' <<<"$bmLink")"
+       bmFavFile="$icodir/$(sed -r 's:^https?\://([^/]+)/?.*$:\1.ico:' <<<"$bmLink")"
+       [ -f "$bmFavFile" ] || (wget -O - "$bmLink" |head -c 4096 |\
+          sed -rn "/<link.*rel=[\"'](shortcut )?icon[\"'].*>/Is:^.*<link.*href=[\"']([^\"']*)[\"'].*$:\1:ip" |\
+          read p && [ -n "$p" ] && (wget -O "$bmFavFile" "$p" || wget -O "$bmFavFile" "$bmBase/$p") ||\
+          wget -O "$bmFavFile" "$bmFav"
+       ) &
+       [ "$bmName" = "$moveName" -a "$bmLink" = "$moveCont" ] && delBookmark=true
+       $delBookmark || echo "
+         <div class='bmDisplay' id='d_$bmId'>
+           <a class='edButton' href='#' onclick='javascript:${hidecmd}${showcmd}show(\"e_$bmId\");hide(\"d_$bmId\");'>&rarr;</a>
+           <img width=16 height=16 src='$bmFavFile'>
+           <a href='$bmLink'>$bmName</a>
+         </div><div class='bmEdit' id='e_$bmId'>
+           <a class='edButton' href='#' onclick='javascript:show(\"d_$bmId\");hide(\"e_$bmId\");'>&larr;</a>
+           <input type='submit' value='Update'><input type='submit' name='deleteBookmark' value='Remove'><br>
+           <a href='?mn=$bmName&mc=$bmLink'>Move Bookmark</a><br>
+           Name: <input type='text' name='title' value='$bmName'><br>
+           Link: <input type='text' name='content' value='$bmLink'>
+         </div>
+       "
+       $delBookmark || ($move && echo "
+         <div class='moveButton'>
+           <input type='hidden' name='title' value='$moveName'>
+           <button type='submit' name='content' value='$moveCont'>Move Here</button>
+         </div>
+       ")
+       delBookmark=false
+       ;;
+    *) echo "<!-- $line -->"
+       ;;
+  esac
+done
+
+echo "
+    <input type='hidden' name='title' value='New Bookmark'>
+    <input type='submit' name='content' value='New Bookmark'>
+  </div>
+  <input type='submit' value='Submit Changes'>
+  <input type='submit' name='folder' value='New Folder'>
+</form>
+"
diff --git a/error.sh b/error.sh
new file mode 100644 (file)
index 0000000..8fa6b50
--- /dev/null
+++ b/error.sh
@@ -0,0 +1,2 @@
+echo 'No user authentication occured.<br>'
+echo 'This does Probably mean, that this service is misconfigured.'
diff --git a/index.cgi b/index.cgi
new file mode 100644 (file)
index 0000000..a0a8490
--- /dev/null
+++ b/index.cgi
@@ -0,0 +1,31 @@
+#!/bin/zsh
+echo 'Content-type: text/html\n'
+
+cat <<NOTES
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Bookmarks!</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <link rel="stylesheet" type="text/css" href="bookmarks.css">
+    <script type="text/javascript">
+    <!--
+    function show(id){
+      document.getElementById(id).style.display = "block";
+    }
+    function hide(id){
+      document.getElementById(id).style.display = "none";
+    }
+    -->
+    </script>
+  </head>
+  <body>
+NOTES
+
+if [ -z "${REMOTE_USER}" ]; then
+  . ./error.sh
+else
+  . ./bookmarks.sh
+fi
+
+echo '</body></html>'