tazpanel view index.cgi @ rev 547

index.cgi: add process start time
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Nov 11 19:20:07 2015 +0100 (2015-11-11)
parents c0f8e615df7d
children 71dcdeb589d1
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 kill)" ] && kill $(GET kill)
469 if [ "$(GET pid)" ] && [ -d /proc/$(GET pid)/ ]; then
470 curpid=$(GET pid)
471 curnice=$(awk '{ print $19 }' /proc/$curpid/stat)
472 cat <<EOT
473 <section>
474 <header>
475 $(ps auxww | sed "/^ *$curpid /!d")
476 <form>
477 <input type="hidden" name="top"/>
478 <button type="submit" data-icon="remove" name="kill" value="$curpid">$(_ 'Kill')</button>
479 </form>
480 </header>
481 <form>
482 <p>$(_ 'Start time')
483 $(stat -c %y /proc/$curpid)
484 </p>
485 <p>$(_ 'Renice')[$curnice]
486 <input type="hidden" name="top"/>
487 EOT
488 values="+19 +15 +10 +5 +3 +1 0 -1 -3 -5 -10 -15 -19"
489 [ $(id -u) -eq 0 ] || values="+19 +15 +10 +5 +3 +1"
490 for i in $values ; do
491 cat <<EOT
492 <input type="radio" name="renice" value="$i $curpid" $([ $curnice -eq $i ] && echo checked) onchange="this.form.submit()"/>
493 <label>$i</label>
494 EOT
495 done
496 cat <<EOT
497 </p>
498 </form>
499 </section>
500 EOT
501 fi
502 echo '<section><div><pre class="term log">'
503 busybox top -n1 -b | htmlize | sed \
504 -e 's|^\( *\)\([0-9][0-9]*\)|\1<a href="?top\&amp;pid=\2">\2</a>|' \
505 -e 's|^[A-Z].*:|<span class="color1 color31">\0</span>|g' \
506 -e 's|^\ *PID|<span class="color1 color32">\0</span>|g'
507 echo '</pre></div></section>' ;;
510 *\ debug\ *)
511 header; xhtml_header "$(_ 'Debug')"
513 cat <<EOT
514 <h2>$(_ 'HTTP Environment')</h2>
516 <section>
517 <div>
518 <pre>$(httpinfo | syntax_highlighter conf)</pre>
519 </div>
520 </section>
521 EOT
522 ;;
525 *\ report\ *)
526 header; xhtml_header "$(_ 'System report')"
528 [ -d '/var/cache/slitaz' ] || mkdir -p /var/cache/slitaz
529 output='/var/cache/slitaz/sys-report.html'
531 cat <<EOT
532 <section>
533 <header>$(_ 'Reporting to: %s' "$output")</header>
534 <table class="wide zebra">
535 <tbody>
536 <tr><td>$(_ 'Creating report header...')</td>
537 EOT
538 cat > $output <<EOT
539 <!DOCTYPE html>
540 <html xmlns="http://www.w3.org/1999/xhtml">
541 <head>
542 <meta charset="utf-8"/>
543 <title>$(_ 'SliTaz system report')</title>
544 <style type="text/css">
545 body { padding: 20px 60px; font-size: 13px; }
546 h1, h2 { color: #444; }
547 pre { background: #f1f1f1; border: 1px solid #ddd;
548 padding: 10px; border-radius: 4px; }
549 span.diff-rm { color: red; }
550 span.diff-add { color: green; }
551 </style>
552 </head>
553 <body>
554 EOT
555 cat <<EOT
556 $(ok_status_t)
557 <tr><td>$(_ 'Creating system summary...')</td>
558 EOT
559 cat >> $output <<EOT
560 <h1>$(_ 'SliTaz system report')</h1>
561 $(_ 'Date:') $(date)
562 <pre>
563 uptime : $(uptime)
564 cmdline : $(cat /proc/cmdline)
565 version : $(cat /etc/slitaz-release)
566 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
567 kernel : $(uname -r)
568 </pre>
569 EOT
570 cat <<EOT
571 $(ok_status_t)
572 <tr><td>$(_ 'Getting hardware info...')</td>
573 EOT
574 cat >> $output <<EOT
575 <h2>free</h2>
576 <pre>$(free)</pre>
578 <h2>lspci -k</h2>
579 <pre>$(lspci -k)</pre>
581 <h2>lsusb</h2>
582 <pre>$(lsusb)</pre>
584 <h2>lsmod</h2>
585 <pre>$(lsmod)</pre>
587 EOT
588 cat <<EOT
589 $(ok_status_t)
590 <tr><td>$(_ 'Getting networking info...')</td>
591 EOT
592 cat >> $output <<EOT
593 <h2>ifconfig -a</h2>
594 <pre>$(ifconfig -a)</pre>
596 <h2>route -n</h2>
597 <pre>$(route -n)</pre>
599 <h2>/etc/resolv.conf</h2>
600 <pre>$(cat /etc/resolv.conf)</pre>
601 EOT
602 cat <<EOT
603 $(ok_status_t)
604 <tr><td>$(_ 'Getting filesystems info...')</td>
605 EOT
606 cat >> $output <<EOT
607 <h2>blkid</h2>
608 <pre>$(blkid)</pre>
610 <h2>fdisk -l</h2>
611 <pre>$(fdisk -l)</pre>
613 <h2>mount</h2>
614 <pre>$(mount)</pre>
616 <h2>df -h</h2>
617 <pre>$(df -h)</pre>
619 <h2>df -i</h2>
620 <pre>$(df -i)</pre>
621 EOT
622 cat <<EOT
623 $(ok_status_t)
624 <tr><td>$(_ 'Getting boot logs...')</td>
625 EOT
626 cat >> $output <<EOT
627 <h2>$(_ 'Kernel messages')</h2>
628 <pre>$(cat /var/log/dmesg.log)</pre>
630 <h2>$(_ 'Boot scripts')</h2>
631 <pre>$(filter_taztools_msgs < /var/log/boot.log)</pre>
632 EOT
633 cat <<EOT
634 $(ok_status_t)
635 <tr><td>$(_ 'Getting package list...')</td>
636 EOT
637 cat >> $output <<EOT
638 <h2>$(_ 'Packages')</h2>
639 EOT
640 ( cd /var/lib/tazpkg/installed
641 for i in * ; do
642 echo "$i $(. $i/receipt ; echo "$VERSION $DEPENDS" | xargs echo ;
643 echo "$PROVIDE" | sed 's/:[^ ]*//g' | xargs echo PROVIDE)"
644 done ) | awk '{
645 if ($1 == "PROVIDE") {
646 for (i = 2; i <= NF; i++) alias[$i] = 1
647 }
648 else { pkg[$1]=$0; idx[c++]=$1 }
649 }
650 function name(n)
651 {
652 split(pkg[n], x, " ")
653 return x[1] " (" x[2] ") "
654 }
655 END {
656 print "<pre>"
657 for (i in pkg) for (j = split(pkg[i], p, " "); j > 2; j--) {
658 if (pkg[p[j]] || alias[p[j]]) kill[p[j]]=1
659 else { miss=1 ; print "Missing dep " p[j] " for " name(p[1]) }
660 }
661 if (miss) print ""
662 n=0
663 for (i=0; i < c; i++) {
664 if (kill[idx[i]]) continue
665 printf "%s" name(idx[i])
666 if (n++ < 2) continue
667 printf "\n"
668 n=0
669 }
670 print "</pre>"
671 }
672 ' >> $output
673 if [ "$(ls report.d/* 2> /dev/null)" ]; then
674 cat <<EOT
675 $(ok_status_t)
676 <tr><td>$(_ 'Getting extra reports...')</td>
677 EOT
678 for i in report.d/* ; do
679 sh $i $i >> $output
680 done
681 fi
682 cat <<EOT
683 $(ok_status_t)
684 <tr><td>$(_ 'Creating report footer...')</td>
685 EOT
686 cat >> $output <<EOT
687 </body>
688 </html>
689 EOT
690 cat <<EOT
691 $(ok_status_t)
692 </tbody>
693 </table>
694 <footer>
695 <form><button name="file" value="$output" data-icon="view">$(_ 'View')</button></form>
696 </footer>
697 </section>
700 $(msg tip "$(_ 'This report can be attached with a bug report on:')
701 <a href="http://bugs.slitaz.org/" target="_blank">bugs.slitaz.org</a></p>")
702 EOT
703 ;;
706 *)
707 #
708 # Default xHTML content
709 #
710 header; xhtml_header "$(_ 'SliTaz administration and configuration Panel')"
711 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
712 [ -n "$(GET rdate)" ] && echo ""
713 hostname=$(hostname)
715 cat <<EOT
716 <form class="nogap"><!--
717 --><button name="terminal" data-icon="terminal">$(_ 'Terminal')</button><!--
718 --><button name="top" data-icon="proc" >$(_ 'Process activity')</button><!--
719 --><button name="report" data-icon="report" data-root>$(_ 'Create a report')</button><!--
720 --></form>
722 <section>
723 <header>$(_ 'Summary')</header>
724 <table>
725 <tr><td>$(_ 'Host:')</td><td>$hostname</td></tr>
726 <tr><td>$(_ 'Uptime:')</td>
727 <td id="uptime">$(uptime | sed 's|\([0-9.:][0-9.:]*\)|<b>\1</b>|g')</td>
728 </tr>
729 <tr><td>$(_ 'Memory in Mb:')</td>
730 <td>$(free -m | grep Mem: | \
731 awk -vline="$(gettext 'Total: %d, Used: %d, Free: %d')" \
732 '{ printf(line, $2, $3, $4) }' | \
733 sed 's|\([0-9][0-9]*\)|<b>\1</b>|g')</td>
734 </tr>
735 <tr><td>$(_ 'Linux kernel:')</td>
736 <td>$(uname -r)</td>
737 </tr>
738 </table>
739 </section>
742 <section>
743 <header>
744 $(_ 'Network status')
745 <form action="network.cgi">
746 <button data-icon="wifi">$(_ 'Network')</button>
747 </form>
748 </header>
749 $(list_network_interfaces)
750 </section>
753 <section>
754 <header>
755 $(_ 'Filesystem usage statistics')
756 <form action="hardware.cgi">
757 <button data-icon="hdd">$(_ 'Disks')</button>
758 </form>
759 </header>
760 <table class="wide zebra center">
761 EOT
762 # Disk stats (management is done as hardware.cgi)
763 df_thead
764 echo '<tbody>'
765 df -h | grep ^/dev | while read fs size used av pct mp; do
766 cat <<EOT
767 <tr>
768 <td><span data-icon="hdd">${fs#/dev/}</span></td>
769 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
770 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
771 <td>$size</td>
772 <td>$av</td>
773 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
774 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
775 <span>$used - $pct</span>
776 </td>
777 <td>$mp</td>
778 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
779 </tr>
780 EOT
781 done
782 cat <<EOT
783 </tbody>
784 </table>
785 </section>
787 <section>
788 <header>
789 $(_ 'Panel Activity')
790 <form>
791 <button name="file" value="$LOG_FILE" data-icon="view">$(_ 'View')</button>
792 </form>
793 </header>
794 <div>
795 <pre id="panel-activity">
796 $(tail -n 8 < $LOG_FILE | sort -r | syntax_highlighter activity)</pre>
797 </div>
798 </section>
799 EOT
800 ;;
801 esac
803 xhtml_footer
804 exit 0