tazpanel view index.cgi @ rev 626

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