tazpanel rev 90

index.cgi: add edit button
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 14 13:14:34 2011 +0200 (2011-04-14)
parents 67f880abcf5e
children 783e2405d384
files index.cgi
line diff
     1.1 --- a/index.cgi	Thu Apr 14 04:32:43 2011 +0200
     1.2 +++ b/index.cgi	Thu Apr 14 13:14:34 2011 +0200
     1.3 @@ -39,17 +39,40 @@
     1.4  		xhtml_header
     1.5  		file="$(GET file)"
     1.6  		echo "<h2>$file</h2>"
     1.7 -		echo '<pre>'
     1.8 -		# Handle file type by extension as a Web Server does it.
     1.9 -		case "$file" in
    1.10 -			*.conf|*.lst)
    1.11 -				syntax_highlighter conf ;;
    1.12 -			*.sh|*.cgi)
    1.13 -				syntax_highlighter sh ;;
    1.14 -			*)
    1.15 -				cat ;;
    1.16 -		esac < $file
    1.17 -		echo '</pre>' ;;
    1.18 +		if [ "$(GET action)" == "edit" ]; then
    1.19 +			cat <<EOT
    1.20 +<form method="post" action="/index.cgi?file=$file">
    1.21 +<img src="/styles/default/images/edit.png" />
    1.22 +<input type="submit" value="`gettext "Save"`">
    1.23 +<textarea name="content" rows="30" style="width: 100%;">
    1.24 +$(cat $file)
    1.25 +</textarea>
    1.26 +</form>
    1.27 +EOT
    1.28 +		else
    1.29 +			[ -n "$(POST content)" ] && 
    1.30 +				sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
    1.31 +$(POST content)
    1.32 +EOT
    1.33 +			cat <<EOT
    1.34 +<div id="actions">
    1.35 +	<a class="button" href='/index.cgi?file=$file&action=edit'>
    1.36 +		<img src="/styles/default/images/edit.png" />`gettext "Edit"`</a>
    1.37 +			
    1.38 +</div>
    1.39 +<pre>
    1.40 +EOT
    1.41 +			# Handle file type by extension as a Web Server does it.
    1.42 +			case "$file" in
    1.43 +				*.conf|*.lst)
    1.44 +					syntax_highlighter conf ;;
    1.45 +				*.sh|*.cgi)
    1.46 +					syntax_highlighter sh ;;
    1.47 +				*)
    1.48 +					cat ;;
    1.49 +			esac < $file
    1.50 +			echo '</pre>'
    1.51 +		fi ;;
    1.52  	*\ debug\ *)
    1.53  		TITLE="- Debug"
    1.54  		xhtml_header