slitaz-arm view 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 source
1 #!/bin/sh
2 #
3 # TazBerry CGI Plugin - Editor
4 #
6 case " $(GET) " in
7 *\ editor\ *)
8 case " $(GET) " in
9 *\ file\ *)
10 file=$(GET file)
11 html_header "Editor"
12 echo "<h1>Editor: $file</h1>"
13 cat << EOT
14 <div id="actions">
15 <form method="get" action="$script">
16 <input type="hidden" name="editor" />
17 <input type="hidden" name="save" value="$file" />
18 <textarea name="content">$(cat "$file" 2>/dev/null)</textarea>
19 <input type="submit" value="Save file" />
20 </form>
21 </div>
22 EOT
23 ;;
25 *\ save\ *)
26 html_header "Editor"
27 echo "<h1>Editor</h1>"
28 echo '<pre>'
29 echo "Saving file : $(GET save)"
30 sed "s/$(echo -en '\r') /\n/g" > $(GET save) << EOT
31 $(GET content)
32 EOT
33 echo "File size : $(du -h $(GET save) | awk '{print $1}')"
34 echo '</pre>'
35 echo "<p><a href='$script?editor'>Editor</a></p>"
36 if [ -d "$cache" ]; then
37 echo "" >> ${cache}/editor.log
38 fi ;;
40 *)
41 html_header "Editor"
42 echo "<h1>Editor</h1>"
43 cat << EOT
44 <div id="actions">
45 <form method="get" action="$script">
46 <input type="hidden" name="editor" />
47 <input type="text" name="file" value="$file" placeholder="File path" />
48 <input type="submit" value="View or edit" />
49 </form>
50 </div>
51 EOT
52 ;;
53 esac
55 html_footer
56 exit 0 ;;
57 esac