tazpanel view hardware.cgi @ rev 237

style: Small color change
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 28 11:59:51 2012 +0100 (2012-02-28)
parents 0b69a546638a
children 460c608c35ff
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 # FIXME
116 #remtime=$(( ($remain * 60) / $rate ))
117 #rempct=$(( ($remain * 100) / $full ))
118 cat << EOT
119 <tr>
120 <td><img src="$IMAGES/battery.png" />
121 Battery $(grep "^battery type" $dev/info | sed 's/.*: *//')
122 $(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
123 <td>health $(( (100*$full)/$design))%</td>
124 EOT
125 if grep -qis discharging $dev/state; then
126 cat <<EOT
127 <td class="pct"><div class="pct"
128 style="width: $rempct%;">charge&nbsp;$rempct%&nbsp;-&nbsp;$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))</div></td>
129 EOT
130 else
131 cat <<EOT
132 <td class="pct"><div class="pct"
133 style="width: $rempct%;">recharging&nbsp;$rempct%</div></td>
134 EOT
135 fi
136 done
137 echo "</table>"
138 fi
139 if [ -n "$(ls /proc/acpi/thermal_zone/*/temperature 2> /dev/null)" ]; then
140 echo "Temperature: "
141 for temp in /proc/acpi/thermal_zone/*/temperature; do
142 sed 's/.*://' < $temp
143 done
144 fi
145 if [ -n "$(ls /proc/acpi/video/*/LCD/brightness 2> /dev/null)" ]; then
146 cat <<EOT
147 <form method="get" action="$SCRIPT_NAME">
148 EOT
149 for dev in /proc/acpi/video/*/LCD/brightness ; do
150 name=$(echo $dev | sed 's|.*/video/||;s|/LCD/.*||')
151 cat <<EOT
152 <input type="hidden" name="dev" value="$name" />
153 $(gettext "LCD brightness") $name: <select name="brightness" onchange="submit();">
154 EOT
155 awk '{
156 if ($1 == "levels:")
157 for (i = 2; i <= NF; i++) level[$i] = i
158 if ($1 == "current:") current=$2
159 }
160 END {
161 for (i in level) {
162 s="<option value=\"" i "\""
163 if (current == i) s=s " selected=\"selected\""
164 s=s ">" i "%</option>"
165 if (i == 100) last=s
166 else print s
167 }
168 print last
169 }' < $dev
170 cat <<EOT
171 </select>
172 EOT
173 done
174 cat << EOT
175 </form>
176 EOT
177 fi
178 cat << EOT
179 </div>
181 <h3>$(gettext "Filesystem usage statistics")</h3>
182 <pre>
183 EOT
184 fdisk -l | fgrep Disk
185 echo '</pre>'
186 #
187 # Disk stats and management (mount, umount, heck)
188 #
189 table_start
190 df_thead
191 df -h | grep ^/dev | while read fs size used av pct mp
192 do
193 cat << EOT
194 <tr>
195 <td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
196 <td>$size</td>
197 <td>$av</td>
198 <td class="pct"><div class="pct"
199 style="width: $pct;">$used&nbsp;-&nbsp;$pct</div></td>
200 <td>$mp</td>
201 </tr>
202 EOT
203 done
204 table_end
205 echo "<h3>$(gettext "System memory")</h3>"
206 echo '<pre>'
207 free -m | sed \
208 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
209 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
210 echo '</pre>'
211 echo '<h3>lspci</h3>'
212 echo '<pre>'
213 lspci -k | sed \
214 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
215 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
216 echo '</pre>'
217 echo '<h3>lsusb</h3>'
218 echo '<pre>'
219 lsusb
220 echo '</pre>'
221 ;;
222 esac
224 xhtml_footer
225 exit 0