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

Add CGI SHell toolkit for ARM devices
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 15 16:42:19 2014 +0100 (2014-03-15)
parents
children e357535f1b91
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cgi-adm/plugins/editor/editor.cgi	Sat Mar 15 16:42:19 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# TazBerry CGI Plugin - Editor
     1.7 +#
     1.8 +
     1.9 +case " $(GET) " in
    1.10 +		*\ editor\ *)
    1.11 +			case " $(GET) " in
    1.12 +				*\ file\ *)
    1.13 +					file=$(GET file)
    1.14 +					html_header "Editor"
    1.15 +					echo "<h1>Editor: $file</h1>"
    1.16 +					cat << EOT
    1.17 +<div id="actions">
    1.18 +	<form method="get" action="$script">
    1.19 +		<input type="hidden" name="editor" />
    1.20 +		<input type="hidden" name="save" value="$file" />
    1.21 +		<textarea name="content">$(cat "$file" 2>/dev/null)</textarea>
    1.22 +		<input type="submit" value="Save file" />
    1.23 +	</form>
    1.24 +</div>
    1.25 +EOT
    1.26 +					;;
    1.27 +				
    1.28 +				*\ save\ *)
    1.29 +					html_header "Editor"
    1.30 +					echo "<h1>Editor</h1>"
    1.31 +					echo '<pre>'
    1.32 +					echo "Saving file : $(GET save)"
    1.33 +					sed "s/$(echo -en '\r') /\n/g" > $(GET save) << EOT
    1.34 +$(GET content)
    1.35 +EOT
    1.36 +					echo "File size   : $(du -h $(GET save) | awk '{print $1}')"
    1.37 +					echo '</pre>'
    1.38 +					echo "<p><a href='$script?editor'>Editor</a></p>"
    1.39 +					if [ -d "$cache" ]; then
    1.40 +						echo "" >> ${cache}/editor.log
    1.41 +					fi ;;
    1.42 +				
    1.43 +				*)
    1.44 +					html_header "Editor"
    1.45 +					echo "<h1>Editor</h1>"
    1.46 +					cat << EOT
    1.47 +<div id="actions">
    1.48 +	<form method="get" action="$script">
    1.49 +		<input type="hidden" name="editor" />
    1.50 +		<input type="text" name="file" value="$file" placeholder="File path" />
    1.51 +		<input type="submit" value="View or edit" />
    1.52 +	</form>
    1.53 +</div>
    1.54 +EOT
    1.55 +					;;
    1.56 +			esac
    1.57 +			
    1.58 +		html_footer
    1.59 +		exit 0 ;;
    1.60 +esac