]> git.plutz.net Git - busy/commitdiff
introduced simple acl engine
authorpaul <paul@plutz.net>
Sun, 30 Oct 2011 16:26:10 +0000 (16:26 +0000)
committerpaul <paul@plutz.net>
Sun, 30 Oct 2011 16:26:10 +0000 (16:26 +0000)
svn path=/trunk/; revision=18

Home.page
Tasks.page
auth/acl.sh [new file with mode: 0755]
auth/develop.user [deleted file]
index.cgi
session.cgi

index ba0fbe263358c2f2443585528b0c7015f27ec816..8f9d9dcb2a59d31d73a26926f680d20b5f39a451 100644 (file)
--- a/Home.page
+++ b/Home.page
@@ -2,6 +2,10 @@
 search="$(egrep -o '(^|&)(s=).+(&|$)' <<<"${QUERY_STRING}" |sed -r 's:^&?s=::;s:\+: :g;s:%:\\x:g')"
 search="$(echo -e "${search}" |sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' |head -n1)"
 
+[ -z "$ACL_EDITINTRO" ] && ACL_EDITINTRO=false
+[ -z "$ACL_ADDNEWS" ] && ACL_ADDNEWS=false
+[ -z "$ACL_EDITNEWS" ] && ACL_EDITNEWS=false
+
 cat <<WikiEND
   <div id="LEFT">
     <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
@@ -29,10 +33,10 @@ cat <<HomeEND
     <div id="INTRO">
       <div id="introtext"><div class="wikitext">
       $([ -r "Home/intro" ] && _wiki "Home/intro")
-      $($ADM && echo "<hr><a class='function' href='#' onclick='javascript:hide_screen(\"introtext\");show_screen(\"introedit\");'>Edit</a>" )
+      $($ACL_EDITINTRO && echo "<hr><a class='function' href='#' onclick='javascript:hide_screen(\"introtext\");show_screen(\"introedit\");'>Edit</a>" )
       </div></div>
 HomeEND
-$ADM && cat <<HomeEND
+$ACL_EDITINTRO && cat <<HomeEND
       <div id="introedit" style="display: none;">
         <form action="/write/introedit.cgi?i=intro" method="post" accept-charset="UTF-8">
           <textarea name="text" rows="10">$([ -r "Home/intro" ] && cat Home/intro)</textarea><br>
@@ -43,7 +47,7 @@ $ADM && cat <<HomeEND
 HomeEND
 echo '</div>'
 
-$ADM && cat <<HomeEND
+$ACL_ADDNEWS && cat <<HomeEND
   <div class="NEWS">
     <a id="new" class='function' href='#add' onclick='javascript:hide_screen("new");show_screen("add");'>Add News</a>
     <div id="add" style="display: none;">
@@ -62,10 +66,10 @@ stat -c '' Home/<0000000000-9999999999>_<000-999>.news && for each in $(ls -c Ho
     <div class="NEWS">
       <div id="news_$info"><div class="wikitext">
       $([ -r "$each" ] && _wiki "$each")
-      $($ADM && echo "<hr><a class='function' href='#edit_$info' onclick='javascript:hide_screen(\"news_$info\");show_screen(\"edit_$info\");'>Edit</a>" )
+      $($ACL_EDITNEWS && echo "<hr><a class='function' href='#edit_$info' onclick='javascript:hide_screen(\"news_$info\");show_screen(\"edit_$info\");'>Edit</a>" )
       </div></div>
 HomeEND
-  $ADM && cat <<HomeEND
+  $ACL_EDITNEWS && cat <<HomeEND
       <div id="edit_$info" style="display: none;">
         <form action="/write/introedit.cgi?i=$info" method="post" accept-charset="UTF-8">
           <textarea name="text" rows="10">$([ -r "$each" ] && cat $each)</textarea><br>
index 7ca263d5b08cf9901e8630af5bac2d3bb149493d..333efe43a0fe3ef8b3b739d055fc5132784b1f85 100644 (file)
@@ -7,6 +7,8 @@ search="$(echo -e "${search}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
 new="$(sed -r 's:(^|.*&)n=(.*)|.*:\2:;s:&.*::;s:\+: :g;s:%:\\x:g' <<<"${QUERY_STRING}")"
 new="$(echo -e "${new}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
 
+[ -z "$ACL_CREATETASK" ] && ACL_CREATETASK=false
+
 cat <<TasksEND
   <div id="LEFT">
     <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
@@ -16,6 +18,7 @@ cat <<TasksEND
     </form>
     <hr>
 TasksEND
+#search results
 if [ -n "$search" ]; then
   echo "<h1>Tasks search results for: $search</h1>"
   for each in $(grep -ile "$search" Tasks/<0000000000-9999999999>_<000-999>); do
@@ -28,6 +31,7 @@ if [ -n "$search" ]; then
 fi
 echo '</div><div id="MAIN">'
 
+#Display single task
 if [ -n "$info" -a -r "Tasks/$info" -a -r "Tasks/$info.meta" ]; then
   datafile="Tasks/$info"
   metafile="Tasks/$info.meta"
@@ -55,6 +59,7 @@ if [ -n "$info" -a -r "Tasks/$info" -a -r "Tasks/$info.meta" ]; then
 TasksEND
 fi
 
+#create task main dialog
 [ -z "$info" -a -n "$new" ] && cat <<TaskEnd
 <form class="Task" style="height:20em;" method="post" action="write/taskmeta.cgi" accept-charset="UTF-8">
   <h1>$new</h1>
@@ -66,17 +71,19 @@ fi
   </div><div style="width:30%;right:.5em;">
     <b>Section:</b><br>
     <select name="section" size="6" style="width:80%">
-    $(for each in $(egrep -x 'section=.+' Tasks/<0000000000-9999999999>_<000-999>.meta |sort -u); do
+    $(for each in $(egrep -hx 'section=.+' Tasks/<0000000000-9999999999>_<000-999>.meta |sort -u); do
         echo "<option>$(sed 's:section=::' <<<"$each")</option>"
       done)
     </select><br>
     <b>other section:</b><br>
     <input type="text" name="section">
+    <input type="submit" value="Robots click here" style="display:none;">
     <input type="submit" value="Create Task">
   </div>
 </form>
 TaskEnd
 
+#Plain list of tasks (default)
 [ -z "$info" -a -z "$new" ] && stat -c '' Tasks/<0000000000-9999999999>_<000-999>.meta && for each in Tasks/<0000000000-9999999999>_<000-999>.meta(.om); do
   info="$(basename "$each" |sed 's:.meta$::')"
   headline="$(sed -rn '/^headline=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
@@ -95,8 +102,9 @@ TaskEnd
 TasksEND
 done
 
+#dropdown dialog for adding a task
 echo '</div> <div id="RIGHT">'
-$LOGIN && [ -z "$new" ] && cat <<TasksEND
+$ACL_CREATETASK && [ -z "$new" ] && cat <<TasksEND
       <a id='newTask_button' class='function' href='#' onclick='javascript:show_screen("newTask");hide_screen("newTask_button");'>New Task</a>
       <div id="newTask" style="display: none;">
         <form action="/${SCRIPTNAME}" method="get" accept-charset="UTF-8">
diff --git a/auth/acl.sh b/auth/acl.sh
new file mode 100755 (executable)
index 0000000..10492dd
--- /dev/null
@@ -0,0 +1,11 @@
+ANL_EDITINTRO="paul"
+ANL_ADDNEWS="paul"
+ANL_EDITNEWS="paul"
+ANL_CREATETASK=".*"
+
+[ -n "$REMOTE_USER" ] && USER="$REMOTE_USER" || USER="#NONE#"
+egrep -xq "$ANL_EDITINTRO"  <<<"$USER" && ACL_EDITINTRO=true
+egrep -xq "$ANL_ADDNEWS"    <<<"$USER" && ACL_ADDNEWS=true
+egrep -xq "$ANL_EDITNEWS"   <<<"$USER" && ACL_EDITNEWS=true
+egrep -xq "$ANL_CREATETASK" <<<"$USER" && ACL_CREATETASK=true
+
diff --git a/auth/develop.user b/auth/develop.user
deleted file mode 100644 (file)
index ea015f6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-paul
index dc04c7360515c106864391cbb3de739758905fd4..1612a9fb89d42c75dd024c4858f6a15fa97f7345 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
 
 umask=002
 alias _wiki="stx2any --no-template --link-abbrevs --quote -T html"
+. auth/acl.sh
 
 page=$(egrep -o '(^|&)p=[a-zA-Z0-9/_-]+(&|$)' <<<"${QUERY_STRING}" |sed 's,&,,g;s,p=,,')
 
 [ -z "$LOGIN" ] && LOGIN=false
-[ -z "$DEV" ] && DEV=false
-[ -z "$ADM" ] && ADM=false
 [ -z "$page" ] && page=Home
 
 if (! $LOGIN && egrep -qx "https?://${HTTP_HOST}/(session.cgi\?|write/).*" <<<"${HTTP_REFERER}"); then
-  echo -n "Location: http://${HTTP_HOST}/session.cgi?${QUERY_STRING}\n\n"
+  echo -n "Location: https://${HTTP_HOST}/session.cgi?${QUERY_STRING}\n\n"
   exit 0
 fi
 
@@ -62,7 +61,7 @@ function hide_screen(id){
       <span id="SLOGAN">$(egrep '^slogan=.*$' project.meta |cut -d= -f2-)</span>
     </div>
     <div id="USERMENU">
-$( $LOGIN || echo '<form action="/login.cgi?'${QUERY_STRING:gs/&/&amp;/}'" method="post" accept-charset="UTF-8">
+$( $LOGIN || echo '<form action="https://'${HTTP_HOST}'/login.cgi?'${QUERY_STRING:gs/&/&amp;/}'" method="post" accept-charset="UTF-8">
                     Login:<br>
                     <input type="text" name="user" value placeholder="Username"><br>
                     <input type="password" name="pass" value placeholder="Password"><br>
index d5eaacbeabfc33800b8defd08a064de6a967813b..ff9f900fe6f3535248d46f2f1acedef804e6ea5d 100755 (executable)
@@ -17,9 +17,4 @@
 
 # This file must be password protected by the webserver (e.g. via a Files clause in .htaccess)
 LOGIN=true
-USER="${REMOTE_USER}"
-
-grep -xq "$USER" auth/develop.user && DEV=true
-grep -xq "$USER" auth/admin.user && ADM=true
-
 . ./index.cgi