tazpanel view hardware.cgi @ rev 303
3 weeks forging ;) Some bugs fixed, maybe all i18n improved (please, recheck 'po's!), couple of new features added... Enjoy!
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri May 04 13:00:43 2012 +0300 (2012-05-04) |
parents | 72e9955ebdff |
children | 3e9acc16f728 |
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 #
16 # Commands
17 #
19 case " $(GET) " in
20 *\ print\ *)
21 xhtml_header
22 echo "<h2>TODO</h2>" ;;
23 *\ detect\ *)
24 # Front end for Tazhw
25 # TODO: Add button to detect webcam, etc. Like in tazhw box.
26 xhtml_header
27 cat << EOT
28 <div id="wrapper">
29 <h2>$(gettext 'Detect hardware')</h2>
30 <p>$(gettext 'Detect PCI and USB hardware')</p>
31 </div>
33 <pre>$(tazhw detect-pci | syntax_highlighter sh)</pre>
35 <pre>$(tazhw detect-usb | syntax_highlighter sh)</pre>
36 EOT
37 ;;
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="search" placeholder="$(gettext 'Modules search')" 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 get_modinfo="$(GET modinfo)"
54 if [ -n "$get_modinfo" ]; then
55 cat << EOT
56 <strong>$(eval_gettext 'Detailed information for module: $get_modinfo')</strong>
58 <pre>$(modinfo $get_modinfo)</pre>
59 EOT
60 fi
61 if [ -n "$(GET modprobe)" ]; then
62 echo "<pre>$(modprobe -v $(GET modprobe))</pre>"
63 fi
64 if [ -n "$(GET rmmod)" ]; then
65 echo "Removing"
66 rmmod -w $(GET rmmod)
67 fi
68 get_search="$(GET search)"
69 if [ -n "$get_search" ]; then
70 eval_gettext 'Matching result(s) for: $get_search'
71 echo '<pre>'
72 modprobe -l | grep "$(GET search)" | while read line
73 do
74 name=$(basename $line)
75 mod=${name%.ko.gz}
76 echo "$(gettext 'Module:') <a href='$SCRIPT_NAME?modinfo=$mod'>$mod</a>"
77 done
78 echo '</pre>'
79 fi
80 cat << EOT
81 $(table_start)
82 <tr class="thead">
83 <td>$(gettext 'Module')</td>
84 <td>$(gettext 'Size')</td>
85 <td>$(gettext 'Used')</td>
86 <td>$(gettext 'by')</td>
87 </tr>
88 EOT
89 # Get the list of modules and link to modinfo
90 lsmod | grep ^[a-z] | while read MOD SIZE USED BY
91 do
92 cat << EOT
93 <tr>
94 <td><a href="$SCRIPT_NAME?modinfo=$MOD">$MOD</a></td>
95 <td>$SIZE</td>
96 <td>$USED</td>
97 <td>$(echo $BY | sed s/","/" "/g)</td>
98 </tr>
99 EOT
100 done
101 table_end ;;
102 *)
103 [ -n "$(GET brightness)" ] &&
104 echo -n $(GET brightness) > /sys/devices/virtual/backlight/$(GET dev)/brightness
106 #
107 # Default to summary with mounted filesystem, loaded modules
108 #
109 xhtml_header
110 cat << EOT
111 <div id="wrapper">
112 <h2>$(gettext 'Drivers & Devices')</h2>
113 <p>$(gettext 'Manage your computer hardware')</p>
114 </div>
115 <div>
116 <a class="button" href="$SCRIPT_NAME?modules">
117 <img src="$IMAGES/tux.png" />$(gettext 'Kernel modules')</a>
118 <a class="button" href="$SCRIPT_NAME?detect">
119 <img src="$IMAGES/monitor.png" />$(gettext 'Detect PCI/USB')</a>
120 </div>
122 <div id="wrapper">
123 EOT
124 if [ -n "$(ls /proc/acpi/battery/*/info 2> /dev/null)" ]; then
125 echo "<table>"
126 for dev in /proc/acpi/battery/*; do
127 grep ^present $dev/info | grep -q yes || continue
128 design=$(sed '/design capacity:/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
129 remain=$(sed '/remaining capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
130 rate=$(sed '/present rate/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
131 full=$(sed '/last full capacity/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
132 warning=$(sed '/design capacity warning/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
133 low=$(sed '/design capacity low/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
134 state=$(sed '/charging state/!d;s/\([^:]*:[ ]\+\)\([a-z]\+\)/\2/' < $dev/state)
136 rempct=$(( $remain * 100 / $full ))
137 cat << EOT
138 <tr>
139 <td><img src="$IMAGES/battery.png" />
140 $(gettext 'Battery') $(grep "^battery type" $dev/info | sed 's/.*: *//')
141 $(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
142 <td>$(gettext 'health') $(( (100*$full)/$design))%</td>
143 <td class="meter"><meter min="0" max="$full" value="$remain" low="$low"
144 high="$warning" optimum="$full"></meter>
145 <span>
146 EOT
147 case "$state" in
148 "discharging")
149 remtime=$(( $remain * 60 / $rate ))
150 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
151 eval_gettext 'Discharging $rempct% - $remtimef' ;;
152 "charging")
153 remtime=$(( ($full - $remain) * 60 / $rate ))
154 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
155 eval_gettext 'Charging $rempct% - $remtimef' ;;
156 "charged")
157 gettext 'Charged 100%' ;;
158 esac
159 echo '</span></td></tr>'
160 done
161 echo "</table>"
162 fi
164 if [ -n "$(ls /sys/devices/virtual/thermal/*/temp 2> /dev/null)" ]; then
165 echo -n '<p>'; gettext 'Temperature:'
166 for temp in /sys/devices/virtual/thermal/*/temp; do
167 awk '{ print $1/1000 }' < $temp
168 done
169 echo '</p>'
170 fi
172 if [ -n "$(ls /sys/devices/virtual/backlight/*/brightness 2> /dev/null)" ]; then
173 cat <<EOT
174 <form method="get" action="$SCRIPT_NAME">
175 EOT
176 for dev in /sys/devices/virtual/backlight/*/brightness ; do
177 name=$(echo $dev | sed 's|.*/backlight/\([^/]*\).*|\1|')
178 cat <<EOT
179 <input type="hidden" name="dev" value="$name" />
180 $(gettext 'Brightness') \
181 $(sed 's/.*\.//;s/_*$//' < /sys/devices/virtual/backlight/$name/device/path):
182 <select name="brightness" onchange="submit();">
183 EOT
184 max=$(cat /sys/devices/virtual/backlight/$name/max_brightness)
185 for i in $(seq 0 $max); do
186 echo -n "<option value=\"$i\""
187 [ $i -eq $(cat /sys/devices/virtual/backlight/$name/actual_brightness) ] &&
188 echo -n " selected=\"selected\""
189 echo "> $(( (($i + 1) * 100) / ($max + 1) ))% </option>"
190 done
191 cat <<EOT
192 </select>
193 EOT
194 done
195 cat << EOT
196 </form>
197 EOT
198 fi
199 cat << EOT
200 </div>
202 <h3>$(gettext 'Filesystem usage statistics')</h3>
203 <pre>
204 EOT
205 fdisk -l | fgrep Disk
206 echo '</pre>'
209 #
210 # Disk stats and management (mount, umount, check)
211 #
212 cat << EOT
213 <table class="zebra">
214 EOT
215 df_thead
216 echo '<tbody>'
217 df -h | grep ^/dev | while read fs size used av pct mp
218 do
219 cat << EOT
220 <tr>
221 <td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
222 <td>$(blkid -o value $fs | head -n1)</td>
223 <td>$(blkid -o value $fs | tail -n1)</td>
224 <td>$size</td>
225 <td>$av</td>
226 <td class="meter"><meter min="0" max="100" value="${pct%%%}" low="70"
227 high="90" optimum="10"></meter>
228 <span>$used - $pct</span>
229 </td>
230 <td>$mp</td>
231 </tr>
232 EOT
233 done
234 cat << EOT
235 </tbody>
236 </table>
238 EOT
241 cat << EOT
242 <h3>$(gettext 'System memory')</h3>
243 <pre>
244 EOT
245 free -m | sed \
246 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
247 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
248 cat << EOT
249 </pre>
251 <h3>lspci</h3>
252 <pre>
253 EOT
254 lspci -k | sed \
255 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
256 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
257 cat << EOT
258 </pre>
260 <h3>lsusb</h3>
261 <pre>$(lsusb)</pre>
262 EOT
263 ;;
264 esac
266 xhtml_footer
267 exit 0