tazpanel view index.cgi @ rev 163

index.cgi: add filesystem info & boot log in report
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Apr 22 09:43:58 2011 +0200 (2011-04-22)
parents 6e757e629f77
children 17f82937866a
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 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
123 output=/var/cache/slitaz/sys-report.html
124 xhtml_header
125 echo "<h2>$(gettext "Reporting to:") $output</h2>"
126 echo '<pre>'
127 gettext "Creating report header... "
128 cat > $output << EOT
129 <!DOCTYPE html>
130 <html xmlns="http://www.w3.org/1999/xhtml">
131 <head>
132 <title>SliTaz system report</title>
133 <style type="text/css">
134 body { padding: 20px 60px; font-size: 13px; } h1, h2 { color: #444; }
135 pre { background: #f1f1f1; border: 1px solid #ddd;
136 padding: 10px; border-radius: 4px; }
137 </style>
138 </head>
139 <body>
140 EOT
141 ok_status
142 gettext "Creating system summary... "
143 cat >> $output << EOT
144 <h1>SliTaz system report</h1>
145 Date: $(date)
146 <pre>
147 uptime : $(uptime)
148 cmdline : $(cat /proc/cmdline)
149 version : $(cat /etc/slitaz-release)
150 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
151 kernel : $(uname -r)
152 </pre>
153 EOT
154 ok_status
155 gettext "Getting hardware info... "
156 cat >> $output << EOT
157 <h2>free</h2>
158 <pre>
159 $(free)
160 </pre>
162 <h2>lspci -k</h2>
163 <pre>
164 $(lspci -k)
165 </pre>
167 <h2>lsusb</h2>
168 <pre>
169 $(lsusb)
170 </pre>
172 <h2>lsmod</h2>
173 <pre>
174 $(lsmod)
175 </pre>
177 EOT
178 ok_status
179 gettext "Getting networking info... "
180 cat >> $output << EOT
181 <h2>ifconfig -a</h2>
182 <pre>
183 $(ifconfig -a)
184 </pre>
185 <h2>route -n</h2>
186 <pre>
187 $(route -n)
188 </pre>
189 <h2>/etc/resolv.conf</h2>
190 <pre>
191 $(cat /etc/resolv.conf)
192 </pre>
193 EOT
194 ok_status
195 gettext "Getting filesystems info..."
196 cat >> $output << EOT
197 <h2>blkid</h2>
198 <pre>
199 $(blkid)
200 </pre>
201 <h2>fdisk -l</h2>
202 <pre>
203 $(fdisk -l)
204 </pre>
205 <h2>mount</h2>
206 <pre>
207 $(mount)
208 </pre>
209 <h2>df -h</h2>
210 <pre>
211 $(df -h)
212 </pre>
213 <h2>df -i</h2>
214 <pre>
215 $(df -i)
216 </pre>
217 EOT
218 ok_status
219 gettext "Getting boot logs... "
220 cat >> $output << EOT
221 <h2>$(gettext "Kernel messages")</h2>
222 <pre>
223 $(cat /var/log/dmesg.log)
224 </pre>
225 <h2>$(gettext "Boot scripts")</h2>
226 <pre>
227 $(cat /var/log/boot.log | filter_taztools_msgs)
228 </pre>
229 EOT
230 ok_status
231 gettext "Creating report footer... "
232 cat cat >> $output << EOT
233 </body>
234 </html>
235 EOT
236 ok_status
237 echo '</pre>'
238 echo "<p><a class='button' href='$SCRIPT_NAME?file=$output'>
239 $(gettext "View report")</a>"
240 gettext "This report can be attached with a bug report on: "
241 echo '<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>' ;;
242 *)
243 #
244 # Default xHTML content
245 #
246 xhtml_header
247 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
248 [ -n "$(GET rdate)" ] && echo ""
249 cat << EOT
250 <div id="wrapper">
251 <h2>$(gettext "Host:") $(hostname)</h2>
252 <p>$(gettext "SliTaz administration and configuration Panel")<p>
253 </div>
254 <div id="actions">
255 <a class="button" href="$SCRIPT_NAME?top">
256 <img src="$IMAGES/monitor.png" />$(gettext "Process activity")</a>
257 <a class="button" href="$SCRIPT_NAME?report">
258 <img src="$IMAGES/text.png" />$(gettext "Create a report")</a>
259 </div>
261 <h3>$(gettext "Summary")</h3>
262 <div id="summary">
263 <pre>
264 $(gettext "Uptime :")$(uptime)
265 $(gettext "Memory in Mb :") $(free -m | grep Mem: | awk \
266 '{print "Total:", $2, "Used:", $3, "Free:", $4}')
267 $(gettext "Linux kernel :") $(uname -r)
268 </pre>
269 <!-- Close summary -->
270 </div>
272 <h4>$(gettext "Network status")</h4>
273 $(list_network_interfaces)
275 <h4>$(gettext "Filesystem usage statistics")</h4>
276 EOT
277 # Disk stats (management is done as hardware.cgi)
278 table_start
279 df_thead
280 df -h | grep ^/dev | while read fs size used av pct mp
281 do
282 cat << EOT
283 <tr>
284 <td><a href="hardware.cgi">
285 <img src="$IMAGES/harddisk.png" />$fs</a></td>
286 <td>$size</td>
287 <td>$av</td>
288 <td class="pct"><div class="pct"
289 style="width: $pct;">$used - $pct</div></td>
290 <td>$mp</td>
291 </tr>
292 EOT
293 done
294 table_end
295 cat << EOT
296 <h3>$(gettext "Panel Activity")</h3>
297 <pre id="panel-activity">
298 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
299 </pre>
301 EOT
302 ;;
303 esac
305 xhtml_footer
306 exit 0