tinycm rev 28
Bunch of improvments and fixes
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Jan 06 14:49:12 2014 +0000 (2014-01-06) |
parents | dcbb06a29438 |
children | a8bb593bd803 |
files | index.cgi plugins/blog/blog.cgi plugins/cloud/cloud.cgi plugins/export/export.cgi style.css |
line diff
1.1 --- a/index.cgi Sun Jan 05 23:20:19 2014 +0000 1.2 +++ b/index.cgi Mon Jan 06 14:49:12 2014 +0000 1.3 @@ -20,6 +20,7 @@ 1.4 tmp="/tmp/tinycm" 1.5 sessions="$tmp/sessions" 1.6 script="$SCRIPT_NAME" 1.7 +activity="$cache/log/activity.log" 1.8 1.9 # Content negotiation for Gettext 1.10 IFS="," 1.11 @@ -113,6 +114,15 @@ 1.12 EOT 1.13 } 1.14 1.15 +# Log main activity. 1.16 +log_activity() { 1.17 + [ -d "$cache/log" ] || mkdir -p ${cache}/log 1.18 + #gravatar="$(get_gravatar $MAIL 24)" 1.19 + grep ^[A-Z] | \ 1.20 + sed s"#^[A-Z]\([^']*\)#$user|$(date '+%Y-%m-%d')|\0#" \ 1.21 + >> $cache/log/activity.log 1.22 +} 1.23 + 1.24 # Log documents activity. 1.25 log() { 1.26 grep ^[A-Z] | \ 1.27 @@ -134,6 +144,11 @@ 1.28 fi 1.29 } 1.30 1.31 +# Check if user is admin 1.32 +admin_user() { 1.33 + fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf 1.34 +} 1.35 + 1.36 # Authentified or not 1.37 user_box() { 1.38 if check_auth; then 1.39 @@ -240,6 +255,10 @@ 1.40 1.41 EOT 1.42 chmod 0600 $PEOPLE/$user/account.conf 1.43 + # First created user is admin 1.44 + if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then 1.45 + echo 'ADMIN_USER="yes"' >> $PEOPLE/$user/account.conf 1.46 + fi 1.47 } 1.48 1.49 # Display user public profile. 1.50 @@ -320,14 +339,16 @@ 1.51 # Log 1.52 if [ "$new" ]; then 1.53 echo "Page created by: $(link_user)" | log 1.54 + 1.55 if [ "$HG" == "yes" ]; then 1.56 cd $content && hg -q add 1.57 hg commit -q -u "$NAME <$MAIL>" -m "Created new document: $d" 1.58 cd $tiny 1.59 fi 1.60 else 1.61 - # Here we will clean log: cat && tail -n 40 1.62 + # Here we may clean log: cat && tail -n 40 1.63 echo "Page edited by: $(link_user)" | log 1.64 + echo "New document: <a href='$script?d=$d'>$d</a>" | log_activity 1.65 if [ "$HG" == "yes" ]; then 1.66 cd $content && hg commit -q -u "$NAME <$MAIL>" \ 1.67 -m "Edited document: $d" 1.68 @@ -485,6 +506,32 @@ 1.69 header 1.70 html_header 1.71 user_box 1.72 + # Main activity 1.73 + if [ "$d" == "log" ]; then 1.74 + echo "<h2>$(gettext "Activity")</h2>" 1.75 + if check_auth; then 1.76 + echo "<div id='tools'>" 1.77 + echo "<a href='$script?dashboard'>Dashboard</a>" 1.78 + echo "</div>" 1.79 + fi 1.80 + echo '<pre>' 1.81 + if [ -f "$cache/log/activity.log" ]; then 1.82 + IFS="|" 1.83 + tac $cache/log/activity.log | while read USER DATE LOG 1.84 + do 1.85 + . ${PEOPLE}/${USER}/account.conf 1.86 + cat << EOT 1.87 +<a href='$script?user=$USER'>$(get_gravatar $MAIL 24)</a>\ 1.88 +<span class='date'>$DATE -</span> $LOG 1.89 +EOT 1.90 + done 1.91 + unset IFS 1.92 + else 1.93 + gettext "No activity log yet"; echo 1.94 + fi 1.95 + echo '</pre>' 1.96 + html_footer && exit 0 1.97 + fi 1.98 get_lang 1.99 echo "<h2>$(gettext "Activity for:") <a href='$script?d=$d'>$d</a></h2>" 1.100 echo '<pre>' 1.101 @@ -498,6 +545,26 @@ 1.102 wiki_tools 1.103 fi 1.104 html_footer ;; 1.105 + 1.106 + *\ ls\ *) 1.107 + d="Document list" 1.108 + header 1.109 + html_header 1.110 + user_box 1.111 + echo "<h2>$(gettext "Document list")</h2>" 1.112 + if check_auth; then 1.113 + echo "<div id='tools'>" 1.114 + echo "<a href='$script?dashboard'>Dashboard</a>" 1.115 + echo "</div>" 1.116 + fi 1.117 + echo '<pre>' 1.118 + cd ${wiki} 1.119 + for d in $(find . -type f | sed s'/.\///') 1.120 + do 1.121 + echo "<a href='$script?d=${d%.txt}'>${d%.txt}</a>" 1.122 + done 1.123 + echo '</pre>' 1.124 + html_footer ;; 1.125 1.126 *\ diff\ *) 1.127 d="$(GET diff)" 1.128 @@ -569,6 +636,8 @@ 1.129 if check_auth && [ "$(GET user)" == "$user" ]; then 1.130 auth_people 1.131 else 1.132 + # check_auth will set VARS to current logged user: re-source 1.133 + . $PEOPLE/"$(GET user)"/account.conf 1.134 public_people 1.135 fi 1.136 html_footer ;; 1.137 @@ -590,17 +659,28 @@ 1.138 echo "<h2>$d</h2>" 1.139 if check_auth; then 1.140 cat << EOT 1.141 +<div id="tools"> 1.142 + <a href='$script?log'>Activity log</a> 1.143 + <a href='$script?ls'>List files</a> 1.144 +</div> 1.145 + 1.146 <pre> 1.147 Users : $users 1.148 Wiki : $docs ($wikisize) 1.149 Cache : $cachesize 1.150 Mercurial : $hg 1.151 </pre> 1.152 - 1.153 -<div id="tools"> 1.154 - 1.155 -</div> 1.156 - 1.157 +<h3>Admin users</h3> 1.158 +EOT 1.159 + # Get the list of administrators 1.160 + for u in $(ls $PEOPLE) 1.161 + do 1.162 + user=${u} 1.163 + if admin_user; then 1.164 + echo "<a href='?user=$u'>$u</a>" 1.165 + fi 1.166 + done 1.167 + cat << EOT 1.168 <h3>$(gettext "Plugins")</h3> 1.169 <pre> 1.170 EOT
2.1 --- a/plugins/blog/blog.cgi Sun Jan 05 23:20:19 2014 +0000 2.2 +++ b/plugins/blog/blog.cgi Mon Jan 06 14:49:12 2014 +0000 2.3 @@ -21,25 +21,44 @@ 2.4 # Post tools 2.5 post_tools() { 2.6 cat << EOT 2.7 -<div class="post-tools"> 2.8 - ${d}: <a href="$script?blogedit&d=${d}">$(gettext "Edit post")</a> 2.9 -</div> 2.10 + - <a href="$script?blogedit&d=${d}">$(gettext "Edit it!")</a> 2.11 EOT 2.12 +#<a href="$script?blogrm&d=${d}">$(gettext "Remove")</a> 2.13 } 2.14 2.15 # Display blog post: show_posts nb 2.16 +show_post() { 2.17 + d=${1%.txt} 2.18 + date=$(fgrep 'DATE=' ${blog}/${d}.txt | cut -d '"' -f 2) 2.19 + # Get post author 2.20 + author=$(fgrep 'AUTHOR=' ${blog}/${d}.txt | cut -d '"' -f 2) 2.21 + if [ -f "${PEOPLE}/${author}/account.conf" ]; then 2.22 + . ${PEOPLE}/${author}/account.conf 2.23 + else 2.24 + echo ERROR: ${PEOPLE}/${author}/account.conf 2.25 + fi 2.26 + echo "<div class=\"blogpost\">" 2.27 + cat ${blog}/${d}.txt | sed -e '/AUTHOR=/'d -e '/DATE=/'d | wiki_parser 2.28 + cat << EOT 2.29 +<div class="post-tools"> 2.30 + <a href="$script?user=$USER">$(get_gravatar $MAIL 24)</a> 2.31 + <span class="date">$date</span> 2.32 +EOT 2.33 + # Post tools for auth users 2.34 + if check_auth; then 2.35 + post_tools 2.36 + echo "</div>" 2.37 + else 2.38 + echo "</div>" 2.39 + fi 2.40 + echo "</div>" 2.41 +} 2.42 + 2.43 +# Display blog post: show_posts count 2.44 show_posts() { 2.45 - for p in $(find $blog -type f | head -n $1) 2.46 + for p in $(ls -r $blog | head -n $1) 2.47 do 2.48 - name=$(basename $p) 2.49 - d=${name%.txt} 2.50 - echo "<div class=\"blogpost\">" 2.51 - cat ${blog}/${d}.txt | wiki_parser 2.52 - echo "</div>" 2.53 - # Post tools for auth users 2.54 - if check_auth; then 2.55 - post_tools 2.56 - fi 2.57 + show_post ${p} 2.58 done 2.59 } 2.60 2.61 @@ -47,12 +66,11 @@ 2.62 # Index main page can display the lastest Blog posts 2.63 # 2.64 if fgrep -q '[BLOG]' $tiny/$wiki/index.txt && [ ! "$(GET)" ]; then 2.65 - d="Blog" 2.66 + d="Blog posts" 2.67 index="blog" 2.68 header 2.69 html_header 2.70 user_box 2.71 - echo "<h2>$(gettext "Latest blog posts")</h2>" 2.72 # Post tools for auth users 2.73 if check_auth; then 2.74 blog_tools 2.75 @@ -75,8 +93,11 @@ 2.76 fi 2.77 # New post 2.78 if [ "$d" == "new" ]; then 2.79 - d=$(date '+%Y%m%d') 2.80 - [ -f "$blog/$d.txt" ] && d=$(date '+%Y%m%d-%H%M') 2.81 + date=$(date '+%Y-%M-%d') 2.82 + last=$(ls -r $blog | head -n 1) 2.83 + nb=${last%.txt} 2.84 + d=$(($nb + 1)) 2.85 + conf=$(echo -e "\nAUTHOR=\"$user\"\nDATE=\"$date\"\n\n====Title====") 2.86 fi 2.87 cat << EOT 2.88 <h2>$(gettext "Blog post"): $d</h2> 2.89 @@ -84,7 +105,7 @@ 2.90 <div id="edit"> 2.91 <form method="get" action="$script" name="editor"> 2.92 <input type="hidden" name="blogsave" value="$d" /> 2.93 - <textarea name="content">$(cat "$blog/$d.txt")</textarea> 2.94 + <textarea name="content">$conf $(cat "$blog/$d.txt")</textarea> 2.95 <input type="submit" value="$(gettext "Post content")" /> 2.96 $(gettext "Code Helper:") 2.97 $(cat lib/jseditor.html) 2.98 @@ -97,6 +118,12 @@ 2.99 d="$(GET blogsave)" 2.100 if check_auth; then 2.101 [ -d "$blog" ] || mkdir -p ${blog} 2.102 + # New post ? 2.103 + if [ ! -f "${blog}/${d}.txt" ]; then 2.104 + echo "New Blog post: <a href='$script?blog=$d'>Read it!</a>" \ 2.105 + | log_activity 2.106 + fi 2.107 + # Write content to file 2.108 sed "s/$(echo -en '\r') /\n/g" > ${blog}/${d}.txt << EOT 2.109 $(GET content) 2.110 EOT 2.111 @@ -104,12 +131,12 @@ 2.112 header "Location: $script?blog" ;; 2.113 2.114 *\ blog\ *) 2.115 - d="Latest blog posts" 2.116 - nb="20" 2.117 + d="Blog posts" 2.118 + count="20" 2.119 header 2.120 html_header 2.121 user_box 2.122 - echo "<h2>$(gettext "Latest blog posts")</h2>" 2.123 + #echo "<h2>$(gettext "Latest blog posts")</h2>" 2.124 # Blog tools for auth users 2.125 if check_auth; then 2.126 blog_tools 2.127 @@ -120,7 +147,12 @@ 2.128 gettext "Blog plugin is not yet active."; echo "</p>" 2.129 html_footer && exit 0 2.130 fi 2.131 - show_posts ${nb} 2.132 + # Single post 2.133 + if [ "$(GET blog)" != "blog" ]; then 2.134 + show_post "$(GET blog)" 2.135 + else 2.136 + show_posts ${count} 2.137 + fi 2.138 html_footer 2.139 exit 0 ;; 2.140 esac
3.1 --- a/plugins/cloud/cloud.cgi Sun Jan 05 23:20:19 2014 +0000 3.2 +++ b/plugins/cloud/cloud.cgi Mon Jan 06 14:49:12 2014 +0000 3.3 @@ -5,7 +5,7 @@ 3.4 . /usr/lib/slitaz/httphelper 3.5 3.6 cloud="$tiny/$content/cloud" 3.7 -cloudlog="$tiny/$cache/cloud.log" 3.8 +cloudlog="$tiny/$cache/log/cloud.log" 3.9 3.10 case " $(GET) " in 3.11 *\ upcloud\ *) 3.12 @@ -14,7 +14,7 @@ 3.13 [ ! "$(FILE datafile name)" ] && header "Location: $HTTP_REFERER" 3.14 user="$(GET user)" 3.15 cloud="../../content/cloud" 3.16 - cloudlog="../../cache/cloud.log" 3.17 + cloudlog="../../cache/log/cloud.log" 3.18 name=$(FILE datafile name) 3.19 tmpname=$(FILE datafile tmpname) 3.20 # Sanity check 3.21 @@ -93,7 +93,7 @@ 3.22 $(gettext "Upload files on the cloud to share them with some other people 3.23 or use them in your documents content.") 3.24 </p> 3.25 -<div style="text-align: center;""> 3.26 +<div style="text-align: center;"> 3.27 <form method="post" action="plugins/cloud/cloud.cgi?upcloud&user=$user" 3.28 enctype="multipart/form-data"> 3.29 <input type="file" name="datafile" size="50" />
4.1 --- a/plugins/export/export.cgi Sun Jan 05 23:20:19 2014 +0000 4.2 +++ b/plugins/export/export.cgi Mon Jan 06 14:49:12 2014 +0000 4.3 @@ -4,6 +4,14 @@ 4.4 # 4.5 . /usr/lib/slitaz/httphelper 4.6 4.7 +# 4.8 +# NOTE: Exporting wiki and make all url's work is is a bit tricky and 4.9 +# actually don't work as expected. The goal is to have a SliTaz codex 4.10 +# online thta can be include on the ISO, so we could have an export 4.11 +# including a small CGI script to simply display wiki pages via HTTPd 4.12 +# knowing that with HTML we must also deal with ../../ 4.13 +# 4.14 + 4.15 if [ "$(GET export)" ]; then 4.16 d="Export" 4.17 date=$(date "+%Y%m%d") 4.18 @@ -14,8 +22,8 @@ 4.19 cat << EOT 4.20 <h2>Export</h2> 4.21 <p> 4.22 -$(gettext "Export to HTML and create a tarball of your text content or 4.23 -uploaded files.") 4.24 +$(gettext "EXPERIMENTAL: Export to HTML and create a tarball of your text 4.25 +content or plugins files.") 4.26 </p> 4.27 <form method="get" action="$WEB_URL"> 4.28 <select name="export"> 4.29 @@ -50,21 +58,18 @@ 4.30 } 4.31 # Export requested content 4.32 case " $(GET export) " in 4.33 - *\ uploads\ *) 4.34 - export="uploads" 4.35 + *\ cloud\ *) 4.36 + export="cloud" 4.37 tmpdir="content" 4.38 echo '<pre>' 4.39 gettext "Exporting:"; echo " $export" 4.40 gen_tarball 4.41 echo '</pre>' 4.42 dl_link ;; 4.43 - *) 4.44 - [ "$(GET export)" == "export" ] && exit 0 4.45 - export="$(GET export)" 4.46 - format="html" 4.47 + *\ wiki\ *) 4.48 + export="wiki" 4.49 echo '<pre>' 4.50 gettext "Exporting:"; echo " $export" 4.51 - gettext "Creating tmp directory:"; echo " PID $$ DATE $date" 4.52 mkdir -p $tmpdir/$export 4.53 gettext "Copying CSS style and images..."; echo 4.54 cp -a style.css images $tmpdir/$export 4.55 @@ -72,28 +77,35 @@ 4.56 for d in $(find . -type f | sed s'!./!!') 4.57 do 4.58 d=${d%.txt} 4.59 - [ "$d" == "help" ] && continue 4.60 + [ "$d" == "en/help" ] && continue 4.61 gettext "Exporting: "; echo "$d.txt" 4.62 mkdir -p $tmpdir/$export/$(dirname $d) 4.63 f=$tmpdir/$export/$d.html 4.64 - html_header > $f 4.65 - sed -i '/functions.js/'d $f 4.66 - sed -i '/favicon.ico/'d $f 4.67 + html_header > ${f} 4.68 + sed -i '/functions.js/'d ${f} 4.69 + sed -i '/favicon.ico/'d ${f} 4.70 + sed -i s'/index.cgi/index.html/'/ ${f} 4.71 + doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*" 4.72 + # 4.73 + # The sed from wiki url's to html bug if there is 2 link 4.74 + # on same line: [test|Test] tralala [en/index|English] 4.75 + # 4.76 cat $d.txt | wiki_parser | sed \ 4.77 - -e '/functions.js/'d \ 4.78 - -e s'/?d=//'g \ 4.79 - -e s"#href='\([^']*\)*\>#\0.html#"g >> $f 4.80 - html_footer >> $f 4.81 + s"#href='\([^]]*\)?d=\($doc\)'>#href='\2.html'>#"g >> ${f} 4.82 + html_footer >> ${f} 4.83 done 4.84 cd $tmpdir/$export 4.85 - [ "$format" == "html" ] && css_path 4.86 + css_path 4.87 gen_tarball 4.88 - gettext "Removing temporary files..."; echo 4.89 rm -rf $tmp/export/$$ 4.90 echo '</pre>' 4.91 dl_link ;; 4.92 + *\ export\ ) html_footer && exit 0 ;; 4.93 + *) 4.94 + echo '<pre>' 4.95 + gettext "Export not yet implemented for"; echo ": $(GET export)" 4.96 + echo '</pre>' ;; 4.97 esac 4.98 4.99 - html_footer 4.100 - exit 0 4.101 + html_footer && exit 0 4.102 fi
5.1 --- a/style.css Sun Jan 05 23:20:19 2014 +0000 5.2 +++ b/style.css Mon Jan 06 14:49:12 2014 +0000 5.3 @@ -10,7 +10,7 @@ 5.4 img { border: 0pt none; vertical-align: middle; } 5.5 pre { 5.6 overflow: auto; 5.7 - font-size: 96%; 5.8 + font-size: 98%; 5.9 } 5.10 textarea, table { width: 100%; } 5.11 thead { font-weight: bold; } 5.12 @@ -148,10 +148,11 @@ 5.13 padding: 10px; 5.14 } 5.15 5.16 -pre img { padding: 4px; } 5.17 +pre img { margin: 4px 4px 4px 0px; } 5.18 5.19 .error { color: red; } 5.20 .ok { color: green; } 5.21 +.date { color: #666; font-size: 96%; } 5.22 5.23 /* Progress bar */ 5.24 5.25 @@ -213,7 +214,7 @@ 5.26 5.27 #tools { 5.28 padding-top: 10px; 5.29 - margin-top: 20px; 5.30 + margin: 20px 0px; 5.31 /*border-top: 1px dotted #ccc; 5.32 position: fixed; 5.33 bottom: 10px;*/ 5.34 @@ -279,3 +280,10 @@ 5.35 } 5.36 5.37 #footer a { padding: 0 2px; } 5.38 + 5.39 +/* Plugins CSS */ 5.40 + 5.41 +.blogpost { border-bottom: 1px dotted #ddd; } 5.42 +.post-tools { border-bottom: 1px dotted #ddd; padding: 4px 0;} 5.43 +.post-tools a { text-decoration: none; } 5.44 +.post-tools a:hover { text-decoration: underline; }