tazpanel annotate hardware.cgi @ rev 357

header.html: add menu extensions for panel, settings, boot and hardware (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Mar 23 08:43:56 2013 +0100 (2013-03-23)
parents d0818093bbc6
children df2865290e55
rev   line source
pankso@46 1 #!/bin/sh
pankso@46 2 #
pankso@46 3 # Hardware part of TazPanel - Devices, drivers, printing
pankso@46 4 #
pankso@112 5 # Copyright (C) 2011 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@292 13 TITLE=$(gettext 'TazPanel - Hardware')
pankso@46 14
pascal@344 15 ktoh()
pascal@344 16 {
pascal@344 17 k=$1
pascal@344 18 if [ $k -lt 1024 ]; then
pascal@344 19 echo ${k}K
pascal@344 20 return
pascal@344 21 fi
pascal@344 22 k=$((($k+512)/1024))
pascal@344 23 if [ $k -lt 1024 ]; then
pascal@344 24 echo ${k}M
pascal@344 25 return
pascal@344 26 fi
pascal@344 27 k=$((($k+512)/1024))
pascal@344 28 if [ $k -lt 1024 ]; then
pascal@344 29 echo ${k}G
pascal@344 30 return
pascal@344 31 fi
pascal@344 32 k=$((($k+512)/1024))
pascal@344 33 echo ${k}T
pascal@344 34 }
pankso@46 35 #
pankso@46 36 # Commands
pankso@46 37 #
pankso@46 38
pascal@81 39 case " $(GET) " in
pascal@81 40 *\ print\ *)
al@303 41 xhtml_header
al@303 42 echo "<h2>TODO</h2>" ;;
pankso@242 43 *\ detect\ *)
pankso@242 44 # Front end for Tazhw
pankso@242 45 # TODO: Add button to detect webcam, etc. Like in tazhw box.
pankso@242 46 xhtml_header
al@303 47 cat << EOT
pankso@242 48 <div id="wrapper">
al@303 49 <h2>$(gettext 'Detect hardware')</h2>
al@303 50 <p>$(gettext 'Detect PCI and USB hardware')</p>
pankso@242 51 </div>
al@303 52
al@303 53 <pre>$(tazhw detect-pci | syntax_highlighter sh)</pre>
al@303 54
al@303 55 <pre>$(tazhw detect-usb | syntax_highlighter sh)</pre>
pankso@242 56 EOT
al@303 57 ;;
pascal@81 58 *\ modules\ *|*\ modinfo\ *)
pankso@46 59 xhtml_header
pankso@46 60 cat << EOT
pankso@46 61 <div id="wrapper">
al@303 62 <h2>$(gettext 'Kernel modules')</h2>
al@303 63 <div class="float-right">
al@303 64 <form method="get" action="$SCRIPT_NAME">
al@303 65 <input type="hidden" name="modules" />
al@303 66 <input type="search" placeholder="$(gettext 'Modules search')" name="search" />
al@303 67 </form>
al@303 68 </div>
al@303 69 <p>$(gettext 'Manage, search or get information about the Linux kernel modules')</p>
pankso@46 70 </div>
pankso@46 71 EOT
pankso@66 72 # Request may be modinfo output that we want in the page itself
al@303 73 get_modinfo="$(GET modinfo)"
al@303 74 if [ -n "$get_modinfo" ]; then
al@303 75 cat << EOT
al@303 76 <strong>$(eval_gettext 'Detailed information for module: $get_modinfo')</strong>
al@303 77
al@303 78 <pre>$(modinfo $get_modinfo)</pre>
al@303 79 EOT
pascal@81 80 fi
pascal@81 81 if [ -n "$(GET modprobe)" ]; then
al@303 82 echo "<pre>$(modprobe -v $(GET modprobe))</pre>"
pascal@81 83 fi
pascal@81 84 if [ -n "$(GET rmmod)" ]; then
pascal@81 85 echo "Removing"
pascal@81 86 rmmod -w $(GET rmmod)
pascal@81 87 fi
al@303 88 get_search="$(GET search)"
al@303 89 if [ -n "$get_search" ]; then
al@303 90 eval_gettext 'Matching result(s) for: $get_search'
pascal@81 91 echo '<pre>'
pascal@81 92 modprobe -l | grep "$(GET search)" | while read line
pascal@81 93 do
pascal@81 94 name=$(basename $line)
pascal@81 95 mod=${name%.ko.gz}
al@303 96 echo "$(gettext 'Module:') <a href='$SCRIPT_NAME?modinfo=$mod'>$mod</a>"
pascal@81 97 done
pascal@81 98 echo '</pre>'
pascal@81 99 fi
pankso@46 100 cat << EOT
al@303 101 $(table_start)
pankso@46 102 <tr class="thead">
al@303 103 <td>$(gettext 'Module')</td>
al@303 104 <td>$(gettext 'Size')</td>
al@303 105 <td>$(gettext 'Used')</td>
al@303 106 <td>$(gettext 'by')</td>
pankso@46 107 </tr>
pankso@46 108 EOT
pankso@46 109 # Get the list of modules and link to modinfo
pankso@46 110 lsmod | grep ^[a-z] | while read MOD SIZE USED BY
pankso@46 111 do
pankso@46 112 cat << EOT
pankso@46 113 <tr>
pankso@46 114 <td><a href="$SCRIPT_NAME?modinfo=$MOD">$MOD</a></td>
pankso@46 115 <td>$SIZE</td>
pankso@46 116 <td>$USED</td>
al@303 117 <td>$(echo $BY | sed s/","/" "/g)</td>
pankso@46 118 </tr>
pankso@46 119 EOT
pankso@46 120 done
pankso@66 121 table_end ;;
pankso@66 122 *)
pascal@217 123 [ -n "$(GET brightness)" ] &&
pascal@262 124 echo -n $(GET brightness) > /sys/devices/virtual/backlight/$(GET dev)/brightness
al@292 125
pankso@66 126 #
pankso@66 127 # Default to summary with mounted filesystem, loaded modules
pankso@66 128 #
pankso@66 129 xhtml_header
pankso@66 130 cat << EOT
pankso@66 131 <div id="wrapper">
al@303 132 <h2>$(gettext 'Drivers &amp; Devices')</h2>
al@303 133 <p>$(gettext 'Manage your computer hardware')</p>
pascal@219 134 </div>
pascal@219 135 <div>
pascal@219 136 <a class="button" href="$SCRIPT_NAME?modules">
al@303 137 <img src="$IMAGES/tux.png" />$(gettext 'Kernel modules')</a>
pankso@242 138 <a class="button" href="$SCRIPT_NAME?detect">
al@303 139 <img src="$IMAGES/monitor.png" />$(gettext 'Detect PCI/USB')</a>
pascal@219 140 </div>
pascal@219 141
pascal@219 142 <div id="wrapper">
pascal@217 143 EOT
pascal@219 144 if [ -n "$(ls /proc/acpi/battery/*/info 2> /dev/null)" ]; then
pascal@219 145 echo "<table>"
pascal@219 146 for dev in /proc/acpi/battery/*; do
pascal@219 147 grep ^present $dev/info | grep -q yes || continue
pascal@219 148 design=$(sed '/design capacity:/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
pascal@219 149 remain=$(sed '/remaining capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
pascal@219 150 rate=$(sed '/present rate/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
pascal@219 151 full=$(sed '/last full capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@303 152 warning=$(sed '/design capacity warning/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@303 153 low=$(sed '/design capacity low/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
al@303 154 state=$(sed '/charging state/!d;s/\([^:]*:[ ]\+\)\([a-z]\+\)/\2/' < $dev/state)
al@303 155
al@303 156 rempct=$(( $remain * 100 / $full ))
pascal@219 157 cat << EOT
pascal@219 158 <tr>
pascal@219 159 <td><img src="$IMAGES/battery.png" />
al@303 160 $(gettext 'Battery') $(grep "^battery type" $dev/info | sed 's/.*: *//')
pascal@219 161 $(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
al@303 162 <td>$(gettext 'health') $(( (100*$full)/$design))%</td>
al@303 163 <td class="meter"><meter min="0" max="$full" value="$remain" low="$low"
al@303 164 high="$warning" optimum="$full"></meter>
al@303 165 <span>
pascal@219 166 EOT
al@303 167 case "$state" in
al@303 168 "discharging")
al@303 169 remtime=$(( $remain * 60 / $rate ))
al@303 170 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
al@303 171 eval_gettext 'Discharging $rempct% - $remtimef' ;;
al@303 172 "charging")
al@303 173 remtime=$(( ($full - $remain) * 60 / $rate ))
al@303 174 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
al@303 175 eval_gettext 'Charging $rempct% - $remtimef' ;;
al@303 176 "charged")
al@303 177 gettext 'Charged 100%' ;;
al@303 178 esac
al@303 179 echo '</span></td></tr>'
pascal@219 180 done
pascal@219 181 echo "</table>"
pascal@219 182 fi
al@303 183
pascal@262 184 if [ -n "$(ls /sys/devices/virtual/thermal/*/temp 2> /dev/null)" ]; then
al@303 185 echo -n '<p>'; gettext 'Temperature:'
pascal@262 186 for temp in /sys/devices/virtual/thermal/*/temp; do
pascal@262 187 awk '{ print $1/1000 }' < $temp
pascal@219 188 done
al@303 189 echo '</p>'
pascal@219 190 fi
al@303 191
pascal@262 192 if [ -n "$(ls /sys/devices/virtual/backlight/*/brightness 2> /dev/null)" ]; then
pascal@217 193 cat <<EOT
pascal@217 194 <form method="get" action="$SCRIPT_NAME">
pascal@217 195 EOT
pascal@262 196 for dev in /sys/devices/virtual/backlight/*/brightness ; do
pascal@262 197 name=$(echo $dev | sed 's|.*/backlight/\([^/]*\).*|\1|')
pascal@217 198 cat <<EOT
pascal@217 199 <input type="hidden" name="dev" value="$name" />
al@303 200 $(gettext 'Brightness') \
pascal@263 201 $(sed 's/.*\.//;s/_*$//' < /sys/devices/virtual/backlight/$name/device/path):
pascal@263 202 <select name="brightness" onchange="submit();">
pascal@217 203 EOT
pascal@262 204 max=$(cat /sys/devices/virtual/backlight/$name/max_brightness)
pascal@262 205 for i in $(seq 0 $max); do
pascal@262 206 echo -n "<option value=\"$i\""
pascal@262 207 [ $i -eq $(cat /sys/devices/virtual/backlight/$name/actual_brightness) ] &&
pascal@262 208 echo -n " selected=\"selected\""
pascal@262 209 echo "> $(( (($i + 1) * 100) / ($max + 1) ))% </option>"
pascal@262 210 done
pascal@217 211 cat <<EOT
pascal@217 212 </select>
pascal@217 213 EOT
pascal@217 214 done
pascal@217 215 cat << EOT
pascal@217 216 </form>
pascal@217 217 EOT
pascal@217 218 fi
pascal@217 219 cat << EOT
pankso@66 220 </div>
pankso@152 221
pascal@346 222 <a name="disk">
al@303 223 <h3>$(gettext 'Filesystem usage statistics')</h3>
pankso@152 224 <pre>
pankso@66 225 EOT
pankso@152 226 fdisk -l | fgrep Disk
pankso@66 227 echo '</pre>'
al@303 228
al@303 229
pankso@153 230 #
al@303 231 # Disk stats and management (mount, umount, check)
pankso@153 232 #
pascal@344 233 device=$(GET device)
pascal@344 234 case "$device" in
pascal@344 235 *[\;\`\&\|\$]*) ;;
pascal@344 236 mount\ *)
pascal@344 237 $device $(GET mountpoint);;
pascal@344 238 umount\ *|swapon\ *|swapoff\ *)
pascal@344 239 $device ;;
pascal@344 240 esac
al@303 241 cat << EOT
pascal@344 242 <a name="mount">
pascal@344 243 <form method="get" action="$SCRIPT_NAME#mount">
al@311 244 <table class="zebra outbox">
al@303 245 EOT
pankso@153 246 df_thead
al@303 247 echo '<tbody>'
pascal@343 248 blkid | sort | while read dev misc
pankso@153 249 do
pascal@343 250 fs=${dev%:}
pascal@343 251 set --
pascal@343 252 df | grep -q "^$fs " && set -- $(df -h | grep "^$fs ")
pascal@343 253 size=$2
pascal@343 254 used=$3
pascal@343 255 av=$4
pascal@343 256 pct=$5
pascal@343 257 mp=$6
pascal@344 258 action="mount"
pascal@344 259 [ -n "$mp" ] && action="umount"
pascal@344 260 type=$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')
pascal@344 261 [ "$type" == "swap" ] && action="swapon"
pascal@344 262 if grep -q "^$fs " /proc/swaps; then
pascal@344 263 action="swapoff"
pascal@344 264 set -- $(grep "^$fs " /proc/swaps)
pascal@344 265 size=$(ktoh $3)
pascal@344 266 used=$(ktoh $4)
pascal@344 267 av=$(ktoh $(($3-$4)))
pascal@344 268 pct=$(((100*$4)/$3))%
pascal@344 269 mp=swap
pascal@344 270 fi
pascal@343 271 cat << EOT
pankso@153 272 <tr>
pascal@344 273 <td><input type="radio" name="device" value="$action $fs" />
pascal@344 274 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
pascal@343 275 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
pascal@344 276 <td>$type</td>
pankso@153 277 <td>$size</td>
pankso@153 278 <td>$av</td>
pascal@343 279 EOT
pascal@343 280 if [ -n "$pct" ]; then
pascal@343 281 cat << EOT
al@303 282 <td class="meter"><meter min="0" max="100" value="${pct%%%}" low="70"
al@303 283 high="90" optimum="10"></meter>
al@303 284 <span>$used - $pct</span>
al@303 285 </td>
pascal@343 286 EOT
pascal@343 287 else
pascal@343 288 cat << EOT
pascal@343 289 <td></td>
pascal@343 290 EOT
pascal@343 291 fi
pascal@343 292 cat << EOT
pankso@153 293 <td>$mp</td>
pascal@344 294 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
pankso@153 295 </tr>
pankso@153 296 EOT
pankso@153 297 done
al@303 298 cat << EOT
al@303 299 </tbody>
al@303 300 </table>
pascal@344 301 <input type="submit" value="mount / umount" /> -
pascal@344 302 new mount point <input type=text" name="mountpoint" value="/media/usbdisk" />
pascal@344 303 </form>
pascal@345 304 <h3>$(gettext 'Filesystems table')</h3>
pascal@345 305 <pre>
pascal@345 306 $(grep -v ^# /etc/fstab | syntax_highlighter conf)
pascal@345 307 </pre>
pascal@345 308 <a class="button" href="index.cgi?file=/etc/fstab&action=edit">
pascal@345 309 <img src="$IMAGES/edit.png" />$(gettext 'Manual Edit')</a>
al@303 310 EOT
al@303 311
al@303 312
al@303 313 cat << EOT
al@303 314 <h3>$(gettext 'System memory')</h3>
al@303 315 <pre>
al@303 316 EOT
pascal@219 317 free -m | sed \
pankso@152 318 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
pankso@152 319 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
al@303 320 cat << EOT
al@303 321 </pre>
al@303 322
al@303 323 <h3>lspci</h3>
al@303 324 <pre>
al@303 325 EOT
pascal@155 326 lspci -k | sed \
pascal@155 327 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
pascal@155 328 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
al@303 329 cat << EOT
al@303 330 </pre>
al@303 331
al@303 332 <h3>lsusb</h3>
al@303 333 <pre>$(lsusb)</pre>
al@303 334 EOT
pankso@46 335 ;;
pankso@46 336 esac
pankso@46 337
pankso@46 338 xhtml_footer
pankso@46 339 exit 0