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