tazpanel view hardware.cgi @ rev 245

Added tag 1.3 for changeset 5103d4743ea4
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 28 14:28:44 2012 +0100 (2012-02-28)
parents 2934365ed3bd
children aa12dc99e177
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) > /proc/acpi/video/$(GET dev)/LCD/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 Harware</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 /proc/acpi/thermal_zone/*/temperature 2> /dev/null)" ]; then
158 echo "Temperature: "
159 for temp in /proc/acpi/thermal_zone/*/temperature; do
160 sed 's/.*://' < $temp
161 done
162 fi
163 if [ -n "$(ls /proc/acpi/video/*/LCD/brightness 2> /dev/null)" ]; then
164 cat <<EOT
165 <form method="get" action="$SCRIPT_NAME">
166 EOT
167 for dev in /proc/acpi/video/*/LCD/brightness ; do
168 name=$(echo $dev | sed 's|.*/video/||;s|/LCD/.*||')
169 cat <<EOT
170 <input type="hidden" name="dev" value="$name" />
171 $(gettext "LCD brightness") $name: <select name="brightness" onchange="submit();">
172 EOT
173 awk '{
174 if ($1 == "levels:")
175 for (i = 2; i <= NF; i++) level[$i] = i
176 if ($1 == "current:") current=$2
177 }
178 END {
179 for (i in level) {
180 s="<option value=\"" i "\""
181 if (current == i) s=s " selected=\"selected\""
182 s=s ">" i "%</option>"
183 if (i == 100) last=s
184 else print s
185 }
186 print last
187 }' < $dev
188 cat <<EOT
189 </select>
190 EOT
191 done
192 cat << EOT
193 </form>
194 EOT
195 fi
196 cat << EOT
197 </div>
199 <h3>$(gettext "Filesystem usage statistics")</h3>
200 <pre>
201 EOT
202 fdisk -l | fgrep Disk
203 echo '</pre>'
204 #
205 # Disk stats and management (mount, umount, heck)
206 #
207 table_start
208 df_thead
209 df -h | grep ^/dev | while read fs size used av pct mp
210 do
211 cat << EOT
212 <tr>
213 <td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
214 <td>$size</td>
215 <td>$av</td>
216 <td class="pct"><div class="pct"
217 style="width: $pct;">$used&nbsp;-&nbsp;$pct</div></td>
218 <td>$mp</td>
219 </tr>
220 EOT
221 done
222 table_end
223 echo "<h3>$(gettext "System memory")</h3>"
224 echo '<pre>'
225 free -m | sed \
226 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
227 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
228 echo '</pre>'
229 echo '<h3>lspci</h3>'
230 echo '<pre>'
231 lspci -k | sed \
232 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
233 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
234 echo '</pre>'
235 echo '<h3>lsusb</h3>'
236 echo '<pre>'
237 lsusb
238 echo '</pre>'
239 ;;
240 esac
242 xhtml_footer
243 exit 0