tazpanel view index.cgi @ rev 352

Added tag 1.6.3 for changeset 54ae5c462742
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 22 08:47:27 2013 +0100 (2013-03-22)
parents b33228b5874d
children 4a8f56bb08cb
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-2012 SliTaz GNU/Linux - BSD License
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 TITLE="TazPanel"
17 # Check whether a configuration file has been modified after installation
18 file_is_modified()
19 {
20 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
22 # Found, but can we do diff ?
23 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
24 org=$(dirname $file)/volatile.cpio.gz
25 zcat $org 2>/dev/null | cpio -t 2>/dev/null | \
26 grep -q "^${1#/}$" || break
28 case "$2" in
29 diff)
30 tmp=/tmp/tazpanel$$
31 mkdir -p $tmp
32 ( cd $tmp ; zcat $org | cpio -id ${1#/} )
33 diff -u $tmp$1 $1 | sed "s|$tmp||"
34 rm -rf $tmp ;;
35 button)
36 cat <<EOT
37 <a class="button" href='$SCRIPT_NAME?file=$1&action=diff'>
38 <img src="$IMAGES/help.png" />$(gettext 'Differences')</a>
39 EOT
40 esac
41 break
42 done
43 }
46 # OK status in table
47 ok_status_t() {
48 echo " <td>[<span class='diff-add'> OK </span>]</td></tr>"
49 }
52 #
53 # Things to do before displaying the page
54 #
56 [ -n "$(GET panel_pass)" ] &&
57 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
59 #
60 # Commands
61 #
63 case " $(GET) " in
64 *\ file\ *)
65 #
66 # Handle files
67 #
68 file="$(GET file)"
69 case $file in
70 *.html)
71 cat $file && exit 0 ;;
72 *)
73 TITLE=$(gettext 'TazPanel - File')
74 xhtml_header
75 echo "<h2>$file</h2>" ;;
76 esac
78 if [ "$(GET action)" == "edit" ]; then
79 cat <<EOT
80 <form method="post" action="$SCRIPT_NAME?file=$file">
81 <img src="$IMAGES/edit.png" />
82 <input type="submit" value="$(gettext 'Save')">
83 <a class="button" href='$SCRIPT_NAME?file=$file&action=diff'>
84 <img src="$IMAGES/help.png" />$(gettext 'Differences')</a>
85 <textarea name="content" rows="30" style="width: 100%;">
86 $(cat $file | htmlize)
87 </textarea>
88 </form>
89 EOT
90 #The space before textarea gets muddled when the form is submitted.
91 #It prevents anything else from getting messed up
92 elif [ "$(GET action)" == "diff" ]; then
93 echo '<pre id="diff">'
94 file_is_modified $file diff | syntax_highlighter diff
95 echo '</pre>'
96 else
97 R=$(echo -en '\r')
98 [ -n "$(POST content)" ] &&
99 sed "s/$R /\n/g;s/$R%0//g" > $file <<EOT
100 $(POST content)
101 EOT
102 cat <<EOT
103 <div id="actions">
104 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
105 <img src="$IMAGES/edit.png" />$(gettext 'Edit')</a>
106 EOT
107 file_is_modified $file button
108 cat << EOT
109 </div>
110 <pre>
111 EOT
112 # Handle file type by extension as a Web Server does it.
113 case "$file" in
114 *.conf|*.lst)
115 syntax_highlighter conf ;;
116 *.sh|*.cgi)
117 syntax_highlighter sh ;;
118 *)
119 cat | htmlize ;;
120 esac < $file
121 echo '</pre>'
122 fi ;;
125 *\ terminal\ *|*\ cmd\ *)
126 # Cmdline terminal.
127 commands='cat du help ls ping pwd who wget'
128 cmd=$(GET cmd)
129 TITLE=$(gettext 'TazPanel - Terminal')
130 xhtml_header
131 cat << EOT
132 <section>
133 <form method="get" action="$SCRIPT_NAME">
134 <div class="box">
135 root@$(hostname):~# <input autofocus type="text" name="cmd" style="width: 80%;" />
136 </div>
137 </form>
138 EOT
139 echo '<pre id="terminal">'
140 # Allow only a few commands for the moment.
141 case "$cmd" in
142 usage|help)
143 gettext 'Small terminal emulator, commands options are supported.'
144 echo ""
145 eval_gettext 'Commands: $commands'
146 echo ;;
147 wget*)
148 dl=/var/cache/downloads
149 [ ! -d "$dl" ] && mkdir -p $dl
150 eval_gettext 'Downloading to: $dl' && echo
151 cd $dl && $cmd ;;
152 du*|ls*|ping*|pwd|who)
153 $cmd ;;
154 cat*)
155 # Cmd must be used with an arg.
156 arg=$(echo $cmd | awk '{print $2}')
157 [ "$arg" == "" ] && eval_gettext '$cmd needs an argument' && break
158 $cmd ;;
159 *)
160 [ "$cmd" == "" ] || \
161 eval_gettext 'Unknown command: $cmd' && echo
162 eval_gettext 'Commands: $commands' ;;
163 esac
164 echo '</pre></section>'
165 ;;
168 *\ top\ *)
169 TITLE=$(gettext 'TazPanel - Process activity')
170 xhtml_header
171 echo $(gettext 'Refresh:') $(GET refresh)
172 cat << EOT
173 <br/>
174 <form method="get">
175 <input type="hidden" name="top"/>
176 <input type="submit" name="refresh" value="$(gettext '1s')"/>
177 <input type="submit" name="refresh" value="$(gettext '5s')"/>
178 <input type="submit" name="refresh" value="$(gettext '10s')"/>
179 <input type="submit" value="$(gettext 'none')"/>
180 </form>
181 EOT
182 if [ -n "$(GET refresh)" ]; then
183 echo -n '<meta http-equiv="refresh" content="'
184 echo -n "$(GET refresh)" | sed 's|\([^0-9]*\)\([0-9]\+\).*|\2|'
185 echo '">'
186 fi
188 echo '<pre>'
189 top -n1 -b | htmlize | sed \
190 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
191 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
192 echo '</pre>' ;;
195 *\ debug\ *)
196 TITLE=$(gettext 'TazPanel - Debug')
197 xhtml_header
198 cat << EOT
199 <h2>$(gettext 'HTTP Environment')</h2>
201 <pre>$(httpinfo)</pre>
202 EOT
203 ;;
206 *\ report\ *)
207 TITLE=$(gettext 'TazPanel - System report')
208 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
209 output=/var/cache/slitaz/sys-report.html
210 xhtml_header
211 cat << EOT
212 <h2>$(eval_gettext 'Reporting to: $output')</h2>
213 <table class="zebra outbox">
214 <tbody>
215 <tr><td>$(gettext 'Creating report header...')</td>
216 EOT
217 cat > $output << EOT
218 <!DOCTYPE html>
219 <html xmlns="http://www.w3.org/1999/xhtml">
220 <head>
221 <meta charset="utf-8" />
222 <title>$(gettext 'SliTaz system report')</title>
223 <style type="text/css">
224 body { padding: 20px 60px; font-size: 13px; }
225 h1, h2 { color: #444; }
226 pre { background: #f1f1f1; border: 1px solid #ddd;
227 padding: 10px; border-radius: 4px; }
228 span.diff-rm { color: red; }
229 span.diff-add { color: green; }
230 </style>
231 </head>
232 <body>
233 EOT
234 cat << EOT
235 $(ok_status_t)
236 <tr><td>$(gettext 'Creating system summary...')</td>
237 EOT
238 cat >> $output << EOT
239 <h1>$(gettext 'SliTaz system report')</h1>
240 $(gettext 'Date:') $(date)
241 <pre>
242 uptime : $(uptime)
243 cmdline : $(cat /proc/cmdline)
244 version : $(cat /etc/slitaz-release)
245 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
246 kernel : $(uname -r)
247 </pre>
248 EOT
249 cat << EOT
250 $(ok_status_t)
251 <tr><td>$(gettext 'Getting hardware info...')</td>
252 EOT
253 cat >> $output << EOT
254 <h2>free</h2>
255 <pre>$(free)</pre>
257 <h2>lspci -k</h2>
258 <pre>$(lspci -k)</pre>
260 <h2>lsusb</h2>
261 <pre>$(lsusb)</pre>
263 <h2>lsmod</h2>
264 <pre>$(lsmod)</pre>
266 EOT
267 cat << EOT
268 $(ok_status_t)
269 <tr><td>$(gettext 'Getting networking info...')</td>
270 EOT
271 cat >> $output << EOT
272 <h2>ifconfig -a</h2>
273 <pre>$(ifconfig -a)</pre>
275 <h2>route -n</h2>
276 <pre>$(route -n)</pre>
278 <h2>/etc/resolv.conf</h2>
279 <pre>$(cat /etc/resolv.conf)</pre>
280 EOT
281 cat << EOT
282 $(ok_status_t)
283 <tr><td>$(gettext 'Getting filesystems info...')</td>
284 EOT
285 cat >> $output << EOT
286 <h2>blkid</h2>
287 <pre>$(blkid)</pre>
289 <h2>fdisk -l</h2>
290 <pre>$(fdisk -l)</pre>
292 <h2>mount</h2>
293 <pre>$(mount)</pre>
295 <h2>df -h</h2>
296 <pre>$(df -h)</pre>
298 <h2>df -i</h2>
299 <pre>$(df -i)</pre>
300 EOT
301 cat << EOT
302 $(ok_status_t)
303 <tr><td>$(gettext 'Getting boot logs...')</td>
304 EOT
305 cat >> $output << EOT
306 <h2>$(gettext 'Kernel messages')</h2>
307 <pre>$(cat /var/log/dmesg.log)</pre>
309 <h2>$(gettext 'Boot scripts')</h2>
310 <pre>$(cat /var/log/boot.log | filter_taztools_msgs)</pre>
311 EOT
312 cat << EOT
313 $(ok_status_t)
314 <tr><td>$(gettext 'Creating report footer...')</td>
315 EOT
316 cat cat >> $output << EOT
317 </body>
318 </html>
319 EOT
320 cat << EOT
321 $(ok_status_t)
322 </tbody>
323 </table>
324 <p><a class="button" href="$SCRIPT_NAME?file=$output">
325 <img src="/styles/default/images/browser.png" />
326 $(gettext 'View report')</a>
327 $(msg tip "$(gettext 'This report can be attached with a bug report on:')
328 <a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>")
329 EOT
330 ;;
333 *)
334 #
335 # Default xHTML content
336 #
337 xhtml_header
338 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
339 [ -n "$(GET rdate)" ] && echo ""
340 hostname=$(hostname)
341 cat << EOT
342 <div id="wrapper">
343 <h2>$(eval_gettext 'Host: $hostname')</h2>
344 <p>$(gettext 'SliTaz administration and configuration Panel')<p>
345 </div>
346 <div id="actions">
347 <a class="button" href="$SCRIPT_NAME?terminal">
348 <img src="$IMAGES/terminal.png" />$(gettext 'Terminal')</a>
349 <a class="button" href="$SCRIPT_NAME?top">
350 <img src="$IMAGES/monitor.png" />$(gettext 'Process activity')</a>
351 <a class="button" href="$SCRIPT_NAME?report">
352 <img src="$IMAGES/text.png" />$(gettext 'Create a report')</a>
353 </div>
355 <section>
356 <h3>$(gettext 'Summary')</h3>
357 <div id="summary">
358 <table>
359 <tr><td>$(gettext 'Uptime:')</td>
360 <td>$(uptime)</td>
361 </tr>
362 <tr><td>$(gettext 'Memory in Mb:')</td>
363 EOT
364 free -m | grep Mem: | awk '{print $2, $3, $4}' | while read memtotal memused memfree
365 do
366 cat << EOT
367 <td>$(eval_gettext 'Total: $memtotal, Used: $memused, Free: $memfree')</td>
368 EOT
369 done
370 cat << EOT
371 </tr>
372 <tr><td>$(gettext 'Linux kernel:')</td>
373 <td>$(uname -r)</td>
374 </tr>
375 </table>
376 <!-- Close summary -->
377 </div>
378 </section>
380 <section>
381 <h4>$(gettext 'Network status')</h4>
382 $(list_network_interfaces)
383 </section>
385 <section>
386 <h4>$(gettext 'Filesystem usage statistics')</h4>
387 EOT
388 # Disk stats (management is done as hardware.cgi)
389 cat << EOT
390 <table class="zebra outbox">
391 EOT
392 df_thead
393 echo '<tbody>'
394 df -h | grep ^/dev | while read fs size used av pct mp
395 do
396 cat << EOT
397 <tr>
398 <td><a href="hardware.cgi">
399 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</a></td>
400 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
401 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
402 <td>$size</td>
403 <td>$av</td>
404 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
405 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
406 <span>$used - $pct</span>
407 </td>
408 <td>$mp</td>
409 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
410 </tr>
411 EOT
412 done
413 cat << EOT
414 </tbody>
415 </table>
416 </section>
418 <section>
419 <h3>$(gettext 'Panel Activity')</h3>
420 <pre id="panel-activity">
421 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
422 </pre>
423 </section>
424 EOT
425 ;;
426 esac
428 xhtml_footer
429 exit 0