slitaz-arm view 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 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 from=$(GET from)
12 html_header "Editor"
13 echo "<h1>Editor: $file</h1>"
14 cat << EOT
15 <div id="actions">
16 <form method="get" action="$script">
17 <input type="hidden" name="editor" />
18 <input type="hidden" name="from" value="$from" />
19 <input type="hidden" name="save" value="$file" />
20 <textarea name="content">$(cat "$file" 2>/dev/null)</textarea>
21 <input type="submit" value="Save file" />
22 </form>
23 </div>
24 EOT
25 ;;
27 *\ save\ *)
28 file="$(GET save)"
29 from=$(GET from)
30 logfile="$cache/editor.log"
31 html_header "Editor"
32 mkdir -p ${cache} && touch ${logfile}
33 echo "<h1>Editor</h1>"
34 echo '<pre>'
35 echo "Saving file : $file"
36 sed "s/$(echo -en '\r') /\n/g" > ${file} << EOT
37 $(GET content)
38 EOT
39 echo "Md5sum : $(md5sum $file | awk '{print $1}')"
40 echo "File size : $(du -h $file | awk '{print $1}')"
41 echo '</pre>'
42 echo "<p><a href='$script?editor'>Editor</a> -"
43 [ "$from" ] && echo "Back to: <a href='$script${from}'>${from#?}</a>"
44 echo '</p>'
45 echo "<a href='$script?editor&amp;file=$file'>$file</a>" >> ${logfile} ;;
47 *)
48 logfile="$cache/editor.log"
49 html_header "Editor"
50 [ "$(GET editor)" == "clean_log" ] && rm -f ${logfile}
51 mkdir -p ${cache} && touch ${logfile}
52 echo "<h1>Editor</h1>"
53 cat << EOT
54 <div id="actions">
55 <form method="get" action="$script">
56 <input type="hidden" name="editor" />
57 <input type="text" name="file" value="$file" placeholder="File path" />
58 <input type="submit" value="View or edit" />
59 </form>
60 </div>
62 <h2>Latest edits</h2>
63 <pre>
64 $(tac $logfile | head -n 8)
65 </pre>
66 <div class="button">
67 <a href="$script?editor=clean_log">Clean logs</a>
68 </div>
70 EOT
71 ;;
72 esac
73 html_footer
74 exit 0 ;;
75 esac