From: paul <paul@plutz.net>
Date: Sun, 30 Oct 2011 18:27:19 +0000 (+0000)
Subject: modified to use acl engine
X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=470dbac80eb2334fdb04a85e448d6194140d250d;p=busy

modified to use acl engine

svn path=/trunk/; revision=19
---

diff --git a/Error.page b/Error.page
index 61af555..519dfbb 100644
--- a/Error.page
+++ b/Error.page
@@ -28,6 +28,8 @@ case "${reason}" in
     ;;
   input) echo 'Invalid set of input data.'
     ;;
+  noaccess) echo '... because you were probably trying to do something nasty.'
+    ;;
   *) echo 'Unknown generic fuckup :-('
     ;;
 esac
diff --git a/Home.page b/Home.page
index 8f9d9dc..6f67a19 100644
--- a/Home.page
+++ b/Home.page
@@ -38,7 +38,7 @@ cat <<HomeEND
 HomeEND
 $ACL_EDITINTRO && cat <<HomeEND
       <div id="introedit" style="display: none;">
-        <form action="/write/introedit.cgi?i=intro" method="post" accept-charset="UTF-8">
+        <form action="/write/$($LOGIN && echo user_)introedit.cgi?i=intro" method="post" accept-charset="UTF-8">
           <textarea name="text" rows="10">$([ -r "Home/intro" ] && cat Home/intro)</textarea><br>
           <input type="submit">
           <a class="function" href="#" onclick="javascript:hide_screen('introedit');show_screen('introtext');">Cancel</a>
@@ -71,7 +71,7 @@ stat -c '' Home/<0000000000-9999999999>_<000-999>.news && for each in $(ls -c Ho
 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">
+        <form action="/write/$($LOGIN && echo user_)introedit.cgi?i=$info" method="post" accept-charset="UTF-8">
           <textarea name="text" rows="10">$([ -r "$each" ] && cat $each)</textarea><br>
           <input type="submit">
           <a class="function" href="#news_$info" onclick="javascript:hide_screen('edit_$info');show_screen('news_$info');">Cancel</a>
diff --git a/Tasks.page b/Tasks.page
index 333efe4..5c4486e 100644
--- a/Tasks.page
+++ b/Tasks.page
@@ -61,7 +61,7 @@ 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">
+<form class="Task" style="height:20em;" method="post" action="write/$($LOGIN && echo user_)taskmeta.cgi" accept-charset="UTF-8">
   <h1>$new</h1>
   <input type="hidden" name="headline" value="$new">
   <input type="hidden" name="status" value="new">
diff --git a/Wiki.page b/Wiki.page
index 9e135ad..8df11d6 100755
--- a/Wiki.page
+++ b/Wiki.page
@@ -6,6 +6,8 @@ rev="$(egrep -o '(^|&)(r=)[0-9]{10}(&|$)' <<<"${QUERY_STRING}" |tr -d '&r=')"
 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_WIKIEDIT" ] && ACL_WIKIEDIT=false
+
 [ -n "$rev" ] && rev=".$rev"
 if [ -n "$search" ]; then
   info=''
@@ -163,12 +165,12 @@ WikiEND
         <a name="$info" href="/?p=Wiki&amp;i=$info"><h1>$title</h1></a>
         $description<br><br>
         <a class="function" href="/?p=Wiki&amp;i=$info">View</a> 
-        $($LOGIN && echo "<a class='function' href='#' onclick=\"javascript:show_screen('change_$info');hide_screen('display_$info');\">Change Info</a>")
+        $($ACL_WIKIEDIT && echo "<a class='function' href='#' onclick=\"javascript:show_screen('change_$info');hide_screen('display_$info');\">Change Info</a>")
       </div>
 WikiEND
-    $LOGIN && cat <<WikiEND
+    $ACL_WIKIEDIT && cat <<WikiEND
       <div id="change_$info" style="display: none;">
-        <form action="/write/wikimeta.cgi?i=$info" method="post" accept-charset="UTF-8">
+        <form action="/write/$($LOGIN && echo user_)wikimeta.cgi?i=$info" method="post" accept-charset="UTF-8">
 	  <b>Title:</b> <input type="text" name="title" value="$title"><br>
 	  <b>Description:</b><br>
 	  <textarea name="desc" rows="6" style="width:100%;">$description</textarea><br>
diff --git a/auth/acl.sh b/auth/acl.sh
index 10492dd..ba0d447 100755
--- a/auth/acl.sh
+++ b/auth/acl.sh
@@ -2,10 +2,12 @@ ANL_EDITINTRO="paul"
 ANL_ADDNEWS="paul"
 ANL_EDITNEWS="paul"
 ANL_CREATETASK=".*"
+ANL_WIKIEDIT="paul"
 
 [ -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
+egrep -xq "$ANL_EDITINTRO"  <<<"$USER" && ACL_EDITINTRO=true  || ACL_EDITINTRO=false
+egrep -xq "$ANL_ADDNEWS"    <<<"$USER" && ACL_ADDNEWS=true    || ACL_ADDNEWS=false
+egrep -xq "$ANL_EDITNEWS"   <<<"$USER" && ACL_EDITNEWS=true   || ACL_EDITNEWS=false
+egrep -xq "$ANL_CREATETASK" <<<"$USER" && ACL_CREATETASK=true || ACL_CREATETASK=false
+egrep -xq "$ANL_WIKIEDIT"   <<<"$USER" && ACL_WIKIEDIT=true   || ACL_WIKIEDIT=false
 
diff --git a/write/.htaccess b/write/.htaccess
index 02be183..df30f7e 100644
--- a/write/.htaccess
+++ b/write/.htaccess
@@ -2,11 +2,13 @@ Options +ExecCGI
 AddHandler cgi-script .cgi
 DirectoryIndex index.cgi
 
-RewriteEngine On
-RewriteCond   %{SERVER_PORT}  80
-RewriteRule   ^.*(/write/.*)$     https://%{SERVER_NAME}/$1
+#RewriteEngine On
+#RewriteCond   %{SERVER_PORT}  80
+#RewriteRule   ^.*(/write/.*)$     https://%{SERVER_NAME}/$1
 
+<FilesMatch "^user_">
 AuthType Basic
 AuthName "Kinoserver Login"
 AuthUserFile /sites/kinob.plutz.net/http/.htpasswd
 Require valid-user
+</FilesMatch>
diff --git a/write/introedit.cgi b/write/introedit.cgi
index 5e53fae..b024371 100755
--- a/write/introedit.cgi
+++ b/write/introedit.cgi
@@ -15,9 +15,16 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
 
+[ "$HTTPS" = "on" ] && proto=https || proto=http
+. ../auth/acl.sh
+
 info="$(egrep -o '(^|&)i=([0-9]{10}_[0-9]{3}|intro|news)(&|$)' <<<"${QUERY_STRING}" |sed 's:&::g;s:i=::')"
-[ "$info" = "news" ] && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
-[ "$info" != "intro" ] && info="${info}.news"
+[ "$info" = "news" ] && $ACL_ADDNEWS && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
+[ "$info" != "intro" ] && $ACL_EDITNEWS && info="${info}.news"
+[ "$info" = "intro" ] && ($ACL_EDITINTRO || info='')
+
+[ -n "$info" ] || echo "Location: ${proto}://${HTTP_HOST}/?p=Error&i=noaccess\n\n"
+[ -n "$info" ] || exit 0
 
 if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
 (head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
@@ -32,4 +39,4 @@ fi
 
 [ -z "$cancel" ] && grep -qx "${REMOTE_USER}" ../auth/admin.user && echo -e "${text}" >"../Home/$info"
 
-echo -n "Location: http://${HTTP_HOST}/?p=Home\n\n"
+echo -n "Location: ${proto}://${HTTP_HOST}/?p=Home\n\n"
diff --git a/write/lock.cgi b/write/lock.cgi
index 41c0951..3c2866d 100755
--- a/write/lock.cgi
+++ b/write/lock.cgi
@@ -15,18 +15,19 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
 
+[ "$HTTPS" = "on" ] && proto=https || proto=http
+. ../auth/acl.sh
+$ACL_WIKIEDIT || echo "Location: ${proto}://${HTTP_HOST}/?p=Error&i=noaccess\n\n"
+$ACL_WIKIEDIT || exit 0 
+
 page=$(egrep -o '(^|&)p=(QandA|Locations|Wiki)(&|$)' <<<"${QUERY_STRING}" |sed 's,p=,,;s,&,,g')
 edit=$(egrep -o '(^|&)e=[0-9]{10}_[0-9]{3}(_[0-9]{1,4})?(&|$)' <<<"${QUERY_STRING}" |tr -d 'e=&')
 
 case "$page" in
-  QandA)	[ -f "../QandA/${edit}.qstn" ] && echo "${REMOTE_USER}:$(($(date +%s)+600))" >"../QandA/${edit}.lock"
-	;;
-  Locations)	[ -f "../Locations/${edit}.jpg" ] && echo "${REMOTE_USER}:$(($(date +%s)+600))" >"../Locations/${edit}.lock"
-	;;
   Wiki)	[ -f "../Wiki/${edit}" ] && echo "${REMOTE_USER}:$(($(date +%s)+600))" >"../Wiki/${edit}.lock"
 	;;
   *)	echo -n "Location: http://$host/?p=Error&r=input&$page\n\n"
 	exit 0
 	;;
 esac
-echo -n "Location: http://${HTTP_HOST}/?${QUERY_STRING}\n\n"
+echo -n "Location: ${proto}://${HTTP_HOST}/?${QUERY_STRING}\n\n"
diff --git a/write/taskmeta.cgi b/write/taskmeta.cgi
index 0d8879c..a5e2ffc 100755
--- a/write/taskmeta.cgi
+++ b/write/taskmeta.cgi
@@ -16,6 +16,12 @@
 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
 
 #info="$(egrep -o '(^|&)i=[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
+[ "$HTTPS" = "on" ] && PROTO=https || proto=http
+
+. ../auth/acl.sh
+$ACL_CREATETASK || echo "Location: ${proto}://${HTTP_HOST}/?p=Error&i=noaccess\n\n"
+$ACL_CREATETASK || exit 0
+
 info="$(sed -r 's:(^|.*&)i=(.*)|.*:\2:;s:&.*::' <<<"${QUERY_STRING}")"
 
 [ -z "$info" ] && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
@@ -52,14 +58,14 @@ if [ -z "$cancel" -a -n "$comment" ]; then
   touch "../Tasks/$info"
   echo -e "author=${REMOTE_USER}" > "$commfile"
   echo -e "${comment}" >> "$commfile"
-  echo -n "Location: http://${HTTP_HOST}/?p=Tasks&i=$info\n\n"
+  echo -n "Location: ${proto}://${HTTP_HOST}/?p=Tasks&i=$info\n\n"
 elif [ -z "$cancel" -a -n "$description" ]; then
   touch "../Tasks/$info"
   echo -e "headline=${headline}" > "$descfile"
   echo -e "status=${taskstatus}" >> "$descfile"
   echo -e "section=${section}" >> "$descfile"
   echo -e "${description}" >> "../Tasks/$info"
-  echo -n "Location: http://${HTTP_HOST}/?p=Tasks#$anchor\n\n"
+  echo -n "Location: ${proto}://${HTTP_HOST}/?p=Tasks#$anchor\n\n"
 elif [ -n "$cancel" ]; then
-  echo -n "Location: http://${HTTP_HOST}/?p=Tasks#$anchor\n\n"
+  echo -n "Location: ${proto}://${HTTP_HOST}/?p=Tasks#$anchor\n\n"
 fi
diff --git a/write/user_introedit.cgi b/write/user_introedit.cgi
new file mode 120000
index 0000000..a23710b
--- /dev/null
+++ b/write/user_introedit.cgi
@@ -0,0 +1 @@
+introedit.cgi
\ No newline at end of file
diff --git a/write/user_lock.cgi b/write/user_lock.cgi
new file mode 120000
index 0000000..a247558
--- /dev/null
+++ b/write/user_lock.cgi
@@ -0,0 +1 @@
+lock.cgi
\ No newline at end of file
diff --git a/write/user_taskmeta.cgi b/write/user_taskmeta.cgi
new file mode 120000
index 0000000..b6544bf
--- /dev/null
+++ b/write/user_taskmeta.cgi
@@ -0,0 +1 @@
+taskmeta.cgi
\ No newline at end of file
diff --git a/write/user_wikiedit.cgi b/write/user_wikiedit.cgi
new file mode 120000
index 0000000..368a76b
--- /dev/null
+++ b/write/user_wikiedit.cgi
@@ -0,0 +1 @@
+wikiedit.cgi
\ No newline at end of file
diff --git a/write/user_wikimeta.cgi b/write/user_wikimeta.cgi
new file mode 120000
index 0000000..002e11e
--- /dev/null
+++ b/write/user_wikimeta.cgi
@@ -0,0 +1 @@
+wikimeta.cgi
\ No newline at end of file
diff --git a/write/wikiedit.cgi b/write/wikiedit.cgi
index 2ce87e2..5a3471e 100755
--- a/write/wikiedit.cgi
+++ b/write/wikiedit.cgi
@@ -15,6 +15,11 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
 
+[ "$HTTPS" = "on" ] && proto=https || proto=http
+. ../auth/acl.sh
+$ACL_WIKIEDIT || echo "Location: ${proto}://${HTTP_HOST}/?p=Error&i=noaccess\n\n"
+$ACL_WIKIEDIT || exit 0
+
 info="$(egrep -o '(^|&)i=[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&=i')"
 [ -f "../Wiki/$info.lock" ] && rm "../Wiki/$info.lock"
 
@@ -32,4 +37,4 @@ fi
 [ -z "$cancel" -a -f "../Wiki/$info" ] && mv "../Wiki/$info" "../Wiki/$info.$(date +%s)"
 [ -z "$cancel" ] && echo -e "${page}" >"../Wiki/$info"
 
-echo -n "Location: https://${HTTP_HOST}/?p=Wiki&i=$info\n\n"
+echo -n "Location: ${proto}://${HTTP_HOST}/?p=Wiki&i=$info\n\n"
diff --git a/write/wikimeta.cgi b/write/wikimeta.cgi
index fe234ae..e032d91 100755
--- a/write/wikimeta.cgi
+++ b/write/wikimeta.cgi
@@ -15,6 +15,12 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with Busy.  If not, see <http://www.gnu.org/licenses/>.
 
+[ "$HTTPS" = "on" ] && proto=https || proto=http
+. ../auth/acl.sh
+env >../debug
+$ACL_WIKIEDIT || echo "Location: ${proto}://${HTTP_HOST}/?p=Error&i=noaccess\n\n"
+$ACL_WIKIEDIT || exit 0 
+
 info="$(egrep -o '(^|&)i=[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
 
 [ -z "$info" ] && info="$(date +%s)_$(apg -M N -a 1 -n 1 -m 3 -x 3)"
@@ -45,12 +51,12 @@ if [ -z "$cancel" -a -n "$comment" ]; then
   touch "../Wiki/$info"
   echo -e "author=${REMOTE_USER}" > "$commfile"
   echo -e "${comment}" >> "$commfile"
-  echo -n "Location: https://${HTTP_HOST}/?p=Wiki&i=$info\n\n"
+  echo -n "Location: ${proto}://${HTTP_HOST}/?p=Wiki&i=$info\n\n"
 elif [ -z "$cancel" -a -n "$description" ]; then
   touch "../Wiki/$info"
   echo -e "title=${title}" > "$descfile"
   echo -e "description=${description}" >> "$descfile"
-  echo -n "Location: https://${HTTP_HOST}/?p=Wiki#$anchor\n\n"
+  echo -n "Location: ${proto}://${HTTP_HOST}/?p=Wiki#$anchor\n\n"
 elif [ -n "$cancel" ]; then
-  echo -n "Location: https://${HTTP_HOST}/?p=Wiki#$anchor\n\n"
+  echo -n "Location: ${proto}://${HTTP_HOST}/?p=Wiki#$anchor\n\n"
 fi