tazpanel view index.cgi @ rev 553

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