tinycm view plugins/cloud/cloud.cgi @ rev 40
Added tag 1.0 for changeset eea2e04b7436
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Jan 08 00:02:16 2014 +0100 (2014-01-08) |
parents | 09f5185ff6e0 |
children | c4a472d0a45e |
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: $WEB_URL"
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&full">$(gettext "More activity")</a>
72 <a href="$script?cloudlog&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 <h2>Cloud files</h2>
92 <p>
93 $(gettext "Upload files on the cloud to share them with some other people
94 or use them in your documents content.")
95 </p>
96 <div style="text-align: center;">
97 <form method="post" action="plugins/cloud/cloud.cgi?upcloud&user=$user"
98 enctype="multipart/form-data">
99 <input type="file" name="datafile" size="50" />
100 <input type="submit" value="Upload" />
101 </form>
102 </div>
103 <div id="tools">
104 <a href="$script?cloudlog">Activity</a>
105 <a href="$content/cloud">Raw files</a>
106 <b>Files:</b> $files | <b>Size:</b> $size
107 </div>
108 EOT
109 echo '<pre>'
110 # List all Cloud files
111 for f in $(ls ${cloud})
112 do
113 case $f in
114 *.png|*.jpg|*.gif) image="images/image.png" ;;
115 *) image="images/empty.png" ;;
116 esac
117 cat << EOT
118 <a href="$content/cloud/${f}" title="${WEB_URL}$content/cloud/${f}">\
119 <img src="$image" />${f}</a> : \
120 <a href="$script?rmcloud&name=${f}&user=$user">$(gettext "Remove")</a>
121 EOT
122 done
123 echo '</pre>'
124 html_footer
125 exit 0
126 esac