tazpanel view hardware.cgi @ rev 224

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