# HG changeset patch # User Christophe Lincoln # Date 1389019752 0 # Node ID 09f5185ff6e00ad6d32bfe3083e0dbdcfeae4d3e # Parent dcbb06a29438a8e244987603c0661c2043d36c6a Bunch of improvments and fixes diff -r dcbb06a29438 -r 09f5185ff6e0 index.cgi --- a/index.cgi Sun Jan 05 23:20:19 2014 +0000 +++ b/index.cgi Mon Jan 06 14:49:12 2014 +0000 @@ -20,6 +20,7 @@ tmp="/tmp/tinycm" sessions="$tmp/sessions" script="$SCRIPT_NAME" +activity="$cache/log/activity.log" # Content negotiation for Gettext IFS="," @@ -113,6 +114,15 @@ EOT } +# Log main activity. +log_activity() { + [ -d "$cache/log" ] || mkdir -p ${cache}/log + #gravatar="$(get_gravatar $MAIL 24)" + grep ^[A-Z] | \ + sed s"#^[A-Z]\([^']*\)#$user|$(date '+%Y-%m-%d')|\0#" \ + >> $cache/log/activity.log +} + # Log documents activity. log() { grep ^[A-Z] | \ @@ -134,6 +144,11 @@ fi } +# Check if user is admin +admin_user() { + fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf +} + # Authentified or not user_box() { if check_auth; then @@ -240,6 +255,10 @@ EOT chmod 0600 $PEOPLE/$user/account.conf + # First created user is admin + if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then + echo 'ADMIN_USER="yes"' >> $PEOPLE/$user/account.conf + fi } # Display user public profile. @@ -320,14 +339,16 @@ # Log if [ "$new" ]; then echo "Page created by: $(link_user)" | log + if [ "$HG" == "yes" ]; then cd $content && hg -q add hg commit -q -u "$NAME <$MAIL>" -m "Created new document: $d" cd $tiny fi else - # Here we will clean log: cat && tail -n 40 + # Here we may clean log: cat && tail -n 40 echo "Page edited by: $(link_user)" | log + echo "New document: $d" | log_activity if [ "$HG" == "yes" ]; then cd $content && hg commit -q -u "$NAME <$MAIL>" \ -m "Edited document: $d" @@ -485,6 +506,32 @@ header html_header user_box + # Main activity + if [ "$d" == "log" ]; then + echo "

$(gettext "Activity")

" + if check_auth; then + echo "
" + echo "Dashboard" + echo "
" + fi + echo '
'
+			if [ -f "$cache/log/activity.log" ]; then
+				IFS="|"
+				tac $cache/log/activity.log | while read USER DATE LOG
+				do
+					. ${PEOPLE}/${USER}/account.conf
+					cat << EOT
+$(get_gravatar $MAIL 24)\
+$DATE - $LOG
+EOT
+				done
+				unset IFS
+			else
+				gettext "No activity log yet"; echo
+			fi
+			echo '
' + html_footer && exit 0 + fi get_lang echo "

$(gettext "Activity for:") $d

" echo '
'
@@ -498,6 +545,26 @@
 			wiki_tools
 		fi 
 		html_footer ;;
+	
+	*\ ls\ *)
+		d="Document list"
+		header
+		html_header
+		user_box
+		echo "

$(gettext "Document list")

" + if check_auth; then + echo "
" + echo "Dashboard" + echo "
" + fi + echo '
'
+		cd ${wiki}
+		for d in $(find . -type f | sed s'/.\///')
+		do
+			echo "${d%.txt}"
+		done
+		echo '
' + html_footer ;; *\ diff\ *) d="$(GET diff)" @@ -569,6 +636,8 @@ if check_auth && [ "$(GET user)" == "$user" ]; then auth_people else + # check_auth will set VARS to current logged user: re-source + . $PEOPLE/"$(GET user)"/account.conf public_people fi html_footer ;; @@ -590,17 +659,28 @@ echo "

$d

" if check_auth; then cat << EOT + +
 Users     : $users
 Wiki      : $docs ($wikisize)
 Cache     : $cachesize
 Mercurial : $hg
 
- -
- -
- +

Admin users

+EOT + # Get the list of administrators + for u in $(ls $PEOPLE) + do + user=${u} + if admin_user; then + echo "$u" + fi + done + cat << EOT

$(gettext "Plugins")

 EOT
diff -r dcbb06a29438 -r 09f5185ff6e0 plugins/blog/blog.cgi
--- a/plugins/blog/blog.cgi	Sun Jan 05 23:20:19 2014 +0000
+++ b/plugins/blog/blog.cgi	Mon Jan 06 14:49:12 2014 +0000
@@ -21,25 +21,44 @@
 # Post tools
 post_tools() {
 	cat << EOT
-
- ${d}: $(gettext "Edit post") -
+ - $(gettext "Edit it!") EOT +#$(gettext "Remove") } # Display blog post: show_posts nb +show_post() { + d=${1%.txt} + date=$(fgrep 'DATE=' ${blog}/${d}.txt | cut -d '"' -f 2) + # Get post author + author=$(fgrep 'AUTHOR=' ${blog}/${d}.txt | cut -d '"' -f 2) + if [ -f "${PEOPLE}/${author}/account.conf" ]; then + . ${PEOPLE}/${author}/account.conf + else + echo ERROR: ${PEOPLE}/${author}/account.conf + fi + echo "
" + cat ${blog}/${d}.txt | sed -e '/AUTHOR=/'d -e '/DATE=/'d | wiki_parser + cat << EOT +
+ $(get_gravatar $MAIL 24) + $date +EOT + # Post tools for auth users + if check_auth; then + post_tools + echo "
" + else + echo "
" + fi + echo "" +} + +# Display blog post: show_posts count show_posts() { - for p in $(find $blog -type f | head -n $1) + for p in $(ls -r $blog | head -n $1) do - name=$(basename $p) - d=${name%.txt} - echo "
" - cat ${blog}/${d}.txt | wiki_parser - echo "
" - # Post tools for auth users - if check_auth; then - post_tools - fi + show_post ${p} done } @@ -47,12 +66,11 @@ # Index main page can display the lastest Blog posts # if fgrep -q '[BLOG]' $tiny/$wiki/index.txt && [ ! "$(GET)" ]; then - d="Blog" + d="Blog posts" index="blog" header html_header user_box - echo "

$(gettext "Latest blog posts")

" # Post tools for auth users if check_auth; then blog_tools @@ -75,8 +93,11 @@ fi # New post if [ "$d" == "new" ]; then - d=$(date '+%Y%m%d') - [ -f "$blog/$d.txt" ] && d=$(date '+%Y%m%d-%H%M') + date=$(date '+%Y-%M-%d') + last=$(ls -r $blog | head -n 1) + nb=${last%.txt} + d=$(($nb + 1)) + conf=$(echo -e "\nAUTHOR=\"$user\"\nDATE=\"$date\"\n\n====Title====") fi cat << EOT

$(gettext "Blog post"): $d

@@ -84,7 +105,7 @@
- + $(gettext "Code Helper:") $(cat lib/jseditor.html) @@ -97,6 +118,12 @@ d="$(GET blogsave)" if check_auth; then [ -d "$blog" ] || mkdir -p ${blog} + # New post ? + if [ ! -f "${blog}/${d}.txt" ]; then + echo "New Blog post: Read it!" \ + | log_activity + fi + # Write content to file sed "s/$(echo -en '\r') /\n/g" > ${blog}/${d}.txt << EOT $(GET content) EOT @@ -104,12 +131,12 @@ header "Location: $script?blog" ;; *\ blog\ *) - d="Latest blog posts" - nb="20" + d="Blog posts" + count="20" header html_header user_box - echo "

$(gettext "Latest blog posts")

" + #echo "

$(gettext "Latest blog posts")

" # Blog tools for auth users if check_auth; then blog_tools @@ -120,7 +147,12 @@ gettext "Blog plugin is not yet active."; echo "

" html_footer && exit 0 fi - show_posts ${nb} + # Single post + if [ "$(GET blog)" != "blog" ]; then + show_post "$(GET blog)" + else + show_posts ${count} + fi html_footer exit 0 ;; esac diff -r dcbb06a29438 -r 09f5185ff6e0 plugins/cloud/cloud.cgi --- a/plugins/cloud/cloud.cgi Sun Jan 05 23:20:19 2014 +0000 +++ b/plugins/cloud/cloud.cgi Mon Jan 06 14:49:12 2014 +0000 @@ -5,7 +5,7 @@ . /usr/lib/slitaz/httphelper cloud="$tiny/$content/cloud" -cloudlog="$tiny/$cache/cloud.log" +cloudlog="$tiny/$cache/log/cloud.log" case " $(GET) " in *\ upcloud\ *) @@ -14,7 +14,7 @@ [ ! "$(FILE datafile name)" ] && header "Location: $HTTP_REFERER" user="$(GET user)" cloud="../../content/cloud" - cloudlog="../../cache/cloud.log" + cloudlog="../../cache/log/cloud.log" name=$(FILE datafile name) tmpname=$(FILE datafile tmpname) # Sanity check @@ -93,7 +93,7 @@ $(gettext "Upload files on the cloud to share them with some other people or use them in your documents content.")

-
+
diff -r dcbb06a29438 -r 09f5185ff6e0 plugins/export/export.cgi --- a/plugins/export/export.cgi Sun Jan 05 23:20:19 2014 +0000 +++ b/plugins/export/export.cgi Mon Jan 06 14:49:12 2014 +0000 @@ -4,6 +4,14 @@ # . /usr/lib/slitaz/httphelper +# +# NOTE: Exporting wiki and make all url's work is is a bit tricky and +# actually don't work as expected. The goal is to have a SliTaz codex +# online thta can be include on the ISO, so we could have an export +# including a small CGI script to simply display wiki pages via HTTPd +# knowing that with HTML we must also deal with ../../ +# + if [ "$(GET export)" ]; then d="Export" date=$(date "+%Y%m%d") @@ -14,8 +22,8 @@ cat << EOT

Export

-$(gettext "Export to HTML and create a tarball of your text content or -uploaded files.") +$(gettext "EXPERIMENTAL: Export to HTML and create a tarball of your text +content or plugins files.")