tazpanel view index.cgi @ rev 533

index.cgi: add kill button
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Aug 29 12:16:13 2015 +0200 (2015-08-29)
parents 8a5c0513df49
children c0f8e615df7d
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 </header>
123 <textarea form="editform" name="content" class="wide" rows="30" autofocus>$(htmlize < $file)</textarea>
124 </section>
125 EOT
126 #The space before textarea gets muddled when the form is submitted.
127 #It prevents anything else from getting messed up
128 ;;
130 setvar)
131 data="$(. $(GET file) ;eval echo \$$(GET var))"
132 cat <<EOT
133 <section>
134 <header>$(GET var)</header>
135 <form method="post" action="?file=$file" class="nogap">
136 <input type="hidden" name="var" value="$(GET var)">
137 <input type="text" name="content" value="${data:-$(GET default)}">
138 <button type="submit" data-icon="save">$(_ 'Save')</button>
139 </form>
140 </section>
141 EOT
142 ;;
144 diff)
145 cat <<EOT
146 <section>
147 <pre id="diff">$(file_is_modified $file diff | syntax_highlighter diff)</pre>
148 </section>
149 EOT
150 ;;
152 *)
153 R=$(echo -en '\r')
154 if [ -n "$(POST content)" ]; then
155 if [ -n "$(POST var)" ]; then
156 sed -i "s|^\\($(POST var)=\\).*|\1\"$(POST content)\"|" $file
157 else
158 sed "s/$R /\n/g;s/$R%0//g" > $file <<EOT
159 $(POST content)
160 EOT
161 fi
162 fi
164 cat <<EOT
165 <section class="bigNoScrollable">
166 <header>
167 <span data-icon="text">${title:-$file}</span>
168 EOT
169 if [ -w "$file" ]; then
170 cat <<EOT
171 <form>
172 <input type="hidden" name="file" value="$file"/>
173 <button onclick='editFile(); return false' id="edit_button"
174 data-icon="edit">$(_ 'Edit')</button><!--
175 --><button onclick='saveFile("$file", "$title"); return false' id="save_button"
176 data-icon="save" style="display:none">$(_ 'Save')</button><!--
177 -->$(file_is_modified $file button)
178 </form>
179 EOT
180 elif [ -r "$file" ]; then
181 cat <<EOT
182 <form>
183 <input type="hidden" name="file" value="$file"/>
184 $(file_is_modified $file button)
185 </form>
186 EOT
187 fi
188 cat <<EOT
189 </header>
191 <div>
192 <pre id="fileContent" class="bigScrollable">
193 EOT
194 end_code=''
195 # Handle file type by extension as a Web Server does it.
196 case "$file" in
197 *.sh|*.cgi|*/receipt|*.conf)
198 echo '<code class="language-bash">'; end_code='</code>'
199 htmlize ;;
200 *.ini)
201 echo '<code class="language-ini">'; end_code='</code>'
202 htmlize ;;
203 *.conf|*.lst)
204 syntax_highlighter conf ;;
205 *Xorg.0.log)
206 syntax_highlighter xlog ;;
207 *dmesg.log)
208 syntax_highlighter kernel ;;
209 *)
210 htmlize ;;
211 esac < $file
212 cat <<EOT
213 $end_code</pre>
214 </div>
215 </section>
216 EOT
217 esac
218 ;;
222 *\ terminal\ *|*\ cmd\ *)
223 # Cmdline terminal
225 header; xhtml_header "$(_ 'Terminal')"
227 user="$REMOTE_USER"
228 HOME="$(getdb passwd | awk -F: -vu=$user '$1==u{print $6}')"
229 historyfile="$HOME/.ash_history"
231 cmd=$(GET cmd)
232 path="$(GET path)"; path="${path:-/tmp}"; cd "$path"
234 font="${TERM_FONT:-monospace}"
235 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
237 [ -n "$cmd" -a "$cmd" != "$(tail -n1 $historyfile)" ] && echo "$cmd" >> $historyfile
240 # Terminal history
242 if [ "$cmd" == 'history' ]; then
243 cat <<EOT
244 <section>
245 <header>
246 $(_ 'History')
247 <form><button name="terminal" data-icon="terminal">$(_ 'Back')</button></form>
248 </header>
249 <form>
250 <input type="hidden" name="path" value="$path"/>
251 <pre class="term $palette" style="font-family: '$font'">
252 EOT
254 htmlize < $historyfile | awk -vrun="$(_ 'run')" -vpath="$path" -vq="'" '
255 BEGIN { num = 1; }
256 {
257 printf("%3d ", num);
258 cmd = $0;
259 gsub("%", "%25", cmd); gsub("+", "%2B", cmd); gsub(" ", "+", cmd);
260 gsub("\"", "%22", cmd); gsub("!", "%21", cmd); gsub(q, "%27", cmd);
261 printf("<a data-icon=\"run\" href=\"?cmd=%s&path=%s\">%s</a> ", cmd, path, run);
262 printf("<input type=\"checkbox\" name=\"rm\" value=\"%d\" id=\"hist%d\">", num, num);
263 printf("<label for=\"hist%d\">%s</label>\n", num, $0);
264 num++;
265 }'
267 cat <<EOT
268 </pre>
269 <footer>
270 <button name="rmhistory" data-icon="remove">$(_ 'Clear')</button>
271 </footer>
272 </form>
273 </section>
274 EOT
275 xhtml_footer
276 exit 0
277 fi
280 # Terminal window
282 cat <<EOT
283 <span id="num_hist"></span>
284 <section>
285 <pre class="term $palette" style="font-family: '$font'" onclick="document.getElementById('typeField').focus()">
286 EOT
287 if [ -n "$cmd" ]; then
288 term_prompt
289 echo "$cmd" | htmlize
290 fi
292 case "$cmd" in
293 usage|help)
294 _ 'Small non-interactive terminal emulator.'; echo
295 _ 'Run any command at your own risk, avoid interactive commands (%s)' 'nano, mc, ...'; echo
296 ;;
297 wget*)
298 dl='/var/cache/downloads'
299 [ ! -d "$dl" ] && mkdir -p $dl
300 _ 'Downloading to: %s' $dl; echo
301 cd $dl; $cmd 2>&1 ;;
302 cd|cd\ *)
303 path="${cmd#cd}"; path="${path:-$HOME}";
304 path="$(realpath $path)"; cd "$path" ;;
305 ls|ls\ *)
306 $cmd -w80 --color=always 2>&1 | filter_taztools_msgs ;;
307 cat)
308 # Cmd must be used with an arg.
309 _ '%s needs an argument' "$cmd" ;;
310 mc|nano|su)
311 # List of restricted (interactive) commands
312 _ "Please, don't run interactive command \"%s\"" "$cmd"; echo; echo ;;
313 *)
314 unset HTTP_REFERER # for fooling /lib/libtaz.sh formatting utils (<hr> in the terminal is so-so)
315 export DISPLAY=:0.0 # for run X applications
316 /bin/sh -c "$cmd" 2>&1 | htmlize | filter_taztools_msgs
317 ;;
318 esac
320 cat <<EOT
321 <form id="term">
322 <div class="cmdline" id="cmdline"><span id="prompt">$(term_prompt)</span><span id="typeField"> </span></div>
323 <input type="hidden" name="path" value="$(pwd)"/>
324 <input type="hidden" name="cmd" id="cmd"/>
325 </form>
326 </pre>
327 </section>
329 <form>
330 <button name="termsettings" data-icon="settings">$(_ 'Settings')</button>
331 <button name="cmd" value="history" data-icon="history">$(_ 'History')</button>
332 </form>
334 <script type="text/javascript">
335 with (document.getElementById('typeField')) {
336 contentEditable=true;
337 focus();
338 }
339 document.onkeydown=keydownHandler;
340 EOT
342 # Export history as array.
343 # Escape "all \"quotes\" in quotes", and all '\'
344 # (because \u, \x, \c has special meaning and can produce syntax error and stop js)
345 sed 's|\\|\\\\|g; s|"|\\"|g' $historyfile | awk '
346 BEGIN{ i=1; printf("ash_history=[") }
347 { printf("\"%s\",", $0); i++ }
348 END{
349 printf("\"\"];")
350 i--; printf("cur_hist=\"%d\";max_hist=\"%d\";", i, i)
351 }'
352 cat <<EOT
353 </script>
354 EOT
355 ;;
358 *\ rmhistory\ *)
359 # Manage shell commandline history
360 user="$REMOTE_USER"
361 HOME="$(getdb passwd | awk -F: -vu="$user" '$1==u{print $6}')"
362 historyfile="$HOME/.ash_history"
364 # Return sed command for removing history lines ('8d12d' to remove 8 and 12 lines)
365 rms=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="rm")printf "%dd", $2}')
367 if [ -n "$rms" ]; then
368 # Actually remove lines
369 sed -i $rms $historyfile
370 # Redirects back to the history table
371 header "HTTP/1.1 301 Moved Permanently" "Location: ?terminal&cmd=history&path=$(GET path)"
372 exit 0
373 fi
374 ;;
377 *\ termsettings\ *)
378 # Terminal settings
379 header; xhtml_header "$(_ 'Terminal')"
380 user="$REMOTE_USER"
381 font="$(GET font)"; font="${font:-$TERM_FONT}"
382 palette="$(GET palette)"; palette="${palette:-$TERM_PALETTE}"
383 pal=$(echo $palette | tr A-Z a-z)
385 # Add or change settings in TazPanel config
386 if [ -z "$TERM_FONT" ]; then
387 echo -e "\n# Terminal font family\nTERM_FONT=\"$font\"" >> $CONFIG
388 else
389 sed -i "s|TERM_FONT=.*|TERM_FONT=\"$font\"|" $CONFIG
390 fi
391 if [ -z "$TERM_PALETTE" ]; then
392 echo -e "\n# Terminal color palette\nTERM_PALETTE=\"$palette\"" >> $CONFIG
393 else
394 sed -i "s|TERM_PALETTE=.*|TERM_PALETTE=\"$palette\"|" $CONFIG
395 fi
397 cat <<EOT
398 <section style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0.5rem;">
399 <header>
400 $(_ 'Terminal settings')
401 <form>
402 <button name="terminal" data-icon="terminal">$(_ 'Terminal')</button>
403 </form>
404 </header>
405 <pre class="term $pal" style="height: auto; font-family: '$font'">
406 <span class='color31'>$user@$(hostname)</span>:<span class='color33'>~</span># palette
408 $(
409 for i in $(seq 30 37); do
410 for b in 0 1; do
411 for j in $(seq 40 47); do
412 echo -n "<span class=\"color$b color$i color$j\">$i:$j</span>"
413 done
414 done
415 echo
416 done
417 )
418 </pre>
419 <footer>
420 <form class="wide">
421 $(_ 'Font:')
422 <select name="font">
423 <option value="">$(_ 'Default')</option>
424 $(fc-list :spacing=mono:lang=en family | sed '/\.pcf/d;/,/d;s|\\-|-|g' | sort -u | \
425 awk -vfont="$font" '{
426 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == font)?" selected":"", $0)
427 }')
428 </select>
429 $(_ 'Palette:')
430 <select name="palette">
431 $(echo -e 'Tango\nLinux\nXterm\nRxvt\nEcho' | awk -vpal="$palette" '{
432 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == pal)?" selected":"", $0)
433 }')
434 </select>
435 <button name="termsettings" data-icon="ok">$(_ 'Apply')</button>
436 </form>
437 </footer>
438 </section>
439 EOT
441 ;;
444 *\ top\ *)
445 header; xhtml_header "$(_ 'Process activity')"
447 r=$(GET refresh)
448 cat <<EOT
449 <form>
450 <p>$(_ 'Refresh:')
451 <input type="hidden" name="top"/>
452 <input type="radio" name="refresh" value="1" id="r1" $([ "$r" == 1 ] && echo checked) onchange="this.form.submit()"/>
453 <label for="r1">$(_ '1s' )</label>
454 <input type="radio" name="refresh" value="5" id="r2" $([ "$r" == 5 ] && echo checked) onchange="this.form.submit()"/>
455 <label for="r2">$(_ '5s' )</label>
456 <input type="radio" name="refresh" value="10" id="r3" $([ "$r" == 10 ] && echo checked) onchange="this.form.submit()"/>
457 <label for="r3">$(_ '10s' )</label>
458 <input type="radio" name="refresh" value="" id="r4" $([ -z "$r" ] && echo checked) onchange="this.form.submit()"/>
459 <label for="r4">$(_ 'none')</label>
460 </p>
461 </form>
462 EOT
463 [ -n "$r" ] && echo "<meta http-equiv=\"refresh\" content=\"$r\">"
465 [ "$(GET renice)" ] && renice $(GET renice)
466 [ "$(GET kill)" ] && kill $(GET kill)
467 if [ "$(GET pid)" ] && [ -d /proc/$(GET pid)/ ]; then
468 curpid=$(GET pid)
469 curnice=$(awk '{ print $19 }' /proc/$curpid/stat)
470 cat <<EOT
471 <section>
472 <header>
473 $(ps auxww | sed "/^ *$curpid /!d")
474 <form>
475 <input type="hidden" name="top"/>
476 <button type="submit" data-icon="remove" name="kill" value="$curpid">$(_ 'Kill')</button>
477 </form>
478 </header>
479 <form>
480 <p>$(_ 'Renice')[$curnice]
481 <input type="hidden" name="top"/>
482 EOT
483 values="+19 +15 +10 +5 +3 +1 0 -1 -3 -5 -10 -15 -19"
484 [ $(id -u) -eq 0 ] || values="+19 +15 +10 +5 +3 +1"
485 for i in $values ; do
486 cat <<EOT
487 <input type="radio" name="renice" value="$i $curpid" $([ $curnice -eq $i ] && echo checked) onchange="this.form.submit()"/>
488 <label>$i</label>
489 EOT
490 done
491 cat <<EOT
492 </p>
493 </form>
494 </section>
495 EOT
496 fi
497 echo '<section><div><pre class="term log">'
498 busybox top -n1 -b | htmlize | sed \
499 -e 's|^\( *\)\([0-9][0-9]*\)|\1<a href="?top\&amp;pid=\2">\2</a>|' \
500 -e 's|^[A-Z].*:|<span class="color1 color31">\0</span>|g' \
501 -e 's|^\ *PID|<span class="color1 color32">\0</span>|g'
502 echo '</pre></div></section>' ;;
505 *\ debug\ *)
506 header; xhtml_header "$(_ 'Debug')"
508 cat <<EOT
509 <h2>$(_ 'HTTP Environment')</h2>
511 <section>
512 <div>
513 <pre>$(httpinfo | syntax_highlighter conf)</pre>
514 </div>
515 </section>
516 EOT
517 ;;
520 *\ report\ *)
521 header; xhtml_header "$(_ 'System report')"
523 [ -d '/var/cache/slitaz' ] || mkdir -p /var/cache/slitaz
524 output='/var/cache/slitaz/sys-report.html'
526 cat <<EOT
527 <section>
528 <header>$(_ 'Reporting to: %s' "$output")</header>
529 <table class="wide zebra">
530 <tbody>
531 <tr><td>$(_ 'Creating report header...')</td>
532 EOT
533 cat > $output <<EOT
534 <!DOCTYPE html>
535 <html xmlns="http://www.w3.org/1999/xhtml">
536 <head>
537 <meta charset="utf-8"/>
538 <title>$(_ 'SliTaz system report')</title>
539 <style type="text/css">
540 body { padding: 20px 60px; font-size: 13px; }
541 h1, h2 { color: #444; }
542 pre { background: #f1f1f1; border: 1px solid #ddd;
543 padding: 10px; border-radius: 4px; }
544 span.diff-rm { color: red; }
545 span.diff-add { color: green; }
546 </style>
547 </head>
548 <body>
549 EOT
550 cat <<EOT
551 $(ok_status_t)
552 <tr><td>$(_ 'Creating system summary...')</td>
553 EOT
554 cat >> $output <<EOT
555 <h1>$(_ 'SliTaz system report')</h1>
556 $(_ 'Date:') $(date)
557 <pre>
558 uptime : $(uptime)
559 cmdline : $(cat /proc/cmdline)
560 version : $(cat /etc/slitaz-release)
561 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
562 kernel : $(uname -r)
563 </pre>
564 EOT
565 cat <<EOT
566 $(ok_status_t)
567 <tr><td>$(_ 'Getting hardware info...')</td>
568 EOT
569 cat >> $output <<EOT
570 <h2>free</h2>
571 <pre>$(free)</pre>
573 <h2>lspci -k</h2>
574 <pre>$(lspci -k)</pre>
576 <h2>lsusb</h2>
577 <pre>$(lsusb)</pre>
579 <h2>lsmod</h2>
580 <pre>$(lsmod)</pre>
582 EOT
583 cat <<EOT
584 $(ok_status_t)
585 <tr><td>$(_ 'Getting networking info...')</td>
586 EOT
587 cat >> $output <<EOT
588 <h2>ifconfig -a</h2>
589 <pre>$(ifconfig -a)</pre>
591 <h2>route -n</h2>
592 <pre>$(route -n)</pre>
594 <h2>/etc/resolv.conf</h2>
595 <pre>$(cat /etc/resolv.conf)</pre>
596 EOT
597 cat <<EOT
598 $(ok_status_t)
599 <tr><td>$(_ 'Getting filesystems info...')</td>
600 EOT
601 cat >> $output <<EOT
602 <h2>blkid</h2>
603 <pre>$(blkid)</pre>
605 <h2>fdisk -l</h2>
606 <pre>$(fdisk -l)</pre>
608 <h2>mount</h2>
609 <pre>$(mount)</pre>
611 <h2>df -h</h2>
612 <pre>$(df -h)</pre>
614 <h2>df -i</h2>
615 <pre>$(df -i)</pre>
616 EOT
617 cat <<EOT
618 $(ok_status_t)
619 <tr><td>$(_ 'Getting boot logs...')</td>
620 EOT
621 cat >> $output <<EOT
622 <h2>$(_ 'Kernel messages')</h2>
623 <pre>$(cat /var/log/dmesg.log)</pre>
625 <h2>$(_ 'Boot scripts')</h2>
626 <pre>$(filter_taztools_msgs < /var/log/boot.log)</pre>
627 EOT
628 cat <<EOT
629 $(ok_status_t)
630 <tr><td>$(_ 'Getting package list...')</td>
631 EOT
632 cat >> $output <<EOT
633 <h2>$(_ 'Packages')</h2>
634 EOT
635 ( cd /var/lib/tazpkg/installed
636 for i in * ; do
637 echo "$i $(. $i/receipt ; echo "$VERSION $DEPENDS" | xargs echo ;
638 echo "$PROVIDE" | sed 's/:[^ ]*//g' | xargs echo PROVIDE)"
639 done ) | awk '{
640 if ($1 == "PROVIDE") {
641 for (i = 2; i <= NF; i++) alias[$i] = 1
642 }
643 else { pkg[$1]=$0; idx[c++]=$1 }
644 }
645 function name(n)
646 {
647 split(pkg[n], x, " ")
648 return x[1] " (" x[2] ") "
649 }
650 END {
651 print "<pre>"
652 for (i in pkg) for (j = split(pkg[i], p, " "); j > 2; j--) {
653 if (pkg[p[j]] || alias[p[j]]) kill[p[j]]=1
654 else { miss=1 ; print "Missing dep " p[j] " for " name(p[1]) }
655 }
656 if (miss) print ""
657 n=0
658 for (i=0; i < c; i++) {
659 if (kill[idx[i]]) continue
660 printf "%s" name(idx[i])
661 if (n++ < 2) continue
662 printf "\n"
663 n=0
664 }
665 print "</pre>"
666 }
667 ' >> $output
668 if [ "$(ls report.d/* 2> /dev/null)" ]; then
669 cat <<EOT
670 $(ok_status_t)
671 <tr><td>$(_ 'Getting extra reports...')</td>
672 EOT
673 for i in report.d/* ; do
674 sh $i $i >> $output
675 done
676 fi
677 cat <<EOT
678 $(ok_status_t)
679 <tr><td>$(_ 'Creating report footer...')</td>
680 EOT
681 cat >> $output <<EOT
682 </body>
683 </html>
684 EOT
685 cat <<EOT
686 $(ok_status_t)
687 </tbody>
688 </table>
689 <footer>
690 <form><button name="file" value="$output" data-icon="view">$(_ 'View')</button></form>
691 </footer>
692 </section>
695 $(msg tip "$(_ 'This report can be attached with a bug report on:')
696 <a href="http://bugs.slitaz.org/" target="_blank">bugs.slitaz.org</a></p>")
697 EOT
698 ;;
701 *)
702 #
703 # Default xHTML content
704 #
705 header; xhtml_header "$(_ 'SliTaz administration and configuration Panel')"
706 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
707 [ -n "$(GET rdate)" ] && echo ""
708 hostname=$(hostname)
710 cat <<EOT
711 <form class="nogap"><!--
712 --><button name="terminal" data-icon="terminal">$(_ 'Terminal')</button><!--
713 --><button name="top" data-icon="proc" >$(_ 'Process activity')</button><!--
714 --><button name="report" data-icon="report" data-root>$(_ 'Create a report')</button><!--
715 --></form>
717 <section>
718 <header>$(_ 'Summary')</header>
719 <table>
720 <tr><td>$(_ 'Host:')</td><td>$hostname</td></tr>
721 <tr><td>$(_ 'Uptime:')</td>
722 <td id="uptime">$(uptime | sed 's|\([0-9.:][0-9.:]*\)|<b>\1</b>|g')</td>
723 </tr>
724 <tr><td>$(_ 'Memory in Mb:')</td>
725 <td>$(free -m | grep Mem: | \
726 awk -vline="$(gettext 'Total: %d, Used: %d, Free: %d')" \
727 '{ printf(line, $2, $3, $4) }' | \
728 sed 's|\([0-9][0-9]*\)|<b>\1</b>|g')</td>
729 </tr>
730 <tr><td>$(_ 'Linux kernel:')</td>
731 <td>$(uname -r)</td>
732 </tr>
733 </table>
734 </section>
737 <section>
738 <header>
739 $(_ 'Network status')
740 <form action="network.cgi">
741 <button data-icon="wifi">$(_ 'Network')</button>
742 </form>
743 </header>
744 $(list_network_interfaces)
745 </section>
748 <section>
749 <header>
750 $(_ 'Filesystem usage statistics')
751 <form action="hardware.cgi">
752 <button data-icon="hdd">$(_ 'Disks')</button>
753 </form>
754 </header>
755 <table class="wide zebra center">
756 EOT
757 # Disk stats (management is done as hardware.cgi)
758 df_thead
759 echo '<tbody>'
760 df -h | grep ^/dev | while read fs size used av pct mp; do
761 cat <<EOT
762 <tr>
763 <td><span data-icon="hdd">${fs#/dev/}</span></td>
764 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
765 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
766 <td>$size</td>
767 <td>$av</td>
768 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
769 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
770 <span>$used - $pct</span>
771 </td>
772 <td>$mp</td>
773 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
774 </tr>
775 EOT
776 done
777 cat <<EOT
778 </tbody>
779 </table>
780 </section>
782 <section>
783 <header>
784 $(_ 'Panel Activity')
785 <form>
786 <button name="file" value="$LOG_FILE" data-icon="view">$(_ 'View')</button>
787 </form>
788 </header>
789 <div>
790 <pre id="panel-activity">
791 $(tail -n 8 < $LOG_FILE | sort -r | syntax_highlighter activity)</pre>
792 </div>
793 </section>
794 EOT
795 ;;
796 esac
798 xhtml_footer
799 exit 0