tazpanel view index.cgi @ rev 551

index.cgi: add ionice support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Nov 15 14:03:03 2015 +0100 (2015-11-15)
parents 9f014dbbbcf8
children 14374547435a
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-2015 SliTaz GNU/Linux - BSD License
8 #
11 # Common functions from libtazpanel
13 . lib/libtazpanel
14 get_config
16 TITLE='TazPanel'
20 # Check whether a configuration file has been modified after installation
22 file_is_modified() {
23 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
25 # Found, but can we do diff?
26 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
27 orig=$(dirname $file)/volatile.cpio.gz
28 zcat $orig 2>/dev/null | cpio -t 2>/dev/null | grep -q "^${1#/}$" || break
30 case "$2" in
31 diff)
32 tmp=$(mktemp -d)
33 ( cd $tmp; zcat $orig | cpio -id ${1#/} )
34 diff -abu $tmp$1 $1 | sed "s|$tmp||"
35 rm -rf $tmp;;
36 button)
37 echo -n '<button name="action" value="diff" data-icon="diff">'$(_ 'Differences')'</button>';;
38 esac
39 break
40 done
41 }
44 # OK status in table
46 ok_status_t() {
47 echo '<td><span class="diff-add" data-img="ok"></span></td></tr>'
48 }
52 # Terminal prompt
54 term_prompt() {
55 if [ "$user" == 'root' ]; then
56 local color1='color31' sign='#'
57 else
58 local color1='color32' sign='$'
59 fi
60 echo -n "<span class='$color1'>$user@$(hostname)</span>:<span class='color33'>"
61 pwd | sed "s|^$HOME|~|" | tr -d '\n'; echo -n "</span>$sign "
62 }
66 #
67 # Commands
68 #
70 case " $(GET) " in
73 *\ exec\ *)
74 # Execute command and display its result in a terminal-like window
76 header; xhtml_header "$(_ 'exec')"
78 exec="$(GET exec)"
79 font="${TERM_FONT:-monospace}"
80 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
82 cat <<EOT
83 <section>
84 <header>
85 $exec
86 $(back_button "$(GET back)" "$(GET back_caption)" "$(GET back_icon)")
87 </header>
88 <div class="term_">
89 <pre class="term $palette" style="font-family: '$font'">$($exec 2>&1 | htmlize | filter_taztools_msgs)</pre>
90 </div>
91 </section>
92 EOT
93 ;;
96 *\ file\ *)
97 #
98 # Handle files
99 #
100 header
101 file="$(GET file)"
102 action="$(POST action)"; [ -z "$action" ] && action="$(GET action)" # receive 'action' both on POST or GET
103 title="$(POST title)"; [ -z "$title" ] && title="$(GET title)" # (optional)
105 case $file in
106 *.html)
107 cat $file; exit 0 ;;
108 *)
109 xhtml_header "$(_ 'File')";;
110 esac
112 case "$action" in
113 edit)
114 cat <<EOT
115 <section>
116 <header>
117 <span data-icon="edit">${title:-$file}</span>
118 <form id="editform" method="post" action="?file=$file">
119 <button data-icon="save">$(_ 'Save')</button>
120 <button name="action" value="diff" data-icon="diff">$(_ 'Differences')</button>
121 </form>
122 $(back_button)
123 </header>
124 <textarea form="editform" name="content" class="wide" rows="30" autofocus>$(htmlize < $file)</textarea>
125 </section>
126 EOT
127 #The space before textarea gets muddled when the form is submitted.
128 #It prevents anything else from getting messed up
129 ;;
131 setvar)
132 data="$(. $(GET file) ;eval echo \$$(GET var))"
133 cat <<EOT
134 <section>
135 <header>$(GET var)</header>
136 <form method="post" action="?file=$file" class="nogap">
137 <input type="hidden" name="var" value="$(GET var)">
138 <input type="text" name="content" value="${data:-$(GET default)}">
139 <button type="submit" data-icon="save">$(_ 'Save')</button>
140 </form>
141 </section>
142 EOT
143 ;;
145 diff)
146 cat <<EOT
147 <section>
148 $(back_button)
149 <pre id="diff">$(file_is_modified $file diff | syntax_highlighter diff)</pre>
150 </section>
151 EOT
152 ;;
154 *)
155 R=$(echo -en '\r')
156 if [ -n "$(POST content)" ]; then
157 if [ -n "$(POST var)" ]; then
158 sed -i "s|^\\($(POST var)=\\).*|\1\"$(POST content)\"|" $file
159 else
160 sed "s/$R /\n/g;s/$R%0//g" > $file <<EOT
161 $(POST content)
162 EOT
163 fi
164 fi
166 cat <<EOT
167 <section class="bigNoScrollable">
168 <header>
169 <span data-icon="text">${title:-$file}</span>
170 EOT
171 if [ -w "$file" ]; then
172 cat <<EOT
173 <form>
174 <input type="hidden" name="file" value="$file"/>
175 <button onclick='editFile(); return false' id="edit_button"
176 data-icon="edit">$(_ 'Edit')</button><!--
177 --><button onclick='saveFile("$file", "$title"); return false' id="save_button"
178 data-icon="save" style="display:none">$(_ 'Save')</button><!--
179 -->$(file_is_modified $file button)
180 </form>
181 EOT
182 elif [ -r "$file" ]; then
183 cat <<EOT
184 <form>
185 <input type="hidden" name="file" value="$file"/>
186 $(file_is_modified $file button)
187 </form>
188 EOT
189 fi
190 cat <<EOT
191 </header>
193 <div>
194 <pre id="fileContent" class="bigScrollable">
195 EOT
196 end_code=''
197 # Handle file type by extension as a Web Server does it.
198 case "$file" in
199 *.sh|*.cgi|*/receipt|*.conf)
200 echo '<code class="language-bash">'; end_code='</code>'
201 htmlize ;;
202 *.ini)
203 echo '<code class="language-ini">'; end_code='</code>'
204 htmlize ;;
205 *.conf|*.lst)
206 syntax_highlighter conf ;;
207 *Xorg.0.log)
208 syntax_highlighter xlog ;;
209 *dmesg.log)
210 syntax_highlighter kernel ;;
211 *)
212 htmlize ;;
213 esac < $file
214 cat <<EOT
215 $end_code</pre>
216 </div>
217 </section>
218 EOT
219 esac
220 ;;
224 *\ terminal\ *|*\ cmd\ *)
225 # Cmdline terminal
227 header; xhtml_header "$(_ 'Terminal')"
229 user="$REMOTE_USER"
230 HOME="$(getdb passwd | awk -F: -vu=$user '$1==u{print $6}')"
231 historyfile="$HOME/.ash_history"
233 cmd=$(GET cmd)
234 path="$(GET path)"; path="${path:-/tmp}"; cd "$path"
236 font="${TERM_FONT:-monospace}"
237 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
239 [ -n "$cmd" -a "$cmd" != "$(tail -n1 $historyfile)" ] && echo "$cmd" >> $historyfile
242 # Terminal history
244 if [ "$cmd" == 'history' ]; then
245 cat <<EOT
246 <section>
247 <header>
248 $(_ 'History')
249 <form><button name="terminal" data-icon="terminal">$(_ 'Back')</button></form>
250 </header>
251 <form>
252 <input type="hidden" name="path" value="$path"/>
253 <pre class="term $palette" style="font-family: '$font'">
254 EOT
256 htmlize < $historyfile | awk -vrun="$(_ 'run')" -vpath="$path" -vq="'" '
257 BEGIN { num = 1; }
258 {
259 printf("%3d ", num);
260 cmd = $0;
261 gsub("%", "%25", cmd); gsub("+", "%2B", cmd); gsub(" ", "+", cmd);
262 gsub("\"", "%22", cmd); gsub("!", "%21", cmd); gsub(q, "%27", cmd);
263 printf("<a data-icon=\"run\" href=\"?cmd=%s&path=%s\">%s</a> ", cmd, path, run);
264 printf("<input type=\"checkbox\" name=\"rm\" value=\"%d\" id=\"hist%d\">", num, num);
265 printf("<label for=\"hist%d\">%s</label>\n", num, $0);
266 num++;
267 }'
269 cat <<EOT
270 </pre>
271 <footer>
272 <button name="rmhistory" data-icon="remove">$(_ 'Clear')</button>
273 </footer>
274 </form>
275 </section>
276 EOT
277 xhtml_footer
278 exit 0
279 fi
282 # Terminal window
284 cat <<EOT
285 <span id="num_hist"></span>
286 <section>
287 <pre class="term $palette" style="font-family: '$font'" onclick="document.getElementById('typeField').focus()">
288 EOT
289 if [ -n "$cmd" ]; then
290 term_prompt
291 echo "$cmd" | htmlize
292 fi
294 case "$cmd" in
295 usage|help)
296 _ 'Small non-interactive terminal emulator.'; echo
297 _ 'Run any command at your own risk, avoid interactive commands (%s)' 'nano, mc, ...'; echo
298 ;;
299 wget*)
300 dl='/var/cache/downloads'
301 [ ! -d "$dl" ] && mkdir -p $dl
302 _ 'Downloading to: %s' $dl; echo
303 cd $dl; $cmd 2>&1 ;;
304 cd|cd\ *)
305 path="${cmd#cd}"; path="${path:-$HOME}";
306 path="$(realpath $path)"; cd "$path" ;;
307 ls|ls\ *)
308 $cmd -w80 --color=always 2>&1 | filter_taztools_msgs ;;
309 cat)
310 # Cmd must be used with an arg.
311 _ '%s needs an argument' "$cmd" ;;
312 mc|nano|su)
313 # List of restricted (interactive) commands
314 _ "Please, don't run interactive command \"%s\"" "$cmd"; echo; echo ;;
315 *)
316 unset HTTP_REFERER # for fooling /lib/libtaz.sh formatting utils (<hr> in the terminal is so-so)
317 export DISPLAY=:0.0 # for run X applications
318 /bin/sh -c "$cmd" 2>&1 | htmlize | filter_taztools_msgs
319 ;;
320 esac
322 cat <<EOT
323 <form id="term">
324 <div class="cmdline" id="cmdline"><span id="prompt">$(term_prompt)</span><span id="typeField"> </span></div>
325 <input type="hidden" name="path" value="$(pwd)"/>
326 <input type="hidden" name="cmd" id="cmd"/>
327 </form>
328 </pre>
329 </section>
331 <form>
332 <button name="termsettings" data-icon="settings">$(_ 'Settings')</button>
333 <button name="cmd" value="history" data-icon="history">$(_ 'History')</button>
334 </form>
336 <script type="text/javascript">
337 with (document.getElementById('typeField')) {
338 contentEditable=true;
339 focus();
340 }
341 document.onkeydown=keydownHandler;
342 EOT
344 # Export history as array.
345 # Escape "all \"quotes\" in quotes", and all '\'
346 # (because \u, \x, \c has special meaning and can produce syntax error and stop js)
347 sed 's|\\|\\\\|g; s|"|\\"|g' $historyfile | awk '
348 BEGIN{ i=1; printf("ash_history=[") }
349 { printf("\"%s\",", $0); i++ }
350 END{
351 printf("\"\"];")
352 i--; printf("cur_hist=\"%d\";max_hist=\"%d\";", i, i)
353 }'
354 cat <<EOT
355 </script>
356 EOT
357 ;;
360 *\ rmhistory\ *)
361 # Manage shell commandline history
362 user="$REMOTE_USER"
363 HOME="$(getdb passwd | awk -F: -vu="$user" '$1==u{print $6}')"
364 historyfile="$HOME/.ash_history"
366 # Return sed command for removing history lines ('8d12d' to remove 8 and 12 lines)
367 rms=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="rm")printf "%dd", $2}')
369 if [ -n "$rms" ]; then
370 # Actually remove lines
371 sed -i $rms $historyfile
372 # Redirects back to the history table
373 header "HTTP/1.1 301 Moved Permanently" "Location: ?terminal&cmd=history&path=$(GET path)"
374 exit 0
375 fi
376 ;;
379 *\ termsettings\ *)
380 # Terminal settings
381 header; xhtml_header "$(_ 'Terminal')"
382 user="$REMOTE_USER"
383 font="$(GET font)"; font="${font:-$TERM_FONT}"
384 palette="$(GET palette)"; palette="${palette:-$TERM_PALETTE}"
385 pal=$(echo $palette | tr A-Z a-z)
387 # Add or change settings in TazPanel config
388 if [ -z "$TERM_FONT" ]; then
389 echo -e "\n# Terminal font family\nTERM_FONT=\"$font\"" >> $CONFIG
390 else
391 sed -i "s|TERM_FONT=.*|TERM_FONT=\"$font\"|" $CONFIG
392 fi
393 if [ -z "$TERM_PALETTE" ]; then
394 echo -e "\n# Terminal color palette\nTERM_PALETTE=\"$palette\"" >> $CONFIG
395 else
396 sed -i "s|TERM_PALETTE=.*|TERM_PALETTE=\"$palette\"|" $CONFIG
397 fi
399 cat <<EOT
400 <section style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0.5rem;">
401 <header>
402 $(_ 'Terminal settings')
403 <form>
404 <button name="terminal" data-icon="terminal">$(_ 'Terminal')</button>
405 </form>
406 </header>
407 <pre class="term $pal" style="height: auto; font-family: '$font'">
408 <span class='color31'>$user@$(hostname)</span>:<span class='color33'>~</span># palette
410 $(
411 for i in $(seq 30 37); do
412 for b in 0 1; do
413 for j in $(seq 40 47); do
414 echo -n "<span class=\"color$b color$i color$j\">$i:$j</span>"
415 done
416 done
417 echo
418 done
419 )
420 </pre>
421 <footer>
422 <form class="wide">
423 $(_ 'Font:')
424 <select name="font">
425 <option value="">$(_ 'Default')</option>
426 $(fc-list :spacing=mono:lang=en family | sed '/\.pcf/d;/,/d;s|\\-|-|g' | sort -u | \
427 awk -vfont="$font" '{
428 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == font)?" selected":"", $0)
429 }')
430 </select>
431 $(_ 'Palette:')
432 <select name="palette">
433 $(echo -e 'Tango\nLinux\nXterm\nRxvt\nEcho' | awk -vpal="$palette" '{
434 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == pal)?" selected":"", $0)
435 }')
436 </select>
437 <button name="termsettings" data-icon="ok">$(_ 'Apply')</button>
438 </form>
439 </footer>
440 </section>
441 EOT
443 ;;
446 *\ top\ *)
447 header; xhtml_header "$(_ 'Process activity')"
449 r=$(GET refresh)
450 cat <<EOT
451 <form>
452 <p>$(_ 'Refresh:')
453 <input type="hidden" name="top"/>
454 <input type="radio" name="refresh" value="1" id="r1" $([ "$r" == 1 ] && echo checked) onchange="this.form.submit()"/>
455 <label for="r1">$(_ '1s' )</label>
456 <input type="radio" name="refresh" value="5" id="r2" $([ "$r" == 5 ] && echo checked) onchange="this.form.submit()"/>
457 <label for="r2">$(_ '5s' )</label>
458 <input type="radio" name="refresh" value="10" id="r3" $([ "$r" == 10 ] && echo checked) onchange="this.form.submit()"/>
459 <label for="r3">$(_ '10s' )</label>
460 <input type="radio" name="refresh" value="" id="r4" $([ -z "$r" ] && echo checked) onchange="this.form.submit()"/>
461 <label for="r4">$(_ 'none')</label>
462 </p>
463 </form>
464 EOT
465 [ -n "$r" ] && echo "<meta http-equiv=\"refresh\" content=\"$r\">"
467 [ "$(GET renice)" ] && renice $(GET renice)
468 [ "$(GET ionice)" ] && ionice $(GET ionice)
469 [ "$(GET kill)" ] && kill $(GET kill)
470 if [ "$(GET pid)" ] && [ -d /proc/$(GET pid)/ ]; then
471 curpid=$(GET pid)
472 curnice=$(awk '{ print int($19) }' /proc/$curpid/stat)
473 bootttime=$(awk '{print int($22/100)}' /proc/$curpid/stat)
474 uptime=$(awk '{print int($1)}' /proc/uptime)
475 now=$(date +%s)
476 starttime=$(date -d @$(($now - ($uptime - $bootttime))))
477 cat <<EOT
478 <section>
479 <header>
480 $(ps auxww | sed "/^ *$curpid /!d")
481 <form>
482 <input type="hidden" name="top"/>
483 <button type="submit" data-icon="remove" name="kill" value="$curpid">$(_ 'Kill')</button>
484 </form>
485 </header>
486 <form>
487 <p>$(_ 'Start time:')
488 $starttime
489 </p>
490 <p>$(_ 'Renice')
491 <input type="hidden" name="top"/>
492 <select name "renice" onchange="this.form.submit()">
493 EOT
494 values="$(seq 20 -1 -20)"
495 [ $(id -u) -eq 0 ] || values="$(seq 20 -1 0)"
496 for i in $values ; do
497 cat <<EOT
498 <option value="$i $curpid" $([ $curnice -eq $i ] && echo selected)>$(printf "%+d" $i)</option>
499 EOT
500 done
501 cat <<EOT
502 </select>
503 $(_ 'I/O class')
504 <select name="ionice" onchange="this.form.submit()">
505 EOT
506 while read class name max; do
507 if [ "$max" ]; then
508 [ $(id -u) -ne 0 ] && continue
509 for i in $(seq 0 $max); do
510 selected="selected"
511 [ "$(ionice $curpid)" = "$name: prio $i" ] || selected=""
512 echo " <option value=\"-c $class -n $i -p $curpid\" $selected>$name: prio $i</option>"
513 done
514 else
515 selected="selected"
516 [ "$(ionice $curpid)" = "$name" ] || selected=""
517 echo " <option value=\"-c $class -p $curpid\" $selected>$name</option>"
518 fi
519 done <<EOT
520 0 none
521 1 realtime 7
522 2 best-effort 7
523 3 idle
524 EOT
525 cat <<EOT
526 </select>
527 </p>
528 </form>
529 </section>
530 EOT
531 fi
532 echo '<section><div><pre class="term log">'
533 busybox top -n1 -b | htmlize | sed \
534 -e 's|^\( *\)\([0-9][0-9]*\)|\1<a href="?top\&amp;pid=\2">\2</a>|' \
535 -e 's|^[A-Z].*:|<span class="color1 color31">\0</span>|g' \
536 -e 's|^\ *PID|<span class="color1 color32">\0</span>|g'
537 echo '</pre></div></section>' ;;
540 *\ debug\ *)
541 header; xhtml_header "$(_ 'Debug')"
543 cat <<EOT
544 <h2>$(_ 'HTTP Environment')</h2>
546 <section>
547 <div>
548 <pre>$(httpinfo | syntax_highlighter conf)</pre>
549 </div>
550 </section>
551 EOT
552 ;;
555 *\ report\ *)
556 header; xhtml_header "$(_ 'System report')"
558 [ -d '/var/cache/slitaz' ] || mkdir -p /var/cache/slitaz
559 output='/var/cache/slitaz/sys-report.html'
561 cat <<EOT
562 <section>
563 <header>$(_ 'Reporting to: %s' "$output")</header>
564 <table class="wide zebra">
565 <tbody>
566 <tr><td>$(_ 'Creating report header...')</td>
567 EOT
568 cat > $output <<EOT
569 <!DOCTYPE html>
570 <html xmlns="http://www.w3.org/1999/xhtml">
571 <head>
572 <meta charset="utf-8"/>
573 <title>$(_ 'SliTaz system report')</title>
574 <style type="text/css">
575 body { padding: 20px 60px; font-size: 13px; }
576 h1, h2 { color: #444; }
577 pre { background: #f1f1f1; border: 1px solid #ddd;
578 padding: 10px; border-radius: 4px; }
579 span.diff-rm { color: red; }
580 span.diff-add { color: green; }
581 </style>
582 </head>
583 <body>
584 EOT
585 cat <<EOT
586 $(ok_status_t)
587 <tr><td>$(_ 'Creating system summary...')</td>
588 EOT
589 cat >> $output <<EOT
590 <h1>$(_ 'SliTaz system report')</h1>
591 $(_ 'Date:') $(date)
592 <pre>
593 uptime : $(uptime)
594 cmdline : $(cat /proc/cmdline)
595 version : $(cat /etc/slitaz-release)
596 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
597 kernel : $(uname -r)
598 </pre>
599 EOT
600 cat <<EOT
601 $(ok_status_t)
602 <tr><td>$(_ 'Getting hardware info...')</td>
603 EOT
604 cat >> $output <<EOT
605 <h2>free</h2>
606 <pre>$(free)</pre>
608 <h2>lspci -k</h2>
609 <pre>$(lspci -k)</pre>
611 <h2>lsusb</h2>
612 <pre>$(lsusb)</pre>
614 <h2>lsmod</h2>
615 <pre>$(lsmod)</pre>
617 EOT
618 cat <<EOT
619 $(ok_status_t)
620 <tr><td>$(_ 'Getting networking info...')</td>
621 EOT
622 cat >> $output <<EOT
623 <h2>ifconfig -a</h2>
624 <pre>$(ifconfig -a)</pre>
626 <h2>route -n</h2>
627 <pre>$(route -n)</pre>
629 <h2>/etc/resolv.conf</h2>
630 <pre>$(cat /etc/resolv.conf)</pre>
631 EOT
632 cat <<EOT
633 $(ok_status_t)
634 <tr><td>$(_ 'Getting filesystems info...')</td>
635 EOT
636 cat >> $output <<EOT
637 <h2>blkid</h2>
638 <pre>$(blkid)</pre>
640 <h2>fdisk -l</h2>
641 <pre>$(fdisk -l)</pre>
643 <h2>mount</h2>
644 <pre>$(mount)</pre>
646 <h2>df -h</h2>
647 <pre>$(df -h)</pre>
649 <h2>df -i</h2>
650 <pre>$(df -i)</pre>
651 EOT
652 cat <<EOT
653 $(ok_status_t)
654 <tr><td>$(_ 'Getting boot logs...')</td>
655 EOT
656 cat >> $output <<EOT
657 <h2>$(_ 'Kernel messages')</h2>
658 <pre>$(cat /var/log/dmesg.log)</pre>
660 <h2>$(_ 'Boot scripts')</h2>
661 <pre>$(filter_taztools_msgs < /var/log/boot.log)</pre>
662 EOT
663 cat <<EOT
664 $(ok_status_t)
665 <tr><td>$(_ 'Getting package list...')</td>
666 EOT
667 cat >> $output <<EOT
668 <h2>$(_ 'Packages')</h2>
669 EOT
670 ( cd /var/lib/tazpkg/installed
671 for i in * ; do
672 echo "$i $(. $i/receipt ; echo "$VERSION $DEPENDS" | xargs echo ;
673 echo "$PROVIDE" | sed 's/:[^ ]*//g' | xargs echo PROVIDE)"
674 done ) | awk '{
675 if ($1 == "PROVIDE") {
676 for (i = 2; i <= NF; i++) alias[$i] = 1
677 }
678 else { pkg[$1]=$0; idx[c++]=$1 }
679 }
680 function name(n)
681 {
682 split(pkg[n], x, " ")
683 return x[1] " (" x[2] ") "
684 }
685 END {
686 print "<pre>"
687 for (i in pkg) for (j = split(pkg[i], p, " "); j > 2; j--) {
688 if (pkg[p[j]] || alias[p[j]]) kill[p[j]]=1
689 else { miss=1 ; print "Missing dep " p[j] " for " name(p[1]) }
690 }
691 if (miss) print ""
692 n=0
693 for (i=0; i < c; i++) {
694 if (kill[idx[i]]) continue
695 printf "%s" name(idx[i])
696 if (n++ < 2) continue
697 printf "\n"
698 n=0
699 }
700 print "</pre>"
701 }
702 ' >> $output
703 if [ "$(ls report.d/* 2> /dev/null)" ]; then
704 cat <<EOT
705 $(ok_status_t)
706 <tr><td>$(_ 'Getting extra reports...')</td>
707 EOT
708 for i in report.d/* ; do
709 sh $i $i >> $output
710 done
711 fi
712 cat <<EOT
713 $(ok_status_t)
714 <tr><td>$(_ 'Creating report footer...')</td>
715 EOT
716 cat >> $output <<EOT
717 </body>
718 </html>
719 EOT
720 cat <<EOT
721 $(ok_status_t)
722 </tbody>
723 </table>
724 <footer>
725 <form><button name="file" value="$output" data-icon="view">$(_ 'View')</button></form>
726 </footer>
727 </section>
730 $(msg tip "$(_ 'This report can be attached with a bug report on:')
731 <a href="http://bugs.slitaz.org/" target="_blank">bugs.slitaz.org</a></p>")
732 EOT
733 ;;
736 *)
737 #
738 # Default xHTML content
739 #
740 header; xhtml_header "$(_ 'SliTaz administration and configuration Panel')"
741 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
742 [ -n "$(GET rdate)" ] && echo ""
743 hostname=$(hostname)
745 cat <<EOT
746 <form class="nogap"><!--
747 --><button name="terminal" data-icon="terminal">$(_ 'Terminal')</button><!--
748 --><button name="top" data-icon="proc" >$(_ 'Process activity')</button><!--
749 --><button name="report" data-icon="report" data-root>$(_ 'Create a report')</button><!--
750 --></form>
752 <section>
753 <header>$(_ 'Summary')</header>
754 <table>
755 <tr><td>$(_ 'Host:')</td><td>$hostname</td></tr>
756 <tr><td>$(_ 'Uptime:')</td>
757 <td id="uptime">$(uptime | sed 's|\([0-9.:][0-9.:]*\)|<b>\1</b>|g')</td>
758 </tr>
759 <tr><td>$(_ 'Memory in Mb:')</td>
760 <td>$(free -m | grep Mem: | \
761 awk -vline="$(gettext 'Total: %d, Used: %d, Free: %d')" \
762 '{ printf(line, $2, $3, $4) }' | \
763 sed 's|\([0-9][0-9]*\)|<b>\1</b>|g')</td>
764 </tr>
765 <tr><td>$(_ 'Linux kernel:')</td>
766 <td>$(uname -r)</td>
767 </tr>
768 </table>
769 </section>
772 <section>
773 <header>
774 $(_ 'Network status')
775 <form action="network.cgi">
776 <button data-icon="wifi">$(_ 'Network')</button>
777 </form>
778 </header>
779 $(list_network_interfaces)
780 </section>
783 <section>
784 <header>
785 $(_ 'Filesystem usage statistics')
786 <form action="hardware.cgi">
787 <button data-icon="hdd">$(_ 'Disks')</button>
788 </form>
789 </header>
790 <table class="wide zebra center">
791 EOT
792 # Disk stats (management is done as hardware.cgi)
793 df_thead
794 echo '<tbody>'
795 df -h | grep ^/dev | while read fs size used av pct mp; do
796 cat <<EOT
797 <tr>
798 <td><span data-icon="hdd">${fs#/dev/}</span></td>
799 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
800 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
801 <td>$size</td>
802 <td>$av</td>
803 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
804 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
805 <span>$used - $pct</span>
806 </td>
807 <td>$mp</td>
808 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
809 </tr>
810 EOT
811 done
812 cat <<EOT
813 </tbody>
814 </table>
815 </section>
817 <section>
818 <header>
819 $(_ 'Panel Activity')
820 <form>
821 <button name="file" value="$LOG_FILE" data-icon="view">$(_ 'View')</button>
822 </form>
823 </header>
824 <div>
825 <pre id="panel-activity">
826 $(tail -n 8 < $LOG_FILE | sort -r | syntax_highlighter activity)</pre>
827 </div>
828 </section>
829 EOT
830 ;;
831 esac
833 xhtml_footer
834 exit 0