tinycm rev 16

Add cloud/upload plugin
author Christophe Lincoln <pankso@slitaz.org>
date Sat Jan 04 19:01:14 2014 +0100 (2014-01-04)
parents 5a312bd55038
children 9aa60a355760
files plugins/cloud/cloud.cgi plugins/cloud/cloud.conf
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/cloud/cloud.cgi	Sat Jan 04 19:01:14 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# TinyCM Plugin - Upload file to the Cloud
     1.7 +#
     1.8 +. /usr/lib/slitaz/httphelper
     1.9 +
    1.10 +cloud="$tiny/$content/cloud"
    1.11 +cloudlog="$tiny/$cache/cloud.log"
    1.12 +
    1.13 +case " $(GET) " in
    1.14 +	*\ upcloud\ *)
    1.15 +		# Have a variable in config file for the content/cloud path ?
    1.16 +		[ ! check_auth ] && header "Location: $HTTP_REFERER"
    1.17 +		[ ! "$(FILE datafile name)" ] && header "Location: $HTTP_REFERER"
    1.18 +		user="$(GET user)"
    1.19 +		cloud="../../content/cloud"
    1.20 +		cloudlog="../../cache/cloud.log"
    1.21 +		name=$(FILE datafile name)
    1.22 +		tmpname=$(FILE datafile tmpname)
    1.23 +		# Sanity check
    1.24 +		[ ! -d "$cloud" ] && mkdir -p ${cloud}
    1.25 +		[ ! -f "$cloudlog" ] && touch ${cloudlog}
    1.26 +		# Move/Overwrite file to the cloud and set permissions
    1.27 +		if ! mv -f ${tmpname} ${cloud}/${name}; then
    1.28 +			echo "ERROR: ${name}" && exit 1
    1.29 +		fi
    1.30 +		chmod a+r ${cloud}/${name}
    1.31 +		# Log activity
    1.32 +		cat >> ${cloudlog} << EOT
    1.33 +$(date '+%Y-%m-%d %H:%M') : <a href="content/cloud/${name}">${name}</a> \
    1.34 +$(gettext "uploaded by:") <a href="index.cgi?user=$user">$user</a>
    1.35 +EOT
    1.36 +		# Back to the cloud
    1.37 +		header "Location: $HTTP_REFERER" ;;
    1.38 +		
    1.39 +	*\ rmcloud\ *)
    1.40 +		user="$(GET user)"
    1.41 +		name="$(GET name)"
    1.42 +		rm -f "$cloud/$name"
    1.43 +		# Log activity
    1.44 +		cat >> ${cloudlog} << EOT
    1.45 +$(date '+%Y-%m-%d %H:%M') : $name $(gettext "removed by:") \
    1.46 +<a href="index.cgi?user=$user">$user</a>
    1.47 +EOT
    1.48 +		# Back to the cloud
    1.49 +		header "Location: $HTTP_REFERER" ;;
    1.50 +		
    1.51 +	*\ cloudlog\ *)
    1.52 +		# Display Cloud activity
    1.53 +		d="Cloud activity"
    1.54 +		[ ! check_auth ] && header "Location: $WEB_URL"
    1.55 +		# Clean-up logfile
    1.56 +		if [ "$(GET clean)" ]; then
    1.57 +			rm -f ${cloudlog} && touch ${cloudlog}
    1.58 +			header "Location: $HTTP_REFERER"
    1.59 +		fi
    1.60 +		header
    1.61 +		html_header
    1.62 +		user_box
    1.63 +		echo "<h2>$(gettext "Cloud activity")</h2>"
    1.64 +		echo '<pre>'
    1.65 +		if [ "$(GET full)" ]; then
    1.66 +			tac ${cloudlog}
    1.67 +		else
    1.68 +			tac ${cloudlog} | head -n 20
    1.69 +		fi
    1.70 +		echo '</pre>'
    1.71 +		cat << EOT
    1.72 +<div id="tools">
    1.73 +	<a href="$script?cloud">Cloud files</a>
    1.74 +	<a href="$script?cloudlog&amp;full">$(gettext "More activity")</a>
    1.75 +	<a href="$script?cloudlog&amp;clean">$(gettext "Clean logfile")</a>
    1.76 +</div>
    1.77 +EOT
    1.78 +		html_footer && exit 0 ;;
    1.79 +		
    1.80 +	*\ cloud\ *)
    1.81 +		# The dashboard
    1.82 +		d="Cloud files"
    1.83 +		files=$(ls -1 $cloud | wc -l)
    1.84 +		size=$(du -sh $cloud | awk '{print $1}')
    1.85 +		header
    1.86 +		html_header
    1.87 +		user_box
    1.88 +		# Security check
    1.89 +		if ! check_auth; then
    1.90 +			gettext "You must be logged in to use the Cloud."
    1.91 +			exit 1
    1.92 +		fi
    1.93 +		cat << EOT 
    1.94 +<h2>Cloud files</h2>
    1.95 +<p>
    1.96 +$(gettext "Upload files on the cloud to share them with some other people
    1.97 +or use them in your documents content.")
    1.98 +</p>
    1.99 +<div style="text-align: center;"">
   1.100 +	<form method="post" action="plugins/cloud/cloud.cgi?upcloud&amp;user=$user"
   1.101 +		enctype="multipart/form-data">
   1.102 +		<input type="file" name="datafile" size="50" />
   1.103 +		<input type="submit" value="Upload" />
   1.104 +	</form>
   1.105 +</div>
   1.106 +<div id="tools">
   1.107 +	<a href="$script?cloudlog">Activity</a>
   1.108 +	<a href="$content/cloud">Raw files</a>
   1.109 +	<b>Files:</b> $files | <b>Size:</b> $size
   1.110 +</div>
   1.111 +EOT
   1.112 +		echo '<pre>'
   1.113 +		# List all Cloud files
   1.114 +		for f in $(ls ${cloud})
   1.115 +		do
   1.116 +			case $f in
   1.117 +				*.png|*.jpg) image="images/image.png" ;;
   1.118 +				*) image="images/empty.png" ;;
   1.119 +			esac
   1.120 +			cat << EOT
   1.121 +<a href="$content/cloud/${f}" title="${WEB_URL}$content/cloud/${f}">\
   1.122 +<img src="$image" />${f}</a> : \
   1.123 +<a href="$script?rmcloud&amp;name=${f}&amp;user=$user">$(gettext "Remove")</a>
   1.124 +EOT
   1.125 +		done
   1.126 +		echo '</pre>'
   1.127 +		html_footer
   1.128 +		exit 0
   1.129 +esac
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/plugins/cloud/cloud.conf	Sat Jan 04 19:01:14 2014 +0100
     2.3 @@ -0,0 +1,7 @@
     2.4 +# TinyCM Plugin configuration
     2.5 +
     2.6 +PLUGIN="Cloud Files"
     2.7 +SHORT_DESC="Online file storage"
     2.8 +MAINTAINER="devel@slitaz.org"
     2.9 +
    2.10 +# Configurable variables used in plugin.cgi