tazpanel view index.cgi @ rev 556

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