slitaz-arm rev 139

Small improvment to editr and use cache dir
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 26 12:41:01 2014 +0200 (2014-04-26)
parents e785c2b0ea5a
children 71b3777ac5f1
files cgi-adm/plugins/editor/editor.cgi cgi-adm/tools.cgi rpi/cgi-adm/plugins/rpi_cam/rpi_cam.cgi
line diff
     1.1 --- a/cgi-adm/plugins/editor/editor.cgi	Sat Apr 26 12:06:42 2014 +0200
     1.2 +++ b/cgi-adm/plugins/editor/editor.cgi	Sat Apr 26 12:41:01 2014 +0200
     1.3 @@ -8,12 +8,14 @@
     1.4  		case " $(GET) " in
     1.5  			*\ file\ *)
     1.6  				file=$(GET file)
     1.7 +				from=$(GET from)
     1.8  				html_header "Editor"
     1.9  				echo "<h1>Editor: $file</h1>"
    1.10  				cat << EOT
    1.11  <div id="actions">
    1.12  	<form method="get" action="$script">
    1.13  		<input type="hidden" name="editor" />
    1.14 +		<input type="hidden" name="from" value="$from" />
    1.15  		<input type="hidden" name="save" value="$file" />
    1.16  		<textarea name="content">$(cat "$file" 2>/dev/null)</textarea>
    1.17  		<input type="submit" value="Save file" />
    1.18 @@ -23,22 +25,30 @@
    1.19  				;;
    1.20  				
    1.21  			*\ save\ *)
    1.22 +				file="$(GET save)"
    1.23 +				from=$(GET from)
    1.24 +				logfile="$cache/editor.log"
    1.25  				html_header "Editor"
    1.26 +				mkdir -p ${cache} && touch ${logfile}
    1.27  				echo "<h1>Editor</h1>"
    1.28  				echo '<pre>'
    1.29 -				echo "Saving file : $(GET save)"
    1.30 -				sed "s/$(echo -en '\r') /\n/g" > $(GET save) << EOT
    1.31 +				echo "Saving file : $file"
    1.32 +				sed "s/$(echo -en '\r') /\n/g" > ${file} << EOT
    1.33  $(GET content)
    1.34  EOT
    1.35 -				echo "File size   : $(du -h $(GET save) | awk '{print $1}')"
    1.36 +				echo "Md5sum      : $(md5sum $file | awk '{print $1}')"
    1.37 +				echo "File size   : $(du -h $file | awk '{print $1}')"
    1.38  				echo '</pre>'
    1.39 -				echo "<p><a href='$script?editor'>Editor</a></p>"
    1.40 -				if [ -d "$cache" ]; then
    1.41 -					echo "" >> ${cache}/editor.log
    1.42 -				fi ;;
    1.43 +				echo "<p><a href='$script?editor'>Editor</a> -"
    1.44 +				[ "$from" ] && echo "Back to: <a href='$script${from}'>${from#?}</a>"
    1.45 +				echo '</p>'
    1.46 +				echo "<a href='$script?editor&amp;file=$file'>$file</a>" >> ${logfile} ;;
    1.47  				
    1.48  			*)
    1.49 +				logfile="$cache/editor.log"
    1.50  				html_header "Editor"
    1.51 +				[ "$(GET editor)" == "clean_log" ] && rm -f ${logfile}
    1.52 +				mkdir -p ${cache} && touch ${logfile}
    1.53  				echo "<h1>Editor</h1>"
    1.54  				cat << EOT
    1.55  <div id="actions">
    1.56 @@ -48,6 +58,15 @@
    1.57  		<input type="submit" value="View or edit" />
    1.58  	</form>
    1.59  </div>
    1.60 +
    1.61 +<h2>Latest edits</h2>
    1.62 +<pre>
    1.63 +$(tac $logfile | head -n 8)
    1.64 +</pre>
    1.65 +<div class="button">
    1.66 +	<a href="$script?editor=clean_log">Clean logs</a>
    1.67 +</div>
    1.68 +
    1.69  EOT
    1.70  				;;
    1.71  		esac	
     2.1 --- a/cgi-adm/tools.cgi	Sat Apr 26 12:06:42 2014 +0200
     2.2 +++ b/cgi-adm/tools.cgi	Sat Apr 26 12:41:01 2014 +0200
     2.3 @@ -15,6 +15,7 @@
     2.4  plugins="$(pwd)/plugins"
     2.5  script="$SCRIPT_NAME"
     2.6  data="$(pwd)/data"
     2.7 +cache="$(pwd)/cache"
     2.8  
     2.9  #
    2.10  # Functions
     3.1 --- a/rpi/cgi-adm/plugins/rpi_cam/rpi_cam.cgi	Sat Apr 26 12:06:42 2014 +0200
     3.2 +++ b/rpi/cgi-adm/plugins/rpi_cam/rpi_cam.cgi	Sat Apr 26 12:41:01 2014 +0200
     3.3 @@ -30,7 +30,7 @@
     3.4  			*\ shot\ *)
     3.5  				opts="$(GET options)"
     3.6  				notify "Executing: raspistill $opts"
     3.7 -				echo "$opts" > ${camdir}/shot.opts
     3.8 +				echo "$opts" > ${cache}/shot.opts
     3.9  				raspistill ${opts} -o ${camdir}/shot.jpg 
    3.10  				notify hide ;;
    3.11  			*\ rm_shot\ *)
    3.12 @@ -38,8 +38,8 @@
    3.13  		esac
    3.14  		
    3.15  		# Get last used options
    3.16 -		if [ -f "${camdir}/shot.opts" ]; then
    3.17 -			shot_opts="$(cat ${camdir}/shot.opts)"
    3.18 +		if [ -f "$cache/shot.opts" ]; then
    3.19 +			shot_opts="$(cat $cache/shot.opts)"
    3.20  		else
    3.21  			shot_opts="--width 480 --height 320"
    3.22  		fi