tazpanel view hardware.cgi @ rev 262

hardware.cgi: get brightness from /sys
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Mar 04 18:02:22 2012 +0100 (2012-03-04)
parents aa12dc99e177
children 11fa97b09b7d
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") ${name#acpi_}: <select name="brightness" onchange="submit();">
172 EOT
173 max=$(cat /sys/devices/virtual/backlight/$name/max_brightness)
174 for i in $(seq 0 $max); do
175 echo -n "<option value=\"$i\""
176 [ $i -eq $(cat /sys/devices/virtual/backlight/$name/actual_brightness) ] &&
177 echo -n " selected=\"selected\""
178 echo "> $(( (($i + 1) * 100) / ($max + 1) ))% </option>"
179 done
180 cat <<EOT
181 </select>
182 EOT
183 done
184 cat << EOT
185 </form>
186 EOT
187 fi
188 cat << EOT
189 </div>
191 <h3>$(gettext "Filesystem usage statistics")</h3>
192 <pre>
193 EOT
194 fdisk -l | fgrep Disk
195 echo '</pre>'
196 #
197 # Disk stats and management (mount, umount, heck)
198 #
199 table_start
200 df_thead
201 df -h | grep ^/dev | while read fs size used av pct mp
202 do
203 cat << EOT
204 <tr>
205 <td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
206 <td>$size</td>
207 <td>$av</td>
208 <td class="pct"><div class="pct"
209 style="width: $pct;">$used&nbsp;-&nbsp;$pct</div></td>
210 <td>$mp</td>
211 </tr>
212 EOT
213 done
214 table_end
215 echo "<h3>$(gettext "System memory")</h3>"
216 echo '<pre>'
217 free -m | sed \
218 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
219 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
220 echo '</pre>'
221 echo '<h3>lspci</h3>'
222 echo '<pre>'
223 lspci -k | sed \
224 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
225 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
226 echo '</pre>'
227 echo '<h3>lsusb</h3>'
228 echo '<pre>'
229 lsusb
230 echo '</pre>'
231 ;;
232 esac
234 xhtml_footer
235 exit 0