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

Some small fixes and improvments
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 11 17:04:56 2017 +0100 (2017-02-11)
parents 8d24e0cbcdab
children 97dca04ea0fa
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 [ -f "$cloudlog" ] || mkdir -p $(dirname $cloudlog)
91 cat << EOT
92 <div id="tools">
93 <a href="$script?cloudlog">Cloud activity</a>
94 <a href="$content/cloud">Raw files</a>
95 <a href="$script?dashboard">Dashboard</a>
96 </div>
98 <h2>Cloud files</h2>
100 <p>
101 $(gettext "Upload files on the cloud to share them with some other people
102 or use them in your documents content. Tip: Drag and Drop files from your
103 desktop.")
104 </p>
105 <div id="cloud-upload">
106 <form method="post" action="plugins/cloud/cloud.cgi?upcloud&amp;user=$user"
107 enctype="multipart/form-data">
108 <input type="file" name="datafile" size="50" />
109 <input type="submit" value="Upload" />
110 </form>
111 </div>
112 <p>
113 <b>Files:</b> $files | <b>Size:</b> $size
114 </p>
115 EOT
116 echo '<pre>'
117 # List all Cloud files
118 for f in $(ls ${cloud})
119 do
120 case $f in
121 *.png|*.jpg|*.gif) image="images/image.png" ;;
122 *) image="images/empty.png" ;;
123 esac
124 cat << EOT
125 <a href="$content/cloud/${f}" title="${WEB_URL}$content/cloud/${f}">\
126 <img src="$image" />${f}</a> : \
127 <a href="$script?rmcloud&amp;name=${f}&amp;user=$user">$(gettext "Remove")</a>
128 EOT
129 done
130 echo '</pre>'
131 html_footer
132 exit 0
133 esac