tazpanel view hardware.cgi @ rev 288

live: make live usb into tazpanle, new input and button style
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 02 11:22:06 2012 +0200 (2012-04-02)
parents 8eb0c310c78c
children 72e9955ebdff
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="- Hardware"
15 #
16 # Commands
17 #
19 case " $(GET) " in
20 *\ print\ *)
21 echo "TODO" ;;
22 *\ detect\ *)
23 # Front end for Tazhw
24 # TODO: Add button to detect webcam, etc. Like in tazhw box.
25 xhtml_header
26 cat << EOT
27 <div id="wrapper">
28 <h2>$(gettext "Detect hardware")</h2>
29 <p>$(gettext "Detect PCI and USB hardware")</p>
30 </div>
31 EOT
32 echo '<pre>'
33 tazhw detect-pci
34 echo '</pre>'
35 echo '<pre>'
36 tazhw detect-usb
37 echo '</pre>' ;;
38 *\ modules\ *|*\ modinfo\ *)
39 xhtml_header
40 cat << EOT
41 <div id="wrapper">
42 <h2>`gettext "Kernel modules"`</h2>
43 <div class="float-right">
44 <form method="get" action="$SCRIPT_NAME">
45 <input type="hidden" name="modules" />
46 <input type="text" name="search" />
47 </form>
48 </div>
49 <p>$(gettext "Manage, search or get information about the Linux kernel modules")</p>
50 </div>
51 EOT
52 # Request may be modinfo output that we want in the page itself
53 if [ -n "$(GET modinfo)" ]; then
54 echo '<strong>'
55 gettext "Detailed information for module: "; echo "$(GET modinfo)"
56 echo '</strong>'
57 echo '<pre>'
58 modinfo $(GET modinfo)
59 echo '</pre>'
60 fi
61 if [ -n "$(GET modprobe)" ]; then
62 echo '<pre>'
63 modprobe -v $(GET modprobe)
64 echo '</pre>'
65 fi
66 if [ -n "$(GET rmmod)" ]; then
67 echo "Removing"
68 rmmod -w $(GET rmmod)
69 fi
70 if [ -n "$(GET search)" ]; then
71 gettext "Matching result(s) for: "; echo "$(GET search)"
72 echo '<pre>'
73 modprobe -l | grep "$(GET search)" | while read line
74 do
75 name=$(basename $line)
76 mod=${name%.ko.gz}
77 echo "Module : <a href='$SCRIPT_NAME?modinfo=$mod'>$mod</a> "
78 done
79 echo '</pre>'
80 fi
81 cat << EOT
82 `table_start`
83 <tr class="thead">
84 <td>`gettext "Module"`</td>
85 <td>`gettext "Size"`</td>
86 <td>`gettext "Used"`</td>
87 <td>`gettext "by"`</td>
88 </tr>
89 EOT
90 # Get the list of modules and link to modinfo
91 lsmod | grep ^[a-z] | while read MOD SIZE USED BY
92 do
93 cat << EOT
94 <tr>
95 <td><a href="$SCRIPT_NAME?modinfo=$MOD">$MOD</a></td>
96 <td>$SIZE</td>
97 <td>$USED</td>
98 <td>`echo $BY | sed s/","/" "/g`</td>
99 </tr>
100 EOT
101 done
102 table_end ;;
103 *)
104 [ -n "$(GET brightness)" ] &&
105 echo -n $(GET brightness) > /sys/devices/virtual/backlight/$(GET dev)/brightness
107 #
108 # Default to summary with mounted filesystem, loaded modules
109 #
110 xhtml_header
111 cat << EOT
112 <div id="wrapper">
113 <h2>`gettext "Drivers &amp; Devices"`</h2>
114 <p>`gettext "Manage your computer hardware`</p>
115 </div>
116 <div>
117 <a class="button" href="$SCRIPT_NAME?modules">
118 <img src="$IMAGES/tux.png" />Kernel modules</a>
119 <a class="button" href="$SCRIPT_NAME?detect">
120 <img src="$IMAGES/monitor.png" />Detect PCI/USB</a>
121 </div>
123 <div id="wrapper">
124 EOT
125 if [ -n "$(ls /proc/acpi/battery/*/info 2> /dev/null)" ]; then
126 echo "<table>"
127 for dev in /proc/acpi/battery/*; do
128 grep ^present $dev/info | grep -q yes || continue
129 design=$(sed '/design capacity:/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
130 remain=$(sed '/remaining capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
131 rate=$(sed '/present rate/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
132 full=$(sed '/last full capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
133 # FIXME
134 #remtime=$(( ($remain * 60) / $rate ))
135 #rempct=$(( ($remain * 100) / $full ))
136 cat << EOT
137 <tr>
138 <td><img src="$IMAGES/battery.png" />
139 Battery $(grep "^battery type" $dev/info | sed 's/.*: *//')
140 $(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
141 <td>health $(( (100*$full)/$design))%</td>
142 EOT
143 if grep -qis discharging $dev/state; then
144 cat <<EOT
145 <td class="pct"><div class="pct"
146 style="width: $rempct%;">charge&nbsp;$rempct%&nbsp;-&nbsp;$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))</div></td>
147 EOT
148 else
149 cat <<EOT
150 <td class="pct"><div class="pct"
151 style="width: $rempct%;">recharging&nbsp;$rempct%</div></td>
152 EOT
153 fi
154 done
155 echo "</table>"
156 fi
157 if [ -n "$(ls /sys/devices/virtual/thermal/*/temp 2> /dev/null)" ]; then
158 echo "Temperature: "
159 for temp in /sys/devices/virtual/thermal/*/temp; do
160 awk '{ print $1/1000 }' < $temp
161 done
162 fi
163 if [ -n "$(ls /sys/devices/virtual/backlight/*/brightness 2> /dev/null)" ]; then
164 cat <<EOT
165 <form method="get" action="$SCRIPT_NAME">
166 EOT
167 for dev in /sys/devices/virtual/backlight/*/brightness ; do
168 name=$(echo $dev | sed 's|.*/backlight/\([^/]*\).*|\1|')
169 cat <<EOT
170 <input type="hidden" name="dev" value="$name" />
171 $(gettext "Brightness") \
172 $(sed 's/.*\.//;s/_*$//' < /sys/devices/virtual/backlight/$name/device/path):
173 <select name="brightness" onchange="submit();">
174 EOT
175 max=$(cat /sys/devices/virtual/backlight/$name/max_brightness)
176 for i in $(seq 0 $max); do
177 echo -n "<option value=\"$i\""
178 [ $i -eq $(cat /sys/devices/virtual/backlight/$name/actual_brightness) ] &&
179 echo -n " selected=\"selected\""
180 echo "> $(( (($i + 1) * 100) / ($max + 1) ))% </option>"
181 done
182 cat <<EOT
183 </select>
184 EOT
185 done
186 cat << EOT
187 </form>
188 EOT
189 fi
190 cat << EOT
191 </div>
193 <h3>$(gettext "Filesystem usage statistics")</h3>
194 <pre>
195 EOT
196 fdisk -l | fgrep Disk
197 echo '</pre>'
198 #
199 # Disk stats and management (mount, umount, heck)
200 #
201 table_start
202 df_thead
203 df -h | grep ^/dev | while read fs size used av pct mp
204 do
205 cat << EOT
206 <tr>
207 <td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
208 <td>$size</td>
209 <td>$av</td>
210 <td class="pct"><div class="pct"
211 style="width: $pct;">$used&nbsp;-&nbsp;$pct</div></td>
212 <td>$mp</td>
213 </tr>
214 EOT
215 done
216 table_end
217 echo "<h3>$(gettext "System memory")</h3>"
218 echo '<pre>'
219 free -m | sed \
220 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
221 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
222 echo '</pre>'
223 echo '<h3>lspci</h3>'
224 echo '<pre>'
225 lspci -k | sed \
226 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
227 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
228 echo '</pre>'
229 echo '<h3>lsusb</h3>'
230 echo '<pre>'
231 lsusb
232 echo '</pre>'
233 ;;
234 esac
236 xhtml_footer
237 exit 0