tinycm view plugins/cloud/cloud.cgi @ 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 190b9ba3af06
children 4418f0315c8e
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">Cloud activity</a>
93 <a href="$content/cloud">Raw files</a>
94 <a href="$script?dashboard">Dashboard</a>
95 </div>
97 <h2>Cloud files</h2>
99 <p>
100 $(gettext "Upload files on the cloud to share them with some other people
101 or use them in your documents content. Tip: Drag and Drop files from your
102 desktop.")
103 </p>
104 <div style="text-align: center;">
105 <form method="post" action="plugins/cloud/cloud.cgi?upcloud&amp;user=$user"
106 enctype="multipart/form-data">
107 <input type="file" name="datafile" size="50" />
108 <input type="submit" value="Upload" />
109 </form>
110 </div>
111 <p>
112 <b>Files:</b> $files | <b>Size:</b> $size
113 </p>
114 EOT
115 echo '<pre>'
116 # List all Cloud files
117 for f in $(ls ${cloud})
118 do
119 case $f in
120 *.png|*.jpg|*.gif) image="images/image.png" ;;
121 *) image="images/empty.png" ;;
122 esac
123 cat << EOT
124 <a href="$content/cloud/${f}" title="${WEB_URL}$content/cloud/${f}">\
125 <img src="$image" />${f}</a> : \
126 <a href="$script?rmcloud&amp;name=${f}&amp;user=$user">$(gettext "Remove")</a>
127 EOT
128 done
129 echo '</pre>'
130 html_footer
131 exit 0
132 esac