tinycm view plugins/cloud/cloud.cgi @ rev 52

Improved added some functions
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jan 24 23:08:48 2014 +0100 (2014-01-24)
parents c4a472d0a45e
children 190b9ba3af06
line source
1 #!/bin/sh
2 #
3 # TinyCM Plugin - Upload files to the Cloud
4 #
5 . /usr/lib/slitaz/httphelper
7 cloud="$tiny/$content/cloud"
8 cloudlog="$tiny/$cache/log/cloud.log"
10 case " $(GET) " in
11 *\ upcloud\ *)
12 # Have a variable in config file for the content/cloud path ?
13 [ ! check_auth ] && header "Location: $HTTP_REFERER"
14 [ ! "$(FILE datafile name)" ] && header "Location: $HTTP_REFERER"
15 user="$(GET user)"
16 cloud="../../content/cloud"
17 cloudlog="../../cache/log/cloud.log"
18 name=$(FILE datafile name)
19 tmpname=$(FILE datafile tmpname)
20 # Sanity check
21 [ ! -d "$cloud" ] && mkdir -p ${cloud}
22 [ ! -f "$cloudlog" ] && touch ${cloudlog}
23 # Move/Overwrite files to the cloud and set permissions
24 if ! mv -f ${tmpname} ${cloud}/${name}; then
25 echo "ERROR: ${name}" && exit 1
26 fi
27 chmod a+r ${cloud}/${name}
28 # Log activity
29 cat >> ${cloudlog} << EOT
30 $(date '+%Y-%m-%d %H:%M') : <a href="content/cloud/${name}">${name}</a> \
31 $(gettext "uploaded by:") <a href="index.cgi?user=$user">$user</a>
32 EOT
33 # Back to the cloud
34 header "Location: $HTTP_REFERER" ;;
36 *\ rmcloud\ *)
37 user="$(GET user)"
38 name="$(GET name)"
39 rm -f "$cloud/$name"
40 # Log activity
41 cat >> ${cloudlog} << EOT
42 $(date '+%Y-%m-%d %H:%M') : $name $(gettext "removed by:") \
43 <a href="index.cgi?user=$user">$user</a>
44 EOT
45 # Back to the cloud
46 header "Location: $HTTP_REFERER" ;;
48 *\ cloudlog\ *)
49 # Display Cloud activity
50 d="Cloud activity"
51 [ ! check_auth ] && header "Location: $script"
52 # Clean-up logfile
53 if [ "$(GET clean)" ]; then
54 rm -f ${cloudlog} && touch ${cloudlog}
55 header "Location: $HTTP_REFERER"
56 fi
57 header
58 html_header
59 user_box
60 echo "<h2>$(gettext "Cloud activity")</h2>"
61 echo '<pre>'
62 if [ "$(GET full)" ]; then
63 tac ${cloudlog}
64 else
65 tac ${cloudlog} | head -n 20
66 fi
67 echo '</pre>'
68 cat << EOT
69 <div id="tools">
70 <a href="$script?cloud">Cloud files</a>
71 <a href="$script?cloudlog&amp;full">$(gettext "More activity")</a>
72 <a href="$script?cloudlog&amp;clean">$(gettext "Clean logfile")</a>
73 </div>
74 EOT
75 html_footer && exit 0 ;;
77 *\ cloud\ *)
78 # The dashboard
79 d="Cloud files"
80 files=$(ls -1 $cloud | wc -l)
81 size=$(du -sh $cloud | awk '{print $1}')
82 header
83 html_header
84 user_box
85 # Security check
86 if ! check_auth; then
87 gettext "You must be logged in to use the Cloud."
88 exit 1
89 fi
90 cat << EOT
91 <div id="tools">
92 <a href="$script?cloudlog">Activity</a>
93 <a href="$content/cloud">Raw files</a>
94 </div>
96 <h2>Cloud files</h2>
98 <p>
99 $(gettext "Upload files on the cloud to share them with some other people
100 or use them in your documents content. Tip: Drag and Drop files from you
101 desktop.")
102 </p>
103 <div style="text-align: center;">
104 <form method="post" action="plugins/cloud/cloud.cgi?upcloud&amp;user=$user"
105 enctype="multipart/form-data">
106 <input type="file" name="datafile" size="50" />
107 <input type="submit" value="Upload" />
108 </form>
109 </div>
110 <p>
111 <b>Files:</b> $files | <b>Size:</b> $size
112 </p>
113 EOT
114 echo '<pre>'
115 # List all Cloud files
116 for f in $(ls ${cloud})
117 do
118 case $f in
119 *.png|*.jpg|*.gif) image="images/image.png" ;;
120 *) image="images/empty.png" ;;
121 esac
122 cat << EOT
123 <a href="$content/cloud/${f}" title="${WEB_URL}$content/cloud/${f}">\
124 <img src="$image" />${f}</a> : \
125 <a href="$script?rmcloud&amp;name=${f}&amp;user=$user">$(gettext "Remove")</a>
126 EOT
127 done
128 echo '</pre>'
129 html_footer
130 exit 0
131 esac