slitaz-arm diff cgi-adm/plugins/editor/editor.cgi @ rev 219

dot command may not search current directory first
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 23 13:50:45 2017 +0200 (2017-07-23)
parents e357535f1b91
children
line diff
     1.1 --- a/cgi-adm/plugins/editor/editor.cgi	Sun Apr 13 00:56:19 2014 +0200
     1.2 +++ b/cgi-adm/plugins/editor/editor.cgi	Sun Jul 23 13:50:45 2017 +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