tazpanel view index.cgi @ rev 144

index.cgi: add top button
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Apr 17 13:23:15 2011 +0200 (2011-04-17)
parents 7855bd81abb7
children 29a4a55db6e3
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 - BSD License
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 # Check whether a configuration file has been modified after installation
16 file_is_modified()
17 {
18 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
20 # Found, but can we do diff ?
21 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
22 org=$(dirname $file)/volatile.cpio.gz
23 zcat $org 2>/dev/null | cpio -t 2>/dev/null | \
24 grep -q "^${1#/}$" || break
26 case "$2" in
27 diff)
28 tmp=/tmp/tazpanel$$
29 mkdir -p $tmp
30 ( cd $tmp ; zcat $org | cpio -id ${1#/} )
31 diff -u $tmp$1 $1
32 rm -rf $tmp ;;
33 button)
34 cat <<EOT
35 <a class="button" href='$SCRIPT_NAME?file=$1&action=diff'>
36 <img src="$IMAGES/help.png" />`gettext "Differences"`</a>
37 EOT
38 esac
39 break
40 done
41 }
43 #
44 # Things to do before displaying the page
45 #
47 [ -n "$(GET panel_pass)" ] &&
48 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
50 #
51 # Commands
52 #
54 case " $(GET) " in
55 *\ file\ *)
56 #
57 # Handle files
58 #
59 TITLE="- File"
60 xhtml_header
61 file="$(GET file)"
62 echo "<h2>$file</h2>"
63 if [ "$(GET action)" == "edit" ]; then
64 cat <<EOT
65 <form method="post" action="$SCRIPT_NAME?file=$file">
66 <img src="$IMAGES/edit.png" />
67 <input type="submit" value="`gettext "Save"`">
68 <textarea name="content" rows="30" style="width: 100%;">
69 $(cat $file)
70 </textarea>
71 </form>
72 EOT
73 elif [ "$(GET action)" == "diff" ]; then
74 echo '<pre id="diff">'
75 file_is_modified $file diff | syntax_highlighter diff
76 echo '</pre>'
77 else
78 [ -n "$(POST content)" ] &&
79 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
80 $(POST content)
81 EOT
82 cat <<EOT
83 <div id="actions">
84 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
85 <img src="$IMAGES/edit.png" />`gettext "Edit"`</a>
86 EOT
87 file_is_modified $file button
88 echo -e "</div>\n<pre>"
89 # Handle file type by extension as a Web Server does it.
90 case "$file" in
91 *.conf|*.lst)
92 syntax_highlighter conf ;;
93 *.sh|*.cgi)
94 syntax_highlighter sh ;;
95 *)
96 cat ;;
97 esac < $file
98 echo '</pre>'
99 fi ;;
100 *\ top\ *)
101 TITLE="- $(gettext "Process activity")"
102 xhtml_header
103 echo '<pre>'
104 top -n1 -b
105 echo '</pre>' ;;
106 *\ debug\ *)
107 TITLE="- Debug"
108 xhtml_header
109 echo '<h2>HTTP Environment</h2>'
110 echo '<pre>'
111 httpinfo
112 echo '</pre>' ;;
113 *)
114 #
115 # Default xHTML content
116 #
117 xhtml_header
118 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
119 [ -n "$(GET rdate)" ] && echo ""
120 cat << EOT
121 <div id="wrapper">
122 <h2>`gettext "Host:"` `hostname`</h2>
123 <p>`gettext "SliTaz administration and configuration Panel"`<p>
124 </div>
126 <h3>`gettext "Summary"`</h3>
127 <div id="summary">
128 <p>
129 `gettext "Uptime:"` `uptime`
130 <a class="button" href="$SCRIPT_NAME?top">
131 <img src="$IMAGES/recharge.png" />`gettext "Process activity"`</a>
132 </p>
133 <p>
134 `gettext "Memory in Mb"`
135 `free -m | grep Mem: | awk \
136 '{print "| Total:", $2, "| Used:", $3, "| Free:", $4}'`
137 </p>
138 <!-- Close summary -->
139 </div>
141 <h4>`gettext "Network status"`</h4>
142 `list_network_interfaces`
144 <h4>`gettext "Filesystem usage statistics"`</h4>
145 <pre>
146 `df -h | grep ^/dev`
147 </pre>
149 <h3>`gettext "Panel Activity"`</h3>
150 <pre id="panel-activity">
151 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
152 </pre>
154 EOT
155 ;;
156 esac
158 xhtml_footer
159 exit 0