tazpanel view index.cgi @ rev 161

Add report creation (to help debbuging)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 21 17:21:12 2011 +0200 (2011-04-21)
parents 2b919224c683
children 3a6f2e0ddaea
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 file="$(GET file)"
60 case $file in
61 *.html)
62 cat $file && exit 0 ;;
63 *)
64 TITLE="- File"
65 xhtml_header
66 echo "<h2>$file</h2>" ;;
67 esac
68 if [ "$(GET action)" == "edit" ]; then
69 cat <<EOT
70 <form method="post" action="$SCRIPT_NAME?file=$file">
71 <img src="$IMAGES/edit.png" />
72 <input type="submit" value="`gettext "Save"`">
73 <textarea name="content" rows="30" style="width: 100%;">
74 $(cat $file)
75 </textarea>
76 </form>
77 EOT
78 elif [ "$(GET action)" == "diff" ]; then
79 echo '<pre id="diff">'
80 file_is_modified $file diff | syntax_highlighter diff
81 echo '</pre>'
82 else
83 [ -n "$(POST content)" ] &&
84 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
85 $(POST content)
86 EOT
87 cat <<EOT
88 <div id="actions">
89 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
90 <img src="$IMAGES/edit.png" />`gettext "Edit"`</a>
91 EOT
92 file_is_modified $file button
93 echo -e "</div>\n<pre>"
94 # Handle file type by extension as a Web Server does it.
95 case "$file" in
96 *.conf|*.lst)
97 syntax_highlighter conf ;;
98 *.sh|*.cgi)
99 syntax_highlighter sh ;;
100 *)
101 cat ;;
102 esac < $file
103 echo '</pre>'
104 fi ;;
105 *\ top\ *)
106 TITLE="- $(gettext "Process activity")"
107 xhtml_header
108 echo '<pre>'
109 top -n1 -b | sed \
110 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
111 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
112 echo '</pre>' ;;
113 *\ debug\ *)
114 TITLE="- Debug"
115 xhtml_header
116 echo '<h2>HTTP Environment</h2>'
117 echo '<pre>'
118 httpinfo
119 echo '</pre>' ;;
120 *\ report\ *)
121 TITLE="- $(gettext "System report")"
122 output=/var/cache/slitaz/sys-report.html
123 xhtml_header
124 echo "<h2>$(gettext "Reporting to:") $output</h2>"
125 echo '<pre>'
126 gettext "Creating report header... "
127 cat > $output << EOT
128 <!DOCTYPE html>
129 <html xmlns="http://www.w3.org/1999/xhtml">
130 <head>
131 <title>SliTaz system report</title>
132 <style type="text/css">
133 body { padding: 20px 60px; font-size: 13px; } h1, h2 { color: #444; }
134 pre { background: #f1f1f1; border: 1px solid #ddd;
135 padding: 10px; border-radius: 4px; }
136 </style>
137 </head>
138 <body>
139 EOT
140 ok_status
141 gettext "Creating system summary... "
142 cat >> $output << EOT
143 <h1>SliTaz system report</h1>
144 Date: $(date)
145 <pre>
146 uptime :$(uptime)
147 cmdline : $(cat /proc/cmdline)
148 version : $(cat /etc/slitaz-release)
149 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
150 kernel : $(uname -r)
151 </pre>
152 EOT
153 ok_status
154 gettext "Getting hardware info... "
155 cat >> $output << EOT
156 <h2>free</h2>
157 <pre>
158 $(free)
159 </pre>
161 <h2>lspci -k</h2>
162 <pre>
163 $(lspci -k)
164 </pre>
166 <h2>lsusb</h2>
167 <pre>
168 $(lsusb)
169 </pre>
171 <h2>lsmod</h2>
172 <pre>
173 $(lsmod)
174 </pre>
176 EOT
177 ok_status
178 gettext "Getting networking info... "
179 cat >> $output << EOT
180 <h2>ifconfig -a</h2>
181 <pre>
182 $(ifconfig -a)
183 </pre>
184 EOT
185 ok_status
186 gettext "Creating report footer... "
187 cat cat >> $output << EOT
188 </body>
189 </html>
190 EOT
191 ok_status
192 echo '</pre>'
193 echo "<p><a class='button' href='$SCRIPT_NAME?file=$output'>
194 $(gettext "View report")</a>"
195 gettext "This report can be attached with a bug report on: "
196 echo '<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>' ;;
197 *)
198 #
199 # Default xHTML content
200 #
201 xhtml_header
202 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
203 [ -n "$(GET rdate)" ] && echo ""
204 cat << EOT
205 <div id="wrapper">
206 <h2>$(gettext "Host:") $(hostname)</h2>
207 <p>$(gettext "SliTaz administration and configuration Panel")<p>
208 </div>
209 <div id="actions">
210 <a class="button" href="$SCRIPT_NAME?top">
211 <img src="$IMAGES/monitor.png" />$(gettext "Process activity")</a>
212 <a class="button" href="$SCRIPT_NAME?report">
213 <img src="$IMAGES/text.png" />$(gettext "Create a report")</a>
214 </div>
216 <h3>$(gettext "Summary")</h3>
217 <div id="summary">
218 <pre>
219 $(gettext "Uptime :")$(uptime)
220 $(gettext "Memory in Mb :") $(free -m | grep Mem: | awk \
221 '{print "Total:", $2, "Used:", $3, "Free:", $4}')
222 $(gettext "Linux kernel :") $(uname -r)
223 </pre>
224 <!-- Close summary -->
225 </div>
227 <h4>$(gettext "Network status")</h4>
228 $(list_network_interfaces)
230 <h4>$(gettext "Filesystem usage statistics")</h4>
231 EOT
232 # Disk stats (management is done as hardware.cgi)
233 table_start
234 df_thead
235 df -h | grep ^/dev | while read fs size used av pct mp
236 do
237 cat << EOT
238 <tr>
239 <td><a href="hardware.cgi">
240 <img src="$IMAGES/harddisk.png" />$fs</a></td>
241 <td>$size</td>
242 <td>$av</td>
243 <td class="pct"><div class="pct"
244 style="width: $pct;">$used - $pct</div></td>
245 <td>$mp</td>
246 </tr>
247 EOT
248 done
249 table_end
250 cat << EOT
251 <h3>$(gettext "Panel Activity")</h3>
252 <pre id="panel-activity">
253 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
254 </pre>
256 EOT
257 ;;
258 esac
260 xhtml_footer
261 exit 0