tazpanel view index.cgi @ 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 | 25602bc63ca7 |
children | 783e2405d384 |
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for TazPanel. In on word: KISS. Use the main css form
4 # command so we are faster and do not load unneeded functions. If necessary
5 # you can use the lib/ dir to handle external resources.
6 #
7 # Copyright (C) 2011 SliTaz GNU/Linux - GNU gpl v3
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 # Include gettext helper script.
16 . /usr/bin/gettext.sh
18 # Export package name for gettext.
19 TEXTDOMAIN='tazpanel'
20 export TEXTDOMAIN
22 #
23 # Things to do before displaying the page
24 #
26 [ -n "$(GET panel_pass)" ] &&
27 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
29 #
30 # Commands
31 #
33 case " $(GET) " in
34 *\ file\ *)
35 #
36 # Handle files (may have an edit function, we will see)
37 #
38 TITLE="- File"
39 xhtml_header
40 file="$(GET file)"
41 echo "<h2>$file</h2>"
42 if [ "$(GET action)" == "edit" ]; then
43 cat <<EOT
44 <form method="post" action="/index.cgi?file=$file">
45 <img src="/styles/default/images/edit.png" />
46 <input type="submit" value="`gettext "Save"`">
47 <textarea name="content" rows="30" style="width: 100%;">
48 $(cat $file)
49 </textarea>
50 </form>
51 EOT
52 else
53 [ -n "$(POST content)" ] &&
54 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
55 $(POST content)
56 EOT
57 cat <<EOT
58 <div id="actions">
59 <a class="button" href='/index.cgi?file=$file&action=edit'>
60 <img src="/styles/default/images/edit.png" />`gettext "Edit"`</a>
62 </div>
63 <pre>
64 EOT
65 # Handle file type by extension as a Web Server does it.
66 case "$file" in
67 *.conf|*.lst)
68 syntax_highlighter conf ;;
69 *.sh|*.cgi)
70 syntax_highlighter sh ;;
71 *)
72 cat ;;
73 esac < $file
74 echo '</pre>'
75 fi ;;
76 *\ debug\ *)
77 TITLE="- Debug"
78 xhtml_header
79 echo '<h2>HTTP Environment</h2>'
80 echo '<pre>'
81 httpinfo
82 echo '</pre>' ;;
83 *)
84 #
85 # Default xHTML content
86 #
87 xhtml_header
88 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
89 [ -n "$(GET rdate)" ] && echo ""
90 cat << EOT
91 <div id="wrapper">
92 <h2>`gettext "Host:"` `hostname`</h2>
93 <p>`gettext "SliTaz administration and configuration Panel"`<p>
94 </div>
96 <h3>`gettext "Summary"`</h3>
97 <div id="summary">
98 <p>
99 `gettext "Uptime:"` `uptime`
100 </p>
101 <p>
102 `gettext "Memory in Mb"`
103 `free -m | grep Mem: | awk \
104 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
105 </p>
106 <!-- Close summary -->
107 </div>
109 <h4>`gettext "Network status"`</h4>
110 `list_network_interfaces`
112 <h4>`gettext "Filesystem usage statistics"`</h4>
113 <pre>
114 `df -h | grep ^/dev`
115 </pre>
117 <h3>`gettext "Panel Activity"`</h3>
118 <pre>
119 $(cat $LOG_FILE | tail -n 6)
120 </pre>
122 <h3>`gettext "Panel settings"`</h3>
123 <form method="get" action="$SCRIPT_NAME">
124 <div>
125 `gettext "Panel password:"`
126 <input type="password" name="panel_pass"/>
127 <input type="submit" value="`gettext "Change"`" />
128 </div>
129 </form>
130 <p>
131 $(gettext "TazPanel provides a debuging mode and page:")
132 <a href='$SCRIPT_NAME?debug'>debug</a>
133 </p>
135 EOT
136 ;;
137 esac
139 xhtml_footer
140 exit 0