tazpanel view index.cgi @ rev 555

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