tazpanel annotate index.cgi @ rev 507

nss support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jul 12 16:19:16 2015 +0200 (2015-07-12)
parents a8ff72f76e0d
children a6066b70a2af
rev   line source
pankso@2 1 #!/bin/sh
pankso@2 2 #
al@419 3 # Main CGI interface for TazPanel. In on word: KISS. Use the main CSS form
paul@52 4 # command so we are faster and do not load unneeded functions. If necessary
pankso@14 5 # you can use the lib/ dir to handle external resources.
pankso@2 6 #
al@419 7 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
pankso@42 8 #
pankso@2 9
al@419 10
pankso@14 11 # Common functions from libtazpanel
al@419 12
pankso@14 13 . lib/libtazpanel
pankso@14 14 get_config
pankso@2 15
al@501 16 TITLE='TazPanel'
al@292 17
al@419 18
al@419 19
paul@127 20 # Check whether a configuration file has been modified after installation
al@419 21
al@437 22 file_is_modified() {
pascal@91 23 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
al@292 24
al@419 25 # Found, but can we do diff?
pascal@91 26 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
al@419 27 orig=$(dirname $file)/volatile.cpio.gz
al@419 28 zcat $orig 2>/dev/null | cpio -t 2>/dev/null | grep -q "^${1#/}$" || break
pascal@91 29
pascal@91 30 case "$2" in
al@419 31 diff)
al@419 32 tmp=$(mktemp -d)
al@419 33 ( cd $tmp; zcat $orig | cpio -id ${1#/} )
al@419 34 diff -abu $tmp$1 $1 | sed "s|$tmp||"
al@419 35 rm -rf $tmp;;
al@419 36 button)
al@437 37 echo -n '<button name="action" value="diff" data-icon="diff">'$(_ 'Differences')'</button>';;
pascal@91 38 esac
pascal@93 39 break
pascal@91 40 done
pascal@91 41 }
al@312 42
al@312 43
al@303 44 # OK status in table
al@419 45
al@303 46 ok_status_t() {
al@419 47 echo '<td><span class="diff-add" data-img="ok"></span></td></tr>'
al@303 48 }
al@303 49
al@303 50
al@419 51
al@437 52 # Terminal prompt
al@437 53
al@437 54 term_prompt() {
al@437 55 if [ "$user" == 'root' ]; then
al@437 56 local color1='color31' sign='#'
al@437 57 else
al@437 58 local color1='color32' sign='$'
al@437 59 fi
al@437 60 echo -n "<span class='$color1'>$user@$(hostname)</span>:<span class='color33'>"
al@437 61 pwd | sed "s|^$HOME|~|" | tr -d '\n'; echo -n "</span>$sign "
al@437 62 }
al@437 63
al@437 64
al@437 65
pankso@2 66 #
pankso@2 67 # Commands
pankso@2 68 #
pankso@2 69
pascal@81 70 case " $(GET) " in
al@419 71
al@419 72
pascal@364 73 *\ exec\ *)
al@419 74 # Execute command and display its result in a terminal-like window
al@419 75
al@501 76 header; xhtml_header "$(_ 'exec')"
al@419 77
pascal@364 78 exec="$(GET exec)"
al@419 79 font="${TERM_FONT:-monospace}"
al@419 80 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
al@419 81
al@419 82 cat <<EOT
al@419 83 <section>
al@419 84 <header>
al@419 85 $exec
al@419 86 $(back_button "$(GET back)" "$(GET back_caption)" "$(GET back_icon)")
al@419 87 </header>
al@419 88 <div class="term_">
al@419 89 <pre class="term $palette" style="font-family: '$font'">$($exec 2>&1 | htmlize | filter_taztools_msgs)</pre>
al@419 90 </div>
al@419 91 </section>
pascal@364 92 EOT
pascal@364 93 ;;
al@419 94
al@419 95
pascal@81 96 *\ file\ *)
pankso@56 97 #
pascal@91 98 # Handle files
pankso@56 99 #
al@419 100 header
pascal@81 101 file="$(GET file)"
al@419 102 action="$(POST action)"; [ -z "$action" ] && action="$(GET action)" # receive 'action' both on POST or GET
al@463 103 title="$(POST title)"; [ -z "$title" ] && title="$(GET title)" # (optional)
al@419 104
pankso@161 105 case $file in
pankso@161 106 *.html)
al@419 107 cat $file; exit 0 ;;
pankso@161 108 *)
al@501 109 xhtml_header "$(_ 'File')";;
pankso@161 110 esac
al@303 111
al@419 112 case "$action" in
al@419 113 edit)
al@419 114 cat <<EOT
al@419 115 <section>
al@419 116 <header>
al@463 117 <span data-icon="edit">${title:-$file}</span>
al@463 118 <form id="editform" method="post" action="?file=$file">
al@443 119 <button data-icon="save">$(_ 'Save')</button>
al@443 120 <button name="action" value="diff" data-icon="diff">$(_ 'Differences')</button>
al@419 121 </form>
al@419 122 </header>
pascal@504 123 <textarea form="editform" name="content" class="wide" rows="30" autofocus>$(htmlize < $file)</textarea>
al@419 124 </section>
pascal@90 125 EOT
naitsirhc@267 126 #The space before textarea gets muddled when the form is submitted.
naitsirhc@267 127 #It prevents anything else from getting messed up
al@419 128 ;;
al@419 129
al@419 130 setvar)
pascal@364 131 data="$(. $(GET file) ;eval echo \$$(GET var))"
pascal@364 132 cat <<EOT
al@419 133 <section>
al@419 134 <header>$(GET var)</header>
al@419 135 <form method="post" action="?file=$file" class="nogap">
al@419 136 <input type="hidden" name="var" value="$(GET var)">
al@419 137 <input type="text" name="content" value="${data:-$(GET default)}">
al@443 138 <button type="submit" data-icon="save">$(_ 'Save')</button>
al@419 139 </form>
al@419 140 </section>
pascal@364 141 EOT
al@419 142 ;;
al@419 143
al@419 144 diff)
al@419 145 cat <<EOT
al@419 146 <section>
al@419 147 <pre id="diff">$(file_is_modified $file diff | syntax_highlighter diff)</pre>
al@419 148 </section>
al@419 149 EOT
al@419 150 ;;
al@419 151
al@419 152 *)
al@340 153 R=$(echo -en '\r')
pascal@364 154 if [ -n "$(POST content)" ]; then
pascal@364 155 if [ -n "$(POST var)" ]; then
pascal@364 156 sed -i "s|^\\($(POST var)=\\).*|\1\"$(POST content)\"|" $file
pascal@364 157 else
pascal@364 158 sed "s/$R /\n/g;s/$R%0//g" > $file <<EOT
pascal@90 159 $(POST content)
pascal@90 160 EOT
pascal@364 161 fi
pascal@364 162 fi
al@419 163
pascal@90 164 cat <<EOT
al@463 165 <section class="bigNoScrollable">
al@439 166 <header>
al@463 167 <span data-icon="text">${title:-$file}</span>
pascal@433 168 EOT
pascal@444 169 if [ -w "$file" ]; then
pascal@444 170 cat <<EOT
al@472 171 <form>
al@419 172 <input type="hidden" name="file" value="$file"/>
al@472 173 <button onclick='editFile(); return false' id="edit_button"
al@472 174 data-icon="edit">$(_ 'Edit')</button><!--
al@472 175 --><button onclick='saveFile("$file", "$title"); return false' id="save_button"
al@472 176 data-icon="save" style="display:none">$(_ 'Save')</button><!--
al@419 177 -->$(file_is_modified $file button)
al@472 178 </form>
pascal@433 179 EOT
pascal@444 180 elif [ -r "$file" ]; then
pascal@444 181 cat <<EOT
pascal@444 182 <form>
pascal@444 183 <input type="hidden" name="file" value="$file"/>
pascal@444 184 $(file_is_modified $file button)
pascal@444 185 </form>
pascal@444 186 EOT
pascal@444 187 fi
pascal@433 188 cat <<EOT
al@439 189 </header>
al@439 190
al@419 191 <div>
al@463 192 <pre id="fileContent" class="bigScrollable">
al@303 193 EOT
al@463 194 end_code=''
pascal@90 195 # Handle file type by extension as a Web Server does it.
pascal@90 196 case "$file" in
al@463 197 *.sh|*.cgi|*/receipt|*.conf)
al@463 198 echo '<code class="language-bash">'; end_code='</code>'
pascal@504 199 htmlize ;;
al@463 200 *.ini)
al@463 201 echo '<code class="language-ini">'; end_code='</code>'
pascal@504 202 htmlize ;;
pascal@90 203 *.conf|*.lst)
pascal@90 204 syntax_highlighter conf ;;
al@419 205 *Xorg.0.log)
al@419 206 syntax_highlighter xlog ;;
al@419 207 *dmesg.log)
al@419 208 syntax_highlighter kernel ;;
pascal@90 209 *)
pascal@504 210 htmlize ;;
pascal@90 211 esac < $file
al@419 212 cat <<EOT
al@463 213 $end_code</pre>
al@419 214 </div>
al@419 215 </section>
al@419 216 EOT
al@419 217 esac
al@419 218 ;;
al@419 219
al@303 220
al@312 221
pankso@191 222 *\ terminal\ *|*\ cmd\ *)
al@419 223 # Cmdline terminal
al@419 224
al@501 225 header; xhtml_header "$(_ 'Terminal')"
al@419 226
al@437 227 user="$REMOTE_USER"
pascal@507 228 HOME="$(getdb passwd | awk -F: -vu=$user '$1==u{print $6}')"
al@437 229 historyfile="$HOME/.ash_history"
al@437 230
pankso@191 231 cmd=$(GET cmd)
al@437 232 path="$(GET path)"; path="${path:-/tmp}"; cd "$path"
al@419 233
al@419 234 font="${TERM_FONT:-monospace}"
al@419 235 palette=$(echo $TERM_PALETTE | tr A-Z a-z)
al@419 236
al@419 237 [ -n "$cmd" -a "$cmd" != "$(tail -n1 $historyfile)" ] && echo "$cmd" >> $historyfile
al@419 238
al@419 239
al@419 240 # Terminal history
al@419 241
al@419 242 if [ "$cmd" == 'history' ]; then
al@419 243 cat <<EOT
al@312 244 <section>
al@419 245 <header>
al@443 246 $(_ 'History')
al@443 247 <form><button name="terminal" data-icon="terminal">$(_ 'Back')</button></form>
al@419 248 </header>
al@419 249 <form>
al@419 250 <input type="hidden" name="path" value="$path"/>
al@419 251 <pre class="term $palette" style="font-family: '$font'">
pankso@191 252 EOT
al@501 253
al@501 254 htmlize < $historyfile | awk -vrun="$(_ 'run')" -vpath="$path" -vq="'" '
al@501 255 BEGIN { num = 1; }
al@501 256 {
al@501 257 printf("%3d ", num);
al@501 258 cmd = $0;
al@501 259 gsub("%", "%25", cmd); gsub("+", "%2B", cmd); gsub(" ", "+", cmd);
al@501 260 gsub("\"", "%22", cmd); gsub("!", "%21", cmd); gsub(q, "%27", cmd);
al@501 261 printf("<a data-icon=\"run\" href=\"?cmd=%s&path=%s\">%s</a> ", cmd, path, run);
al@501 262 printf("<input type=\"checkbox\" name=\"rm\" value=\"%d\" id=\"hist%d\">", num, num);
al@501 263 printf("<label for=\"hist%d\">%s</label>\n", num, $0);
al@501 264 num++;
al@501 265 }'
al@501 266
al@419 267 cat <<EOT
al@419 268 </pre>
al@419 269 <footer>
al@443 270 <button name="rmhistory" data-icon="remove">$(_ 'Clear')</button>
al@419 271 </footer>
al@419 272 </form>
al@419 273 </section>
al@419 274 EOT
al@419 275 xhtml_footer
al@419 276 exit 0
al@419 277 fi
al@419 278
al@419 279
al@419 280 # Terminal window
al@419 281
al@419 282 cat <<EOT
al@419 283 <span id="num_hist"></span>
al@419 284 <section>
al@419 285 <pre class="term $palette" style="font-family: '$font'" onclick="document.getElementById('typeField').focus()">
al@419 286 EOT
al@419 287 if [ -n "$cmd" ]; then
al@437 288 term_prompt
al@419 289 echo "$cmd" | htmlize
al@419 290 fi
al@419 291
al@419 292 case "$cmd" in
pankso@191 293 usage|help)
al@443 294 _ 'Small non-interactive terminal emulator.'; echo
al@463 295 _ 'Run any command at your own risk, avoid interactive commands (%s)' 'nano, mc, ...'; echo
al@419 296 ;;
pankso@191 297 wget*)
al@501 298 dl='/var/cache/downloads'
pankso@191 299 [ ! -d "$dl" ] && mkdir -p $dl
al@443 300 _ 'Downloading to: %s' $dl; echo
al@419 301 cd $dl; $cmd 2>&1 ;;
al@419 302 cd|cd\ *)
al@437 303 path="${cmd#cd}"; path="${path:-$HOME}";
al@437 304 path="$(realpath $path)"; cd "$path" ;;
al@419 305 ls|ls\ *)
al@419 306 $cmd -w80 --color=always 2>&1 | filter_taztools_msgs ;;
al@419 307 cat)
pankso@194 308 # Cmd must be used with an arg.
al@443 309 _ '%s needs an argument' "$cmd" ;;
al@443 310 mc|nano|su)
al@419 311 # List of restricted (interactive) commands
al@443 312 _ "Please, don't run interactive command \"%s\"" "$cmd"; echo; echo ;;
pankso@191 313 *)
al@419 314 unset HTTP_REFERER # for fooling /lib/libtaz.sh formatting utils (<hr> in the terminal is so-so)
al@419 315 export DISPLAY=:0.0 # for run X applications
al@419 316 /bin/sh -c "$cmd" 2>&1 | htmlize | filter_taztools_msgs
al@419 317 ;;
pankso@191 318 esac
al@419 319
al@419 320 cat <<EOT
al@419 321 <form id="term">
al@437 322 <div class="cmdline" id="cmdline"><span id="prompt">$(term_prompt)</span><span id="typeField"> </span></div>
al@437 323 <input type="hidden" name="path" value="$(pwd)"/>
al@419 324 <input type="hidden" name="cmd" id="cmd"/>
al@419 325 </form>
al@419 326 </pre>
al@419 327 </section>
al@419 328
al@419 329 <form>
al@443 330 <button name="termsettings" data-icon="settings">$(_ 'Settings')</button>
al@443 331 <button name="cmd" value="history" data-icon="history">$(_ 'History')</button>
al@419 332 </form>
al@419 333
al@419 334 <script type="text/javascript">
al@419 335 with (document.getElementById('typeField')) {
al@419 336 contentEditable=true;
al@419 337 focus();
al@419 338 }
al@419 339 document.onkeydown=keydownHandler;
al@419 340 EOT
al@419 341
al@419 342 # Export history as array.
al@419 343 # Escape "all \"quotes\" in quotes", and all '\'
al@419 344 # (because \u, \x, \c has special meaning and can produce syntax error and stop js)
al@419 345 sed 's|\\|\\\\|g; s|"|\\"|g' $historyfile | awk '
al@419 346 BEGIN{ i=1; printf("ash_history=[") }
al@419 347 { printf("\"%s\",", $0); i++ }
al@419 348 END{
al@419 349 printf("\"\"];")
al@419 350 i--; printf("cur_hist=\"%d\";max_hist=\"%d\";", i, i)
al@419 351 }'
al@419 352 cat <<EOT
al@419 353 </script>
al@419 354 EOT
al@312 355 ;;
al@312 356
al@312 357
al@419 358 *\ rmhistory\ *)
al@419 359 # Manage shell commandline history
al@437 360 user="$REMOTE_USER"
pascal@507 361 HOME="$(getdb passwd | awk -F: -vu="$user" '$1==u{print $6}')"
al@437 362 historyfile="$HOME/.ash_history"
al@419 363
al@419 364 # Return sed command for removing history lines ('8d12d' to remove 8 and 12 lines)
al@419 365 rms=$(echo $QUERY_STRING | awk 'BEGIN{RS="&";FS="="}{if($1=="rm")printf "%dd", $2}')
al@419 366
al@419 367 if [ -n "$rms" ]; then
al@419 368 # Actually remove lines
al@419 369 sed -i $rms $historyfile
al@419 370 # Redirects back to the history table
al@419 371 header "HTTP/1.1 301 Moved Permanently" "Location: ?terminal&cmd=history&path=$(GET path)"
al@419 372 exit 0
al@419 373 fi
al@419 374 ;;
al@419 375
al@419 376
al@419 377 *\ termsettings\ *)
al@419 378 # Terminal settings
al@501 379 header; xhtml_header "$(_ 'Terminal')"
al@419 380 user="$REMOTE_USER"
al@419 381 font="$(GET font)"; font="${font:-$TERM_FONT}"
al@419 382 palette="$(GET palette)"; palette="${palette:-$TERM_PALETTE}"
al@419 383 pal=$(echo $palette | tr A-Z a-z)
al@419 384
al@419 385 # Add or change settings in TazPanel config
al@419 386 if [ -z "$TERM_FONT" ]; then
al@419 387 echo -e "\n# Terminal font family\nTERM_FONT=\"$font\"" >> $CONFIG
al@419 388 else
al@419 389 sed -i "s|TERM_FONT=.*|TERM_FONT=\"$font\"|" $CONFIG
al@419 390 fi
al@419 391 if [ -z "$TERM_PALETTE" ]; then
al@419 392 echo -e "\n# Terminal color palette\nTERM_PALETTE=\"$palette\"" >> $CONFIG
al@419 393 else
al@419 394 sed -i "s|TERM_PALETTE=.*|TERM_PALETTE=\"$palette\"|" $CONFIG
al@419 395 fi
al@419 396
al@419 397 cat <<EOT
al@463 398 <section style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: 0.5rem;">
al@419 399 <header>
al@443 400 $(_ 'Terminal settings')
al@419 401 <form>
al@443 402 <button name="terminal" data-icon="terminal">$(_ 'Terminal')</button>
al@419 403 </form>
al@419 404 </header>
al@419 405 <pre class="term $pal" style="height: auto; font-family: '$font'">
al@419 406 <span class='color31'>$user@$(hostname)</span>:<span class='color33'>~</span># palette
al@419 407
al@419 408 $(
al@419 409 for i in $(seq 30 37); do
al@419 410 for b in 0 1; do
al@419 411 for j in $(seq 40 47); do
al@419 412 echo -n "<span class=\"color$b color$i color$j\">$i:$j</span>"
al@419 413 done
al@419 414 done
al@419 415 echo
al@419 416 done
al@419 417 )
al@419 418 </pre>
al@419 419 <footer>
al@419 420 <form class="wide">
al@443 421 $(_ 'Font:')
al@419 422 <select name="font">
al@443 423 <option value="">$(_ 'Default')</option>
al@419 424 $(fc-list :spacing=mono:lang=en family | sed '/\.pcf/d;/,/d;s|\\-|-|g' | sort -u | \
al@419 425 awk -vfont="$font" '{
al@419 426 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == font)?" selected":"", $0)
al@419 427 }')
al@419 428 </select>
al@443 429 $(_ 'Palette:')
al@419 430 <select name="palette">
al@419 431 $(echo -e 'Tango\nLinux\nXterm\nRxvt\nEcho' | awk -vpal="$palette" '{
al@419 432 printf("<option value=\"%s\"%s>%s</option>\n", $0, ($0 == pal)?" selected":"", $0)
al@419 433 }')
al@419 434 </select>
al@443 435 <button name="termsettings" data-icon="ok">$(_ 'Apply')</button>
al@419 436 </form>
al@419 437 </footer>
al@419 438 </section>
al@419 439 EOT
al@419 440
al@419 441 ;;
al@419 442
al@419 443
pascal@144 444 *\ top\ *)
al@501 445 header; xhtml_header "$(_ 'Process activity')"
al@419 446
al@419 447 r=$(GET refresh)
al@419 448 cat <<EOT
al@419 449 <form>
al@443 450 <p>$(_ 'Refresh:')
naitsirhc@268 451 <input type="hidden" name="top"/>
al@419 452 <input type="radio" name="refresh" value="1" id="r1" $([ "$r" == 1 ] && echo checked) onchange="this.form.submit()"/>
al@443 453 <label for="r1">$(_ '1s' )</label>
al@419 454 <input type="radio" name="refresh" value="5" id="r2" $([ "$r" == 5 ] && echo checked) onchange="this.form.submit()"/>
al@443 455 <label for="r2">$(_ '5s' )</label>
al@419 456 <input type="radio" name="refresh" value="10" id="r3" $([ "$r" == 10 ] && echo checked) onchange="this.form.submit()"/>
al@443 457 <label for="r3">$(_ '10s' )</label>
al@419 458 <input type="radio" name="refresh" value="" id="r4" $([ -z "$r" ] && echo checked) onchange="this.form.submit()"/>
al@443 459 <label for="r4">$(_ 'none')</label>
al@419 460 </p>
al@303 461 </form>
al@303 462 EOT
al@419 463 [ -n "$r" ] && echo "<meta http-equiv=\"refresh\" content=\"$r\">"
naitsirhc@268 464
al@419 465 echo '<section><div><pre class="term log">'
al@303 466 top -n1 -b | htmlize | sed \
al@419 467 -e 's|^[A-Z].*:|<span class="color1 color31">\0</span>|g' \
al@419 468 -e 's|^\ *PID|<span class="color1 color32">\0</span>|g'
al@419 469 echo '</pre></div></section>' ;;
al@303 470
al@312 471
pascal@81 472 *\ debug\ *)
al@501 473 header; xhtml_header "$(_ 'Debug')"
al@419 474
al@419 475 cat <<EOT
al@443 476 <h2>$(_ 'HTTP Environment')</h2>
al@303 477
al@419 478 <section>
al@419 479 <div>
al@419 480 <pre>$(httpinfo | syntax_highlighter conf)</pre>
al@419 481 </div>
al@419 482 </section>
al@303 483 EOT
al@303 484 ;;
al@303 485
al@312 486
pankso@161 487 *\ report\ *)
al@501 488 header; xhtml_header "$(_ 'System report')"
al@419 489
al@501 490 [ -d '/var/cache/slitaz' ] || mkdir -p /var/cache/slitaz
al@501 491 output='/var/cache/slitaz/sys-report.html'
al@419 492
al@419 493 cat <<EOT
al@419 494 <section>
al@443 495 <header>$(_ 'Reporting to: %s' "$output")</header>
al@419 496 <table class="wide zebra">
al@419 497 <tbody>
al@443 498 <tr><td>$(_ 'Creating report header...')</td>
al@303 499 EOT
al@419 500 cat > $output <<EOT
pankso@161 501 <!DOCTYPE html>
pankso@161 502 <html xmlns="http://www.w3.org/1999/xhtml">
pankso@161 503 <head>
al@419 504 <meta charset="utf-8"/>
al@443 505 <title>$(_ 'SliTaz system report')</title>
pankso@161 506 <style type="text/css">
al@303 507 body { padding: 20px 60px; font-size: 13px; }
al@303 508 h1, h2 { color: #444; }
pankso@161 509 pre { background: #f1f1f1; border: 1px solid #ddd;
pankso@161 510 padding: 10px; border-radius: 4px; }
pascal@166 511 span.diff-rm { color: red; }
pascal@166 512 span.diff-add { color: green; }
pankso@161 513 </style>
pankso@161 514 </head>
pankso@161 515 <body>
pankso@161 516 EOT
al@419 517 cat <<EOT
al@303 518 $(ok_status_t)
al@443 519 <tr><td>$(_ 'Creating system summary...')</td>
al@303 520 EOT
al@419 521 cat >> $output <<EOT
al@443 522 <h1>$(_ 'SliTaz system report')</h1>
al@443 523 $(_ 'Date:') $(date)
pankso@161 524 <pre>
pascal@163 525 uptime : $(uptime)
pankso@161 526 cmdline : $(cat /proc/cmdline)
pankso@161 527 version : $(cat /etc/slitaz-release)
pankso@161 528 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
pankso@161 529 kernel : $(uname -r)
pankso@161 530 </pre>
pankso@161 531 EOT
al@419 532 cat <<EOT
al@303 533 $(ok_status_t)
al@443 534 <tr><td>$(_ 'Getting hardware info...')</td>
al@303 535 EOT
al@419 536 cat >> $output <<EOT
pankso@161 537 <h2>free</h2>
al@303 538 <pre>$(free)</pre>
pankso@161 539
pankso@161 540 <h2>lspci -k</h2>
al@303 541 <pre>$(lspci -k)</pre>
pankso@161 542
pankso@161 543 <h2>lsusb</h2>
al@303 544 <pre>$(lsusb)</pre>
pankso@161 545
pankso@161 546 <h2>lsmod</h2>
al@303 547 <pre>$(lsmod)</pre>
pankso@161 548
pankso@161 549 EOT
al@419 550 cat <<EOT
al@303 551 $(ok_status_t)
al@443 552 <tr><td>$(_ 'Getting networking info...')</td>
al@303 553 EOT
al@419 554 cat >> $output <<EOT
pankso@161 555 <h2>ifconfig -a</h2>
al@303 556 <pre>$(ifconfig -a)</pre>
al@303 557
pascal@163 558 <h2>route -n</h2>
al@303 559 <pre>$(route -n)</pre>
al@303 560
pascal@163 561 <h2>/etc/resolv.conf</h2>
al@303 562 <pre>$(cat /etc/resolv.conf)</pre>
pascal@163 563 EOT
al@419 564 cat <<EOT
al@303 565 $(ok_status_t)
al@443 566 <tr><td>$(_ 'Getting filesystems info...')</td>
al@303 567 EOT
al@419 568 cat >> $output <<EOT
pascal@163 569 <h2>blkid</h2>
al@303 570 <pre>$(blkid)</pre>
al@303 571
pascal@163 572 <h2>fdisk -l</h2>
al@303 573 <pre>$(fdisk -l)</pre>
al@303 574
pascal@163 575 <h2>mount</h2>
al@303 576 <pre>$(mount)</pre>
al@303 577
pascal@163 578 <h2>df -h</h2>
al@303 579 <pre>$(df -h)</pre>
al@303 580
pascal@163 581 <h2>df -i</h2>
al@303 582 <pre>$(df -i)</pre>
pascal@163 583 EOT
al@419 584 cat <<EOT
al@303 585 $(ok_status_t)
al@443 586 <tr><td>$(_ 'Getting boot logs...')</td>
al@303 587 EOT
al@419 588 cat >> $output <<EOT
al@443 589 <h2>$(_ 'Kernel messages')</h2>
al@303 590 <pre>$(cat /var/log/dmesg.log)</pre>
al@303 591
al@443 592 <h2>$(_ 'Boot scripts')</h2>
pascal@504 593 <pre>$(filter_taztools_msgs < /var/log/boot.log)</pre>
pankso@161 594 EOT
al@419 595 cat <<EOT
al@303 596 $(ok_status_t)
al@443 597 <tr><td>$(_ 'Creating report footer...')</td>
al@303 598 EOT
pascal@504 599 cat >> $output <<EOT
pankso@161 600 </body>
pankso@161 601 </html>
pankso@161 602 EOT
al@419 603 cat <<EOT
al@303 604 $(ok_status_t)
al@419 605 </tbody>
al@419 606 </table>
al@419 607 <footer>
al@443 608 <form><button name="file" value="$output" data-icon="view">$(_ 'View')</button></form>
al@419 609 </footer>
al@419 610 </section>
al@419 611
al@419 612
al@443 613 $(msg tip "$(_ 'This report can be attached with a bug report on:')
al@419 614 <a href="http://bugs.slitaz.org/" target="_blank">bugs.slitaz.org</a></p>")
al@303 615 EOT
al@303 616 ;;
al@312 617
al@312 618
pankso@2 619 *)
pankso@14 620 #
pankso@2 621 # Default xHTML content
pankso@14 622 #
al@501 623 header; xhtml_header "$(_ 'SliTaz administration and configuration Panel')"
pascal@81 624 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
pascal@81 625 [ -n "$(GET rdate)" ] && echo ""
al@303 626 hostname=$(hostname)
al@419 627
al@419 628 cat <<EOT
al@419 629 <form class="nogap"><!--
al@443 630 --><button name="terminal" data-icon="terminal">$(_ 'Terminal')</button><!--
al@443 631 --><button name="top" data-icon="proc" >$(_ 'Process activity')</button><!--
al@443 632 --><button name="report" data-icon="report" data-root>$(_ 'Create a report')</button><!--
al@437 633 --></form>
pankso@14 634
al@312 635 <section>
al@443 636 <header>$(_ 'Summary')</header>
al@419 637 <table>
al@501 638 <tr><td>$(_ 'Host:')</td><td>$hostname</td></tr>
al@443 639 <tr><td>$(_ 'Uptime:')</td>
al@419 640 <td id="uptime">$(uptime | sed 's|\([0-9.:][0-9.:]*\)|<b>\1</b>|g')</td>
al@419 641 </tr>
al@443 642 <tr><td>$(_ 'Memory in Mb:')</td>
al@419 643 <td>$(free -m | grep Mem: | \
al@419 644 awk -vline="$(gettext 'Total: %d, Used: %d, Free: %d')" \
al@419 645 '{ printf(line, $2, $3, $4) }' | \
al@419 646 sed 's|\([0-9][0-9]*\)|<b>\1</b>|g')</td>
al@419 647 </tr>
al@443 648 <tr><td>$(_ 'Linux kernel:')</td>
al@419 649 <td>$(uname -r)</td>
al@419 650 </tr>
al@419 651 </table>
al@419 652 </section>
al@419 653
al@419 654
al@419 655 <section>
al@419 656 <header>
al@443 657 $(_ 'Network status')
al@419 658 <form action="network.cgi">
al@443 659 <button data-icon="wifi">$(_ 'Network')</button>
al@419 660 </form>
al@419 661 </header>
al@419 662 $(list_network_interfaces)
al@419 663 </section>
al@419 664
al@419 665
al@419 666 <section>
al@419 667 <header>
al@443 668 $(_ 'Filesystem usage statistics')
al@419 669 <form action="hardware.cgi">
al@443 670 <button data-icon="hdd">$(_ 'Disks')</button>
al@419 671 </form>
al@419 672 </header>
al@419 673 <table class="wide zebra center">
al@303 674 EOT
al@419 675 # Disk stats (management is done as hardware.cgi)
al@419 676 df_thead
al@419 677 echo '<tbody>'
al@419 678 df -h | grep ^/dev | while read fs size used av pct mp; do
al@419 679 cat <<EOT
al@419 680 <tr>
al@419 681 <td><span data-icon="hdd">${fs#/dev/}</span></td>
al@419 682 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
al@419 683 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
al@419 684 <td>$size</td>
al@419 685 <td>$av</td>
al@419 686 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
al@419 687 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
al@419 688 <span>$used - $pct</span>
al@419 689 </td>
al@419 690 <td>$mp</td>
al@419 691 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
al@419 692 </tr>
al@303 693 EOT
al@303 694 done
al@419 695 cat <<EOT
al@419 696 </tbody>
al@419 697 </table>
al@312 698 </section>
pankso@14 699
al@312 700 <section>
al@419 701 <header>
al@443 702 $(_ 'Panel Activity')
al@419 703 <form>
al@443 704 <button name="file" value="$LOG_FILE" data-icon="view">$(_ 'View')</button>
al@419 705 </form>
al@419 706 </header>
al@419 707 <div>
al@419 708 <pre id="panel-activity">
pascal@504 709 $(tail -n 8 < $LOG_FILE | sort -r | syntax_highlighter activity)</pre>
al@419 710 </div>
al@312 711 </section>
pankso@2 712 EOT
pankso@2 713 ;;
pankso@2 714 esac
pankso@2 715
pankso@14 716 xhtml_footer
pankso@14 717 exit 0