tinycm rev 59

Bunch of change, mv dashboard to plugins
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jan 31 00:48:32 2014 +0100 (2014-01-31)
parents 91c28ed67409
children 854c4a8f0972
files index.cgi plugins/cloud/cloud.cgi plugins/cloud/cloud.conf plugins/dashboard/dashboard.cgi plugins/dashboard/dashboard.conf
line diff
     1.1 --- a/index.cgi	Sat Jan 25 16:23:20 2014 +0000
     1.2 +++ b/index.cgi	Fri Jan 31 00:48:32 2014 +0100
     1.3 @@ -287,12 +287,14 @@
     1.4  		cat << EOT
     1.5  <div id="tools">
     1.6  	<a href="$script?edit=profile">$(gettext "Edit profile")</a>
     1.7 +	<a href="$script?dashboard">Dashboard</a>
     1.8  </div>
     1.9  EOT
    1.10  	else
    1.11  		cat << EOT
    1.12  <div id="tools">
    1.13  	<a href="$script?edit=profile">$(gettext "Create a profile page")</a>
    1.14 +	<a href="$script?dashboard">Dashboard</a>
    1.15  </div>
    1.16  EOT
    1.17  	fi
    1.18 @@ -369,23 +371,23 @@
    1.19  		cat << EOT
    1.20  <div id="tools">
    1.21  	<a href="$script?edit=$d">$(gettext "Edit document")</a>
    1.22 +	<a href="$script?log=$d">$(gettext "File log")</a>
    1.23  	<a href="$script?diff=$d">$(gettext "Last diff")</a>
    1.24 -	<a href="$script?log=$d">$(gettext "File log")</a>
    1.25 -	<a href='$script?dashboard'>$(gettext 'Dashboard')</a>
    1.26 +	$PLUGINS_TOOLS
    1.27  EOT
    1.28  		[ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>"
    1.29  		echo "</div>"
    1.30  	fi
    1.31  }
    1.32  
    1.33 -# Built-in Dashboard tools and ADMIN_TOOLS from plugins
    1.34 -dashboard_tools() {
    1.35 +# Built-in tools such as log/ls and PLUGINS_TOOLS
    1.36 +tiny_tools() {
    1.37  	if check_auth; then
    1.38  				cat << EOT
    1.39  <div id='tools'>
    1.40  	<a href='$script?log'>Activity log</a>
    1.41  	<a href='$script?ls'>Pages list</a>
    1.42 -	<a href='$script?dashboard'>Dashboard</a>
    1.43 +	$PLUGINS_TOOLS
    1.44  </div>
    1.45  EOT
    1.46  	fi 
    1.47 @@ -477,6 +479,7 @@
    1.48  		html_header
    1.49  		user_box
    1.50  		get_lang
    1.51 +		wiki_tools
    1.52  		if check_auth; then
    1.53  			if [ "$doc" == "profile" ]; then
    1.54  				wiki="$PEOPLE/$user"
    1.55 @@ -521,7 +524,7 @@
    1.56  		user_box
    1.57  		# Main activity
    1.58  		if [ "$d" == "log" ]; then
    1.59 -			dashboard_tools
    1.60 +			tiny_tools
    1.61  			echo "<h2>$(gettext "Activity log")</h2>"
    1.62  			echo '<pre>'
    1.63  			if [ -f "$cache/log/activity.log" ]; then
    1.64 @@ -559,23 +562,24 @@
    1.65  		header
    1.66  		html_header
    1.67  		user_box
    1.68 -		dashboard_tools
    1.69 +		tiny_tools
    1.70 +		[ ! check_auth ] && auth=0
    1.71  		echo "<h2>$(gettext "Pages list")</h2>"
    1.72  		echo '<pre>'
    1.73  		cd ${wiki}
    1.74  		for d in $(find . -type f | sed s'/.\///')
    1.75  		do
    1.76 -			cat << EOT
    1.77 -<a href="$script?d=${d%.txt}">${d%.txt}</a> : \
    1.78 -<a href="$script?rm=$d">$(gettext "Remove")</a> || \
    1.79 +			echo "<a href='$script?d=${d%.txt}'>${d%.txt}</a>"
    1.80 +			[ "$auth" ] && cat << EOT
    1.81 + : <a href="$script?rm=$d">$(gettext "Remove")</a> || \
    1.82  <a href="$script?edit=$d">$(gettext "Edit")</a>
    1.83  EOT
    1.84 -		done
    1.85 +		done && unset auth
    1.86  		echo '</pre>'
    1.87  		html_footer ;;
    1.88  	
    1.89  	*\ rm\ *)
    1.90 -		[ ! check_auth ] && header "Location: Location: $script"
    1.91 +		[ ! check_auth ] && exit 1
    1.92  		d="$(GET rm)"
    1.93  		rm ${wiki}/"${d}"
    1.94  		rm -rf ${cache}/"${d%.txt}"
    1.95 @@ -598,7 +602,7 @@
    1.96  			-e s"#^+\([^']*\).#<span style='color: green;'>\0</span>#"g \
    1.97  			-e s"#@@\([^']*\)@@#<span style='color: blue;'>@@\1@@</span>#"g
    1.98  		else
    1.99 -			gettext "No diff for: $d"; echo
   1.100 +			gettext "No diff for:"; echo " $d"
   1.101  		fi
   1.102  		echo '</pre>'
   1.103  		html_footer ;;
   1.104 @@ -660,80 +664,13 @@
   1.105  		fi
   1.106  		html_footer ;;
   1.107  		
   1.108 -	*\ dashboard\ *)
   1.109 -		# For now simply list plugins and users info. We could have a 
   1.110 -		# dashbord only for ADMINS found in the config file. The dashboard
   1.111 -		# should also be a plugin.
   1.112 -		d="Dashboard"
   1.113 +	*\ hg\ *)
   1.114 +		d="Hg Log"
   1.115  		header
   1.116  		html_header
   1.117  		user_box
   1.118 -		users=$(ls -1 $PEOPLE | wc -l)
   1.119 -		docs=$(find $wiki -type f | wc -l)
   1.120 -		wikisize="$(du -sh $wiki | awk '{print $1}')"
   1.121 -		cachesize="$(du -sh $cache | awk '{print $1}')"
   1.122 -		[ "$HG" != "yes" ] && hg=$(gettext "disabled")
   1.123 -		[ "$HG" == "yes" ] && hg=$(gettext "enabled")
   1.124 -		# Source all plugins.conf to get DASHBOARD_TOOLS and ADMIN_TOOLS
   1.125 -		ADMIN_TOOLS=""
   1.126 -		DASHBOARD_TOOLS=""
   1.127 -		for p in $(ls $plugins)
   1.128 -		do
   1.129 -			. $plugins/$p/$p.conf
   1.130 -		done
   1.131 -		if check_auth && ! admin_user; then
   1.132 -			ADMIN_TOOLS=""
   1.133 -		fi
   1.134 -		if check_auth; then
   1.135 -			cat << EOT
   1.136 -<div id="tools">
   1.137 -	<a href='$script?log'>Activity log</a>
   1.138 -	<a href='$script?ls'>Pages list</a>
   1.139 -	$DASHBOARD_TOOLS
   1.140 -	$ADMIN_TOOLS
   1.141 -</div>
   1.142 -
   1.143 -<h2>$d</h2>
   1.144 -
   1.145 -<pre>
   1.146 -Users     : $users
   1.147 -Wiki      : $docs ($wikisize)
   1.148 -Cache     : $cachesize
   1.149 -Mercurial : $hg
   1.150 -</pre>
   1.151 -
   1.152 -<h3>Admin users</h3>
   1.153 -EOT
   1.154 -			# Get the list of administrators
   1.155 -			for u in $(ls $PEOPLE)
   1.156 -			do
   1.157 -				user=${u}
   1.158 -				if admin_user; then
   1.159 -					echo "<a href='?user=$u'>$u</a>"
   1.160 -				fi
   1.161 -			done
   1.162 -			cat << EOT
   1.163 -<h3>$(gettext "Plugins")</h3>
   1.164 -<pre>
   1.165 -EOT
   1.166 -			for p in $(ls -1 $plugins)
   1.167 -			do
   1.168 -				. $plugins/$p/$p.conf
   1.169 -				echo "<a href='?$p'>$PLUGIN</a> - $SHORT_DESC"
   1.170 -			done
   1.171 -			echo '</pre>'
   1.172 -		else
   1.173 -			gettext "You must be logged in to view the dashboard."
   1.174 -		fi
   1.175 -		html_footer ;;
   1.176 -		
   1.177 -	*\ hg\ *)
   1.178 -		header
   1.179  		[ "$HG" != "yes" ] && gettext "Hg is disabled" && exit 0
   1.180  		[ ! -x /usr/bin/hg ] && gettext "Hg is not installed" && exit 0
   1.181 -		d="Hg Log"
   1.182 -		html_header
   1.183 -		user_box
   1.184  		echo "<h2>$d</h2>"
   1.185  		case " $(GET hg) " in
   1.186  			*\ init\ *)
   1.187 @@ -745,7 +682,7 @@
   1.188  					echo '[hooks]' > .hg/hgrc
   1.189  					echo 'incoming = hg update' >> .hg/hgrc
   1.190  					gettext "Adding current content and committing"; echo
   1.191 -					[ ! -f "$wiki/index.txt" ] && touch $wiki/$index.txt
   1.192 +					[ ! -f "$wiki/index.txt" ] && default_index
   1.193  					hg add && hg commit -u "$NAME <$MAIL>" \
   1.194  						-m "Initial commit with current content"
   1.195  					echo '</pre>' && cd .. 
   1.196 @@ -778,11 +715,11 @@
   1.197  			html_footer && exit 0
   1.198  		fi
   1.199  		
   1.200 -		# Wiki tools and Hg warning if enabled but not initiated
   1.201 +		# Hg warning if enabled but not initiated
   1.202  		if [ "$HG" == "yes" ] && [ ! -d "$content/.hg" ]; then
   1.203  			echo '<p class="error box">'
   1.204  			gettext "Mercurial is enabled but no repository found"
   1.205 -			echo ": <a href='?hg=init'>Hg init</a>"
   1.206 +			echo ": <a href='$script?hg=init'>Hg init</a>"
   1.207  			echo '</p>'
   1.208  		fi
   1.209  		
   1.210 @@ -793,7 +730,7 @@
   1.211  		if [ ! -f "$wiki/$d.txt" ]; then
   1.212  			echo "<h2>$d</h2>"
   1.213  			gettext "The document does not exist. You can create it or read the"
   1.214 -			echo " <a href='?d=en/help'>help</a>"
   1.215 +			echo " <a href='$script?d=en/help'>help</a>"
   1.216  		else
   1.217  			if fgrep -q [NOWIKI] $wiki/$d.txt; then
   1.218  				cat $wiki/$d.txt | sed '/\[NOWIKI\]/'d
     2.1 --- a/plugins/cloud/cloud.cgi	Sat Jan 25 16:23:20 2014 +0000
     2.2 +++ b/plugins/cloud/cloud.cgi	Fri Jan 31 00:48:32 2014 +0100
     2.3 @@ -89,8 +89,9 @@
     2.4  		fi
     2.5  		cat << EOT
     2.6  <div id="tools">
     2.7 -	<a href="$script?cloudlog">Activity</a>
     2.8 +	<a href="$script?cloudlog">Cloud activity</a>
     2.9  	<a href="$content/cloud">Raw files</a>
    2.10 +	<a href="$script?dashboard">Dashboard</a>
    2.11  </div>
    2.12  
    2.13  <h2>Cloud files</h2>
     3.1 --- a/plugins/cloud/cloud.conf	Sat Jan 25 16:23:20 2014 +0000
     3.2 +++ b/plugins/cloud/cloud.conf	Fri Jan 31 00:48:32 2014 +0100
     3.3 @@ -4,4 +4,6 @@
     3.4  SHORT_DESC="Online file storage"
     3.5  MAINTAINER="devel@slitaz.org"
     3.6  
     3.7 +DASHBOARD_TOOLS="${DASHBOARD_TOOLS} <a href='?cloud'>Cloud files</a>"
     3.8 +
     3.9  # Configurable variables used in plugin.cgi
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/plugins/dashboard/dashboard.cgi	Fri Jan 31 00:48:32 2014 +0100
     4.3 @@ -0,0 +1,71 @@
     4.4 +#!/bin/sh
     4.5 +#
     4.6 +# TinyCM Plugin - Users and admin Dashboard.
     4.7 +#
     4.8 +. /usr/lib/slitaz/httphelper
     4.9 +
    4.10 +if [ "$(GET dashboard)" ]; then
    4.11 +		d="Dashboard"
    4.12 +		header
    4.13 +		html_header
    4.14 +		user_box
    4.15 +		users=$(ls -1 $PEOPLE | wc -l)
    4.16 +		docs=$(find $wiki -type f | wc -l)
    4.17 +		wikisize="$(du -sh $wiki | awk '{print $1}')"
    4.18 +		cachesize="$(du -sh $cache | awk '{print $1}')"
    4.19 +		[ "$HG" != "yes" ] && hg=$(gettext "disabled")
    4.20 +		[ "$HG" == "yes" ] && hg=$(gettext "enabled")
    4.21 +		# Source all plugins.conf to get DASHBOARD_TOOLS and ADMIN_TOOLS
    4.22 +		ADMIN_TOOLS=""
    4.23 +		DASHBOARD_TOOLS=""
    4.24 +		for p in $(ls $plugins)
    4.25 +		do
    4.26 +			. $plugins/$p/$p.conf
    4.27 +		done
    4.28 +		if check_auth && ! admin_user; then
    4.29 +			ADMIN_TOOLS=""
    4.30 +		fi
    4.31 +		if check_auth; then
    4.32 +			cat << EOT
    4.33 +<div id="tools">
    4.34 +	<a href='$script?log'>Activity log</a>
    4.35 +	<a href='$script?ls'>Pages list</a>
    4.36 +	$DASHBOARD_TOOLS
    4.37 +	$ADMIN_TOOLS
    4.38 +</div>
    4.39 +
    4.40 +<h2>$d</h2>
    4.41 +
    4.42 +<pre>
    4.43 +Users     : $users
    4.44 +Wiki      : $docs ($wikisize)
    4.45 +Cache     : $cachesize
    4.46 +Mercurial : $hg
    4.47 +</pre>
    4.48 +
    4.49 +<h3>Admin users</h3>
    4.50 +EOT
    4.51 +			# Get the list of administrators
    4.52 +			for u in $(ls $PEOPLE)
    4.53 +			do
    4.54 +				user=${u}
    4.55 +				if admin_user; then
    4.56 +					echo "<a href='?user=$u'>$u</a>"
    4.57 +				fi
    4.58 +			done
    4.59 +			cat << EOT
    4.60 +<h3>$(gettext "Plugins")</h3>
    4.61 +<pre>
    4.62 +EOT
    4.63 +			for p in $(ls -1 $plugins)
    4.64 +			do
    4.65 +				. $plugins/$p/$p.conf
    4.66 +				echo "<a href='?$p'>$PLUGIN</a> - $SHORT_DESC"
    4.67 +			done
    4.68 +			echo '</pre>'
    4.69 +		else
    4.70 +			gettext "You must be logged in to view the dashboard."
    4.71 +		fi
    4.72 +		html_footer
    4.73 +		exit 0
    4.74 +fi
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/plugins/dashboard/dashboard.conf	Fri Jan 31 00:48:32 2014 +0100
     5.3 @@ -0,0 +1,12 @@
     5.4 +# TinyCM Plugin configuration.
     5.5 +
     5.6 +# NOTE: This plugin is not compatible with TazBug.
     5.7 +
     5.8 +PLUGIN="Dashboard"
     5.9 +SHORT_DESC="TinyCM administrators dashboard"
    5.10 +MAINTAINER="devel@slitaz.org"
    5.11 +
    5.12 +# Authenticated users
    5.13 +PLUGINS_TOOLS="<a href='?dashboard'>Dashboard</a> ${PLUGINS_TOOLS}"
    5.14 +
    5.15 +# Configurable variables used in plugin.cgi