tazpanel view hardware.cgi @ rev 217

hardware.cgi: add LCD brightness support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Dec 30 17:31:42 2011 +0100 (2011-12-30)
parents dbb91ac456b7
children 775fbfd01b04
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 EOT
107 if [ -n "$(ls /proc/acpi/video/*/LCD/brightness 2> /dev/null)" ]; then
108 cat <<EOT
109 <form method="get" action="$SCRIPT_NAME">
110 EOT
111 for dev in /proc/acpi/video/*/LCD/brightness ; do
112 name=$(echo $dev | sed 's|.*/video/||;s|/LCD/.*||')
113 cat <<EOT
114 <input type="hidden" name="dev" value="$name" />
115 $(gettext "LCD brightness") $name: <select name="brightness" onchange="submit();">
116 EOT
117 awk '{
118 if ($1 == "levels:")
119 for (i = 2; i <= NF; i++) level[$i] = i
120 if ($1 == "current:") current=$2
121 }
122 END {
123 for (i in level) {
124 s="<option value=\"" i "\""
125 if (current == i) s=s " selected=\"selected\""
126 s=s ">" i "%</option>"
127 if (i == 100) last=s
128 else print s
129 }
130 print last
131 }' < $dev
132 cat <<EOT
133 </select>
134 EOT
135 done
136 cat << EOT
137 </form>
138 EOT
139 fi
140 cat << EOT
141 </div>
142 <div>
143 <a class="button" href="$SCRIPT_NAME?modules">
144 <img src="$IMAGES/tux.png" />Kernel modules</a>
145 </div>
147 <h3>$(gettext "Filesystem usage statistics")</h3>
148 <pre>
149 EOT
150 fdisk -l | fgrep Disk
151 echo '</pre>'
152 #
153 # Disk stats and management (mount, umount, heck)
154 #
155 table_start
156 df_thead
157 df -h | grep ^/dev | while read fs size used av pct mp
158 do
159 cat << EOT
160 <tr>
161 <td><img src="$IMAGES/harddisk.png" />${fs#/dev/}</td>
162 <td>$size</td>
163 <td>$av</td>
164 <td class="pct"><div class="pct"
165 style="width: $pct;">$used&nbsp;-&nbsp;$pct</div></td>
166 <td>$mp</td>
167 </tr>
168 EOT
169 done
170 table_end
171 echo "<h3>$(gettext "System memory")</h3>"
172 echo '<pre>'
173 free -m | sed \
174 -e s"#total.*\([^']\)#<span class='top'>\0</span>#"g \
175 -e s"#^[A-Z-].*:\([^']\)#<span class='sh-comment'>\0</span>#"g
176 echo '</pre>'
177 echo '<h3>lspci</h3>'
178 echo '<pre>'
179 lspci -k | sed \
180 -e s"#^[0-9].*\([^']\)#<span class='diff-at'>\0</span>#" \
181 -e s"#use: \(.*\)#use: <span class='diff-rm'>\1</span>#"
182 echo '</pre>'
183 echo '<h3>lsusb</h3>'
184 echo '<pre>'
185 lsusb
186 echo '</pre>'
187 ;;
188 esac
190 xhtml_footer
191 exit 0