tazpanel view hardware.cgi @ rev 234

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