tazpanel annotate hardware.cgi @ rev 502

Update zh_CN.po (thanks Zhangwenyu)
author Paul Issott <paul@slitaz.org>
date Sat Jul 11 13:51:39 2015 +0100 (2015-07-11)
parents 5f5f6496a115
children c0997cc494ed
rev   line source
pankso@46 1 #!/bin/sh
pankso@46 2 #
pankso@46 3 # Hardware part of TazPanel - Devices, drivers, printing
pankso@46 4 #
al@419 5 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
pankso@46 6 #
pankso@46 7
pankso@46 8 # Common functions from libtazpanel
pankso@46 9 . lib/libtazpanel
pankso@46 10 get_config
pascal@81 11 header
pankso@46 12
al@501 13 TITLE=$(_ 'Hardware')
pankso@46 14
paul@385 15 # Call an optional module
al@426 16 lib() {
pascal@373 17 module=lib/$1
pascal@373 18 shift
pascal@373 19 [ -s $module ] && . $module "$@"
pascal@373 20 }
pascal@373 21
pascal@431 22 disk_info() {
pascal@431 23 fdisk -l | fgrep Disk | while read a b c; do
pascal@431 24 d=${b#/dev/}
pascal@431 25 d="/sys/block/${d%:}/device"
pascal@431 26 [ -d $d ] && echo "$a $b $c, $(cat $d/vendor) $(cat $d/model)"
pascal@431 27 done 2> /dev/null | sed 's/ */ /g'
pascal@431 28 }
al@419 29
pascal@473 30 lsusb_vd() {
pascal@473 31 if lsusb --help 2>&1 | grep -qi busybox ; then
pascal@473 32 for i in /sys/class/usb_device/*/device ; do
pascal@473 33 grep -qs ${1%:*} $i/idVendor || continue
pascal@473 34 grep -qs ${1#*:} $i/idProduct || continue
pascal@473 35 ( cd $i ; for j in * ; do
pascal@473 36 [ -f $j -a -r $j ] || continue
pascal@473 37 case "$j" in
pascal@473 38 descriptors|remove) continue
pascal@473 39 esac
pascal@473 40 printf "%-20s %s\n" $j "$(xargs echo < $j)"
pascal@473 41 done )
pascal@473 42 break
pascal@473 43 done
pascal@473 44 else
pascal@473 45 lsusb -vd $1 | syntax_highlighter lsusb
pascal@473 46 fi
pascal@473 47 }
pascal@473 48
al@426 49 lsusb_table() {
al@419 50 cat <<EOT
al@419 51 <table class="wide zebra">
al@426 52 <thead>
al@426 53 <tr>
al@443 54 <td>$(_ 'Bus')</td>
al@443 55 <td>$(_ 'Device')</td>
al@443 56 <td>$(_ 'ID')</td>
al@443 57 <td>$(_ 'Name')</td>
al@426 58 </tr>
al@426 59 </thead>
al@363 60 <tbody>
al@363 61 EOT
pascal@473 62 lsusb | while read x b y d z id name ; do
pascal@473 63 echo "<tr><td>$b</td><td>${d%:}</td><td><a href=\"?lsusb=$id"
pascal@473 64 p=$(printf "class/usb_device/usbdev%d.%d" $b ${d%:})
pascal@473 65 grep -qs 0 /sys/$p/device/authorized && id="<del>$id</del>"
pascal@473 66 echo "\">$id</td><td>$name</td></tr>"
pascal@473 67 done
al@363 68 echo "</tbody></table>"
al@363 69 }
al@363 70
al@419 71
al@426 72 lspci_table() {
al@419 73 cat <<EOT
al@419 74 <table class="wide zebra">
al@363 75 <thead><tr><td>Slot</td><td>Device</td><td>Name</td></thead>
al@363 76 <tbody>
al@363 77 EOT
al@363 78 lspci | sed 's| |</td><td>|;
al@363 79 s|: |</td><td>|;
al@363 80 s|^\([^<]*\)|<a href="?lspci=\1">\1</a>|;
al@363 81 s|^.*$|<tr><td>\0</td></tr>|'
al@363 82 echo "</tbody></table>"
al@363 83 }
al@363 84
al@426 85
pankso@46 86 #
pankso@46 87 # Commands
pankso@46 88 #
pankso@46 89
pascal@81 90 case " $(GET) " in
pascal@81 91 *\ print\ *)
al@303 92 xhtml_header
al@419 93 echo "<h2>TODO</h2>"
al@419 94 ;;
al@419 95
al@419 96
psychomaniak@407 97 *\ tazx\ *)
psychomaniak@407 98 xhtml_header
al@419 99 cat <<EOT
psychomaniak@407 100 <pre>$(tazx auto)</pre>
psychomaniak@407 101 EOT
psychomaniak@407 102 ;;
al@419 103
al@419 104
pankso@242 105 *\ detect\ *)
pankso@242 106 # Front end for Tazhw
pankso@242 107 # TODO: Add button to detect webcam, etc. Like in tazhw box.
al@501 108 xhtml_header "$(_ 'Detect hardware')"
al@419 109 cat <<EOT
al@443 110 <p>$(_ 'Detect PCI and USB hardware')</p>
pankso@242 111 EOT
al@501 112 tazhw detect-pci | sed 's|^>|\&gt;|g'
al@501 113 tazhw detect-usb | sed 's|^>|\&gt;|g'
al@303 114 ;;
al@419 115
al@419 116
pascal@81 117 *\ modules\ *|*\ modinfo\ *)
al@501 118 xhtml_header "$(_ 'Kernel modules')"
al@501 119
al@501 120 search="$(GET search)"
al@419 121 cat <<EOT
al@443 122 <p>$(_ 'Manage, search or get information about the Linux kernel modules')</p>
al@419 123
al@501 124 <form class="search">
al@419 125 <input type="hidden" name="modules"/>
al@501 126 <input type="search" name="search" value="$search" placeholder="$(_ 'Modules search')" results="5" autosave="modsearch" autocomplete="on"/>
al@501 127 <button type="submit">$(_n 'Search')</button>
al@419 128 </form>
pankso@46 129 EOT
pankso@66 130 # Request may be modinfo output that we want in the page itself
al@303 131 get_modinfo="$(GET modinfo)"
al@303 132 if [ -n "$get_modinfo" ]; then
al@419 133 cat <<EOT
al@419 134 <section>
al@443 135 <header>$(_ 'Detailed information for module: %s' $get_modinfo)</header>
al@501 136 <div class="scroll">
al@303 137
al@303 138 EOT
al@419 139 modinfo $get_modinfo | awk 'BEGIN{print "<table class=\"wide zebra\">"}
al@419 140 {
al@419 141 printf("<tr><td><b>%s</b></td>", $1)
al@419 142 $1=""; printf("<td>%s</td></tr>", $0)
al@419 143 }
al@501 144 END{print "</table></div></section>"}'
pascal@81 145 fi
al@419 146
pascal@81 147 if [ -n "$(GET modprobe)" ]; then
al@303 148 echo "<pre>$(modprobe -v $(GET modprobe))</pre>"
pascal@81 149 fi
pascal@81 150 if [ -n "$(GET rmmod)" ]; then
pascal@81 151 echo "Removing"
pascal@81 152 rmmod -w $(GET rmmod)
pascal@81 153 fi
al@501 154
al@501 155 # Module search
al@501 156 if [ -n "$search" ]; then
al@501 157 cat <<EOT
al@501 158 <section>
al@501 159 <header>$(_ 'Matching result(s) for: %s' $search)</header>
al@501 160 <pre class="scroll">
al@501 161 EOT
al@501 162 busybox modprobe -l | grep "$search" | while read line
pascal@81 163 do
pascal@81 164 name=$(basename $line)
al@501 165 mod=${name%.ko.xz}
al@501 166 echo "<span data-icon=\"modules\">$(_ 'Module:')</span> <a href='?modinfo=$mod'>$mod</a>"
pascal@81 167 done
al@501 168 echo '</pre></section>'
pascal@81 169 fi
al@501 170
al@419 171 cat <<EOT
al@419 172 <section>
al@426 173 <table class="zebra">
al@419 174 <thead>
al@419 175 <tr>
al@443 176 <td>$(_ 'Module')</td>
al@443 177 <td>$(_ 'Description')</td>
al@443 178 <td>$(_ 'Size')</td>
al@443 179 <td>$(_ 'Used')</td>
al@443 180 <td>$(_ 'by')</td>
al@419 181 </tr>
al@419 182 <thead>
al@419 183 <tbody>
pankso@46 184 EOT
pankso@46 185 # Get the list of modules and link to modinfo
al@419 186 lsmod | tail -n+2 | awk '{
al@419 187 gsub(",", " ", $4);
al@419 188 printf("<tr><td><a href=\"?modinfo=%s\">%s</a></td><td>", $1, $1);
al@419 189 system("modinfo -d " $1);
al@419 190 printf("</td><td>%s</td><td>%s</td><td>%s</td></tr>", $2, $3, $4);
al@419 191 }'
al@419 192 cat <<EOT
al@419 193 </thead>
al@419 194 </table>
al@419 195 </section>
pankso@46 196 EOT
al@419 197 ;;
al@419 198
al@419 199
al@363 200 *\ lsusb\ *)
al@363 201 xhtml_header
al@363 202 vidpid="$(GET lsusb)"
al@419 203 cat <<EOT
al@443 204 <h2>$(_ 'Information for USB Device %s' $vidpid)</h2>
al@419 205
al@443 206 <p>$(_ 'Detailed information about specified device.')</p>
al@419 207
al@419 208 <section>$(lsusb_table)</section>
al@426 209 EOT
al@426 210 [ "$vidpid" != 'lsusb' ] && cat <<EOT
al@419 211 <section>
pascal@473 212 <pre style="white-space: pre-wrap">$(lsusb_vd $vidpid)</pre>
al@419 213 </section>
al@363 214 EOT
al@363 215 ;;
al@419 216
al@419 217
al@363 218 *\ lspci\ *)
al@363 219 xhtml_header
al@363 220 slot="$(GET lspci)"
al@419 221 cat <<EOT
al@443 222 <h2>$(_ 'Information for PCI Device %s' $slot)</h2>
al@419 223
al@443 224 <p>$(_ 'Detailed information about specified device.')</p>
al@419 225
al@419 226 <section>$(lspci_table)</section>
al@426 227 EOT
al@426 228 [ "$slot" != 'lspci' ] && cat <<EOT
al@419 229 <section>
al@426 230 <pre style="white-space: pre-wrap">$(lspci -vs $slot | syntax_highlighter lspci)</pre>
al@419 231 </section>
al@363 232 EOT
al@363 233 ;;
al@419 234
al@419 235
pankso@66 236 *)
pascal@217 237 [ -n "$(GET brightness)" ] &&
al@426 238 echo -n $(GET brightness) > /sys/devices/virtual/backlight/$(GET dev)/brightness
al@292 239
pankso@66 240 #
pankso@66 241 # Default to summary with mounted filesystem, loaded modules
pankso@66 242 #
al@501 243 xhtml_header "$(_ 'Drivers &amp; Devices')"
al@419 244 cat <<EOT
al@443 245 <p>$(_ 'Manage your computer hardware')</p>
al@419 246
al@419 247 <form><!--
al@443 248 --><button name="modules" data-icon="modules">$(_ 'Kernel modules')</button><!--
al@443 249 --><button name="detect" data-icon="detect" data-root>$(_ 'Detect PCI/USB')</button><!--
al@443 250 --><button name="tazx" data-icon="tazx" data-root>$(_ 'Auto-install Xorg video driver')</button><!--
al@437 251 --></form>
pascal@219 252
pascal@217 253 EOT
al@419 254
al@419 255
al@419 256 # Battery state
al@419 257 if [ -n "$(ls /proc/acpi/battery/*/info 2>/dev/null)" ]; then
al@419 258 cat <<EOT
al@419 259 <section>
al@443 260 <header>$(_ 'Battery')</header>
al@419 261 <div>
al@419 262 <table class="wide">
al@419 263 EOT
pascal@219 264 for dev in /proc/acpi/battery/*; do
pascal@219 265 grep ^present $dev/info | grep -q yes || continue
al@419 266 design=$(sed '/design capacity:/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@419 267 remain=$(sed '/remaining capacity/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
al@419 268 rate=$(sed '/present rate/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
al@419 269 full=$(sed '/last full capacity/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@303 270 warning=$(sed '/design capacity warning/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@419 271 low=$(sed '/design capacity low/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@419 272 state=$(sed '/charging state/!d; s/\([^:]*:[ ]\+\)\([a-z]\+\)/\2/' < $dev/state)
al@303 273
al@303 274 rempct=$(( $remain * 100 / $full ))
al@419 275 cat <<EOT
al@419 276 <tr>
al@443 277 <td><span data-icon="battery">$(_ 'Battery')</span>
al@419 278 $(grep "^battery type" $dev/info | sed 's/.*: *//')
al@419 279 $(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
al@443 280 <td>$(_ 'health') $(( (100*$full)/$design))%</td>
al@419 281 <td class="meter"><meter min="0" max="$full" value="$remain" low="$low"
al@419 282 high="$warning" optimum="$full"></meter>
al@419 283 <span>
pascal@219 284 EOT
al@303 285 case "$state" in
al@303 286 "discharging")
al@303 287 remtime=$(( $remain * 60 / $rate ))
al@303 288 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
al@443 289 _ 'Discharging %d%% - %s' $rempct $remtimef ;;
al@303 290 "charging")
al@303 291 remtime=$(( ($full - $remain) * 60 / $rate ))
al@303 292 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
pascal@468 293 _ 'Charging %d%% - %s' $rempct $remtimef ;;
al@303 294 "charged")
pascal@469 295 _ 'Charged 100%%' ;;
al@303 296 esac
al@419 297 cat <<EOT
al@419 298
al@419 299 </span>
al@419 300 </td>
al@419 301 </tr>
al@419 302 EOT
pascal@219 303 done
al@419 304 cat <<EOT
al@419 305 </table>
al@419 306 </div>
al@419 307 </section>
al@419 308 EOT
pascal@219 309 fi
al@303 310
al@419 311
al@419 312 # Thermal sensors
al@419 313 if [ -n "$(ls /sys/devices/virtual/thermal/*/temp 2>/dev/null)" ]; then
al@443 314 echo "<p><span data-icon=\"temperature\">$(_ 'Temperature:')</span>"
pascal@262 315 for temp in /sys/devices/virtual/thermal/*/temp; do
al@419 316 awk '{ print $1/1000 "℃" }' < $temp
pascal@219 317 done
al@303 318 echo '</p>'
pascal@219 319 fi
al@303 320
al@419 321
al@419 322 # Brightness
al@419 323 if [ -n "$(ls /sys/devices/virtual/backlight/*/brightness 2>/dev/null)" ]; then
al@419 324 echo '<form>'
al@419 325 for dev in /sys/devices/virtual/backlight/*/brightness; do
pascal@262 326 name=$(echo $dev | sed 's|.*/backlight/\([^/]*\).*|\1|')
pascal@217 327 cat <<EOT
al@419 328 <input type="hidden" name="dev" value="$name"/>
al@443 329 <span data-icon="brightness">$(_ 'Brightness')</span> \
pascal@263 330 $(sed 's/.*\.//;s/_*$//' < /sys/devices/virtual/backlight/$name/device/path):
al@419 331 <select name="brightness" onchange="submit();">
pascal@217 332 EOT
pascal@262 333 max=$(cat /sys/devices/virtual/backlight/$name/max_brightness)
pascal@262 334 for i in $(seq 0 $max); do
pascal@262 335 echo -n "<option value=\"$i\""
pascal@262 336 [ $i -eq $(cat /sys/devices/virtual/backlight/$name/actual_brightness) ] &&
pascal@262 337 echo -n " selected=\"selected\""
pascal@262 338 echo "> $(( (($i + 1) * 100) / ($max + 1) ))% </option>"
pascal@262 339 done
al@419 340 echo '</select>'
pascal@217 341 done
al@419 342 echo '</form>'
pascal@217 343 fi
pankso@152 344
al@363 345
al@419 346 cat <<EOT
al@419 347 <section>
al@419 348 <form action="#mount" class="wide">
al@443 349 <header id="disk">$(_ 'Filesystem usage statistics')</header>
al@419 350 <div>
pascal@431 351 <pre>$(disk_info)</pre>
al@419 352 </div>
pankso@66 353 EOT
al@303 354
al@303 355
pankso@153 356 #
pascal@376 357 # Loop device management actions
pascal@376 358 #
pascal@376 359 device=$(GET loopdev)
pascal@376 360 lib crypto $device
pascal@376 361 case "$device" in
pascal@425 362 /dev/*loop*)
pascal@376 363 set -- $(losetup | grep ^$device:)
pascal@376 364 [ -n "$3" ] && losetup -d $device
pascal@376 365 ro=""
pascal@376 366 [ -n "$(GET readonly)" ] && ro="-r"
pascal@376 367 file="$(GET backingfile)"
pascal@376 368 [ -n "$file" ] && losetup -o $(GET offset) $ro $device $file
pascal@376 369 esac
al@419 370
al@419 371
pascal@376 372 #
al@303 373 # Disk stats and management (mount, umount, check)
pankso@153 374 #
pascal@344 375 device=$(GET device)
pascal@373 376 lib crypto $device
pascal@344 377 case "$device" in
pascal@344 378 *[\;\`\&\|\$]*) ;;
pascal@344 379 mount\ *)
pascal@375 380 ro=""
pascal@375 381 [ -n "$(GET readonly)" ] && ro="-r"
pascal@389 382 mntdir="$(GET mountpoint)"
pascal@389 383 [ -d "$mntdir" ] || mkdir -p "$mntdir"
pascal@389 384 $device $ro "$mntdir";;
pascal@344 385 umount\ *|swapon\ *|swapoff\ *)
pascal@344 386 $device ;;
pascal@344 387 esac
al@419 388 cat <<EOT
al@419 389 <table id="mount" class="zebra wide center">
al@303 390 EOT
pankso@153 391 df_thead
al@303 392 echo '<tbody>'
al@426 393 for fs in $(blkid | sort | sed 's/:.*//'); do
pascal@373 394 set -- $(df -h | grep "^$fs ")
pascal@343 395 size=$2
pascal@343 396 used=$3
pascal@343 397 av=$4
pascal@375 398 grep "^$fs " /proc/mounts | grep -q "[, ]ro[, ]" &&
pascal@375 399 av="<del>$av</del>"
pascal@343 400 pct=$5
pascal@343 401 mp=$6
al@419 402
al@419 403 # action
pascal@344 404 action="mount"
pascal@344 405 [ -n "$mp" ] && action="umount"
pascal@431 406 type=$(blkid $fs | sed '/TYPE=/!d;s/.* TYPE="\([^"]*\).*/\1/')
pascal@344 407 [ "$type" == "swap" ] && action="swapon"
pascal@344 408 if grep -q "^$fs " /proc/swaps; then
pascal@344 409 action="swapoff"
pascal@344 410 set -- $(grep "^$fs " /proc/swaps)
pascal@364 411 size=$(blk2h $(($3*2)))
pascal@364 412 used=$(blk2h $(($4*2)))
pascal@364 413 av=$(blk2h $((2*($3-$4))))
pascal@344 414 pct=$(((100*$4)/$3))%
pascal@344 415 mp=swap
pascal@344 416 fi
al@419 417
al@419 418 # size
pascal@364 419 [ -z "$size" ] &&
pascal@364 420 size="$(blk2h $(cat /sys/block/${fs#/dev/}/size /sys/block/*/${fs#/dev/}/size))"
al@419 421
al@419 422 # image
al@419 423 disktype="hdd"
al@419 424 case "$(cat /sys/block/${fs#/dev/}/removable 2>/dev/null ||
al@419 425 cat /sys/block/${fs:5:3}/removable 2>/dev/null)" in
al@419 426 1) disktype="removable" ;;
pascal@373 427 esac
al@419 428 case "$(cat /sys/block/${fs#/dev/}/ro 2>/dev/null ||
al@419 429 cat /sys/block/${fs:5:3}/ro 2>/dev/null)" in
al@419 430 1) disktype="cd" ;;
pascal@373 431 esac
al@419 432
pascal@473 433 radio="<input type=\"radio\" name=\"device\" value=\"$action $fs\" id=\"${fs#/dev/}\"/>"
pascal@473 434 [ "$REMOTE_USER" == "root" ] || radio=""
al@419 435 cat <<EOT
al@419 436 <tr>
pascal@473 437 <td>$radio<!--
al@419 438 --><label for="${fs#/dev/}" data-icon="$disktype">&thinsp;${fs#/dev/}</label></td>
al@419 439 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
al@419 440 <td>$type</td>
al@419 441 <td>$size</td>
al@419 442 <td>$av</td>
pascal@343 443 EOT
pascal@343 444 if [ -n "$pct" ]; then
al@419 445 cat <<EOT
al@419 446 <td class="meter"><meter min="0" max="100" value="${pct%%%}" low="70"
al@419 447 high="90" optimum="10"></meter>
al@419 448 <span>$used - $pct</span>
al@419 449 </td>
pascal@343 450 EOT
pascal@343 451 else
al@419 452 cat <<EOT
al@419 453 <td> </td>
pascal@343 454 EOT
pascal@343 455 fi
al@419 456 cat <<EOT
al@419 457 <td>$mp</td>
al@419 458 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
al@419 459 </tr>
pankso@153 460 EOT
pankso@153 461 done
al@419 462 cat <<EOT
al@419 463 </tbody>
al@419 464 </table>
pascal@433 465 EOT
pascal@433 466 [ "$REMOTE_USER" == "root" ] && cat <<EOT
al@419 467 $(lib crypto input)
al@363 468
al@419 469 <footer>
al@419 470 <button type="submit">mount / umount</button> -
al@443 471 $(_ 'new mount point:') <input type="text" name="mountpoint" value="/media/usbdisk"/> -
al@443 472 <input type="checkbox" name="readonly" id="ro"><label for="ro">&thinsp;$(_ 'read-only')</label>
al@419 473 </footer>
pascal@433 474 EOT
pascal@433 475 cat <<EOT
al@419 476 </form>
al@419 477 </section>
al@363 478 EOT
al@363 479
al@419 480
al@419 481 #
al@419 482 # /etc/fstab
al@419 483 #
al@419 484 cat <<EOT
al@419 485 <section>
al@426 486 <header>
al@443 487 $(_ 'Filesystems table')
pascal@436 488 EOT
pascal@436 489 [ -w /etc/fstab ] && cat <<EOT
al@426 490 <form action="index.cgi">
al@426 491 <input type="hidden" name="file" value="/etc/fstab"/>
al@443 492 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
al@426 493 </form>
pascal@436 494 EOT
pascal@436 495 cat <<EOT
al@426 496 </header>
al@419 497 <table class="wide zebra center">
al@419 498 <thead>
al@419 499 <tr>
al@443 500 <td>$(_ 'Disk')</td>
al@443 501 <td>$(_ 'Mount point')</td>
al@443 502 <td>$(_ 'Type')</td>
al@443 503 <td>$(_ 'Options')</td>
al@443 504 <td>$(_ 'Freq')</td>
al@443 505 <td>$(_ 'Pass')</td>
al@419 506 </tr>
al@419 507 </thead>
al@419 508 <tbody>
al@419 509 EOT
al@419 510
al@419 511 grep -v '^#' /etc/fstab | awk '{
al@419 512 print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4
al@419 513 print "</td><td>" $5 "</td><td>" $6 "</td></tr>"
al@419 514 }
al@363 515 END{print "</tbody></table>"}'
al@363 516
al@419 517 cat <<EOT
al@419 518 </section>
al@419 519 EOT
al@363 520
al@363 521
al@419 522 #
al@419 523 # Loop device management GUI
al@419 524 #
al@419 525 cat <<EOT
al@419 526 <section>
al@443 527 <header>$(_ 'Loop devices')</header>
al@419 528
al@419 529 <form action="#loop" class="wide">
pascal@429 530 <div class="scroll">
pascal@429 531 <table id="loop" class="wide zebra scroll">
al@419 532 <thead>
al@419 533 <tr>
al@443 534 <td>$(_ 'Device')</td>
al@443 535 <td>$(_ 'Backing file')</td>
pascal@497 536 <td>$(_ 'Size')</td>
al@443 537 <td>$(_ 'Access')</td>
al@443 538 <td>$(_ 'Offset')</td>
al@419 539 </tr>
al@419 540 </thead>
al@419 541 <tbody>
pascal@373 542 EOT
pascal@425 543 for devloop in $(ls /dev/*loop[0-9]*); do
al@419 544 loop="${devloop#/dev/}"
pascal@497 545 dir=/sys/block/$loop
pascal@497 546 case "$(cat $dir/ro 2>/dev/null)" in
al@443 547 0) ro="$(_ "read/write")" ;;
al@443 548 1) ro="$(_ "read only")" ;;
pascal@373 549 *) ro="" ;;
pascal@373 550 esac
pascal@497 551 size=$(blk2h $(cat $dir/size))
pascal@497 552 [ "$size" == "0.0K" ] && size="" && ro=""
pascal@497 553 set -- $(losetup $devloop)
pascal@497 554 set -- "${3:-$(cat $dir/loop/backing_file)}" "${2:-$(cat $dir/loop/offset)}" ${ro// /&nbsp;}
al@419 555 cat <<EOT
al@419 556 <tr><td><input type="radio" name="loopdev" value="$devloop" id="$loop"/><!--
al@419 557 --><label for="$loop" data-icon="loopback">$loop</label></td>
pascal@497 558 <td>$1</td><td>$size</td><td align="center">$3</td><td align="right">$2</td>
al@419 559 </tr>
pascal@373 560 EOT
pascal@373 561 done
al@419 562 cat <<EOT
al@419 563 </tbody>
al@419 564 </table>
pascal@429 565 </div>
al@419 566
pascal@373 567 $(lib crypto input)
al@419 568
al@419 569 <footer>
al@443 570 <button type="submit" data-icon="ok">$(_ 'Setup')</button> -
al@443 571 $(_ 'new backing file:') <input type="text" name="backingfile"/> -
al@443 572 $(_ 'offset in bytes:') <input type="text" name="offset" value="0" size="8"/> -
al@443 573 <input type="checkbox" name="readonly" id="ro"/><label for="ro">$(_ 'read only')</label>
al@419 574 </footer>
al@419 575 </form>
al@419 576 </section>
pascal@373 577 EOT
pascal@373 578
al@419 579
al@419 580 #
al@419 581 # System memory
al@419 582 #
al@419 583 mem_total=$(free -m | awk '$1 ~ "M" {print $2}')
al@419 584 mem_used=$((100 * $(free -m | awk '$1 ~ "+" {print $3}') / mem_total))
al@419 585 mem_buff=$((100 * $(free -m | awk '$1 ~ "M" {print $6}') / mem_total))
al@419 586 mem_free=$((100 - mem_used - mem_buff))
al@419 587
al@419 588 cat <<EOT
al@419 589 <section>
al@443 590 <header>$(_ 'System memory')</header>
al@419 591
al@419 592 <div class="sysmem"><!--
al@443 593 --><span class="sysmem_used" style="width: ${mem_used}%" title="$(_ 'Used')" ><span>${mem_used}%</span></span><!--
al@419 594 EOT
al@419 595 [ $mem_buff != 0 ] && cat <<EOT
al@443 596 --><span class="sysmem_buff" style="width: ${mem_buff}%" title="$(_ 'Buffers')"><span>${mem_buff}%</span></span><!--
al@419 597 EOT
al@419 598 cat <<EOT
al@443 599 --><span class="sysmem_free" style="width: ${mem_free}%" title="$(_ 'Free')" ><span>${mem_free}%</span></span><!--
al@419 600 --></div>
al@419 601
al@419 602 <table class="wide zebra center">
al@419 603 <thead>
al@419 604 <tr>
al@419 605 <td>&nbsp;</td>
al@419 606 <td>total</td>
al@419 607 <td>used</td>
al@419 608 <td>free</td>
al@419 609 <td>shared</td>
al@419 610 <td>buffers</td>
al@419 611 </tr>
al@419 612 </thead>
al@419 613 <tbody>
al@303 614 EOT
al@303 615
al@419 616 free -m | awk '
al@419 617 $1 ~ "M" {print "<tr><td>"$1"</td><td>"$2"</td><td>"$3"</td><td>"$4"</td><td>"$5"</td><td>"$6"</td></tr>"}
al@419 618 $1 ~ "+" {print "<tr><td>"$1 $2"</td><td></td><td>"$3"</td><td>"$4"</td><td></td><td></td></tr>"}
al@419 619 $1 ~ "S" {print "<tr><td>"$1"</td><td>"$2"</td><td>"$3"</td><td>"$4"</td><td></td><td></td></tr>"}'
al@303 620
al@419 621 cat <<EOT
al@419 622 </tbody>
al@419 623 </table>
al@419 624 </section>
al@419 625 EOT
al@303 626
al@419 627
al@419 628 #
al@419 629 # lspci and lsusb summary tables
al@419 630 #
al@419 631 cat <<EOT
al@419 632 <section>
al@419 633 <header>lspci</header>
al@419 634 $(lspci_table)
al@419 635 </section>
al@419 636
al@419 637
al@419 638 <section>
al@419 639 <header>lsusb</header>
al@419 640 $(lsusb_table)
al@419 641 </section>
al@303 642 EOT
al@419 643 ;;
pankso@46 644 esac
pankso@46 645
pankso@46 646 xhtml_footer
pankso@46 647 exit 0