rev |
line source |
pankso@46
|
1 #!/bin/sh
|
pankso@46
|
2 #
|
pankso@46
|
3 # Hardware part of TazPanel - Devices, drivers, printing
|
pankso@46
|
4 #
|
al@419
|
5 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
|
pankso@46
|
6 #
|
pankso@46
|
7
|
pankso@46
|
8 # Common functions from libtazpanel
|
pascal@613
|
9 . ./lib/libtazpanel
|
pankso@46
|
10 get_config
|
pascal@81
|
11 header
|
pankso@46
|
12
|
al@501
|
13 TITLE=$(_ 'Hardware')
|
pankso@46
|
14
|
paul@385
|
15 # Call an optional module
|
al@426
|
16 lib() {
|
pascal@373
|
17 module=lib/$1
|
pascal@373
|
18 shift
|
pascal@373
|
19 [ -s $module ] && . $module "$@"
|
pascal@373
|
20 }
|
pascal@373
|
21
|
pascal@431
|
22 disk_info() {
|
pascal@431
|
23 fdisk -l | fgrep Disk | while read a b c; do
|
pascal@622
|
24 d=${b##*/}
|
pascal@618
|
25 t="HD"
|
pascal@618
|
26 [ "$(cat /sys/block/${d%:}/queue/rotational)" -eq "0" ] && t="SSD"
|
pascal@619
|
27 d="/sys/block/${d%:}/device"
|
pascal@618
|
28 [ -d $d ] && echo "$a $b $c, $t $(cat $d/vendor) $(cat $d/model)"
|
pascal@612
|
29 smartctl -a ${b%:} | sed '/^Model/,/^Firmware/!d'
|
pascal@431
|
30 done 2> /dev/null | sed 's/ */ /g'
|
pascal@431
|
31 }
|
al@419
|
32
|
pascal@473
|
33 lsusb_vd() {
|
pascal@473
|
34 if lsusb --help 2>&1 | grep -qi busybox ; then
|
pascal@473
|
35 for i in /sys/class/usb_device/*/device ; do
|
pascal@473
|
36 grep -qs ${1%:*} $i/idVendor || continue
|
pascal@473
|
37 grep -qs ${1#*:} $i/idProduct || continue
|
pascal@473
|
38 ( cd $i ; for j in * ; do
|
pascal@473
|
39 [ -f $j -a -r $j ] || continue
|
pascal@473
|
40 case "$j" in
|
pascal@473
|
41 descriptors|remove) continue
|
pascal@473
|
42 esac
|
pascal@569
|
43 awk -vn=$j '{printf "%-20s %s\n",n,$0;n=""}' <$j
|
pascal@473
|
44 done )
|
pascal@473
|
45 break
|
pascal@473
|
46 done
|
pascal@473
|
47 else
|
pascal@473
|
48 lsusb -vd $1 | syntax_highlighter lsusb
|
pascal@473
|
49 fi
|
pascal@473
|
50 }
|
pascal@473
|
51
|
al@426
|
52 lsusb_table() {
|
al@419
|
53 cat <<EOT
|
al@419
|
54 <table class="wide zebra">
|
al@426
|
55 <thead>
|
al@426
|
56 <tr>
|
al@443
|
57 <td>$(_ 'Bus')</td>
|
al@443
|
58 <td>$(_ 'Device')</td>
|
al@443
|
59 <td>$(_ 'ID')</td>
|
al@443
|
60 <td>$(_ 'Name')</td>
|
al@426
|
61 </tr>
|
al@426
|
62 </thead>
|
al@363
|
63 <tbody>
|
al@363
|
64 EOT
|
pascal@473
|
65 lsusb | while read x b y d z id name ; do
|
pascal@473
|
66 echo "<tr><td>$b</td><td>${d%:}</td><td><a href=\"?lsusb=$id"
|
pascal@473
|
67 p=$(printf "class/usb_device/usbdev%d.%d" $b ${d%:})
|
pascal@473
|
68 grep -qs 0 /sys/$p/device/authorized && id="<del>$id</del>"
|
pascal@566
|
69 echo "\">$id</td><td>${name:-$(sed 's/ .*//' /sys/$p/device/manufacturer) $(cat /sys/$p/device/product)}</td></tr>"
|
pascal@473
|
70 done
|
al@363
|
71 echo "</tbody></table>"
|
al@363
|
72 }
|
al@363
|
73
|
al@419
|
74
|
al@426
|
75 lspci_table() {
|
al@419
|
76 cat <<EOT
|
al@419
|
77 <table class="wide zebra">
|
al@541
|
78 <thead><tr>
|
al@541
|
79 <td>$(_ 'Slot')</td>
|
al@541
|
80 <td>$(_ 'Device')</td>
|
al@541
|
81 <td>$(_ 'Name')</td>
|
al@541
|
82 </tr></thead>
|
al@363
|
83 <tbody>
|
al@363
|
84 EOT
|
pascal@596
|
85 lspci | while read a b c id ; do
|
pascal@596
|
86 if [ $b != "Class" ] || [ ! -s /usr/share/misc/pci.ids.gz ]; then
|
pascal@597
|
87 echo "X$a $b $c $id"
|
pascal@596
|
88 continue
|
pascal@596
|
89 fi
|
pascal@597
|
90 echo -n "$a "
|
pascal@596
|
91 zcat /usr/share/misc/pci.ids.gz | \
|
pascal@596
|
92 awk -va=${c:0:2} -vb=${c:2:2} -vh=${id:0:4} -vl=${id:5:4} '{
|
pascal@596
|
93 if ($1 == "C" && $2 == a) class=substr($0,5)
|
pascal@596
|
94 if (class != "" && $1 == b) { class=substr($0,5); exit }
|
pascal@596
|
95 if (substr($0,1,4) == h) m=substr($0,7)
|
pascal@596
|
96 else if (m == "") next
|
pascal@596
|
97 else if (substr($0,2,4) == l) { name=m substr($0,7); m="" }
|
pascal@596
|
98 else if ($1 == h && $2 == l) { name=m substr($0,14); m="" }
|
pascal@598
|
99 } END { print "[" a b "] " class ": [" h "/" l "] " name }'
|
pascal@596
|
100 done | sed 's| |</td><td>|;
|
al@363
|
101 s|: |</td><td>|;
|
pascal@597
|
102 s|^X\([^<]*\)|<a href="?lspci=\1">\1</a>|;
|
al@363
|
103 s|^.*$|<tr><td>\0</td></tr>|'
|
al@363
|
104 echo "</tbody></table>"
|
al@363
|
105 }
|
al@363
|
106
|
al@426
|
107
|
pankso@46
|
108 #
|
pankso@46
|
109 # Commands
|
pankso@46
|
110 #
|
pankso@46
|
111
|
pascal@81
|
112 case " $(GET) " in
|
pascal@81
|
113 *\ print\ *)
|
al@303
|
114 xhtml_header
|
al@419
|
115 echo "<h2>TODO</h2>"
|
al@419
|
116 ;;
|
al@419
|
117
|
al@419
|
118
|
psychomaniak@407
|
119 *\ tazx\ *)
|
psychomaniak@407
|
120 xhtml_header
|
al@419
|
121 cat <<EOT
|
psychomaniak@407
|
122 <pre>$(tazx auto)</pre>
|
psychomaniak@407
|
123 EOT
|
psychomaniak@407
|
124 ;;
|
al@419
|
125
|
al@419
|
126
|
pankso@242
|
127 *\ detect\ *)
|
pankso@242
|
128 # Front end for Tazhw
|
pankso@242
|
129 # TODO: Add button to detect webcam, etc. Like in tazhw box.
|
al@501
|
130 xhtml_header "$(_ 'Detect hardware')"
|
al@419
|
131 cat <<EOT
|
al@443
|
132 <p>$(_ 'Detect PCI and USB hardware')</p>
|
pankso@242
|
133 EOT
|
pascal@567
|
134 tazhw detect-pci | htmlize
|
pascal@567
|
135 tazhw detect-usb | htmlize | filter_taztools_msgs
|
al@303
|
136 ;;
|
al@419
|
137
|
al@419
|
138
|
pascal@81
|
139 *\ modules\ *|*\ modinfo\ *)
|
al@501
|
140 xhtml_header "$(_ 'Kernel modules')"
|
al@501
|
141
|
al@501
|
142 search="$(GET search)"
|
al@419
|
143 cat <<EOT
|
al@443
|
144 <p>$(_ 'Manage, search or get information about the Linux kernel modules')</p>
|
al@419
|
145
|
al@501
|
146 <form class="search">
|
al@419
|
147 <input type="hidden" name="modules"/>
|
al@501
|
148 <input type="search" name="search" value="$search" placeholder="$(_ 'Modules search')" results="5" autosave="modsearch" autocomplete="on"/>
|
al@501
|
149 <button type="submit">$(_n 'Search')</button>
|
al@419
|
150 </form>
|
pankso@46
|
151 EOT
|
pankso@66
|
152 # Request may be modinfo output that we want in the page itself
|
al@303
|
153 get_modinfo="$(GET modinfo)"
|
al@303
|
154 if [ -n "$get_modinfo" ]; then
|
al@419
|
155 cat <<EOT
|
al@419
|
156 <section>
|
al@443
|
157 <header>$(_ 'Detailed information for module: %s' $get_modinfo)</header>
|
al@501
|
158 <div class="scroll">
|
al@303
|
159
|
al@303
|
160 EOT
|
al@419
|
161 modinfo $get_modinfo | awk 'BEGIN{print "<table class=\"wide zebra\">"}
|
al@419
|
162 {
|
al@419
|
163 printf("<tr><td><b>%s</b></td>", $1)
|
al@419
|
164 $1=""; printf("<td>%s</td></tr>", $0)
|
al@419
|
165 }
|
al@501
|
166 END{print "</table></div></section>"}'
|
pascal@81
|
167 fi
|
al@419
|
168
|
pascal@81
|
169 if [ -n "$(GET modprobe)" ]; then
|
al@303
|
170 echo "<pre>$(modprobe -v $(GET modprobe))</pre>"
|
pascal@81
|
171 fi
|
pascal@81
|
172 if [ -n "$(GET rmmod)" ]; then
|
pascal@81
|
173 echo "Removing"
|
pascal@81
|
174 rmmod -w $(GET rmmod)
|
pascal@81
|
175 fi
|
al@501
|
176
|
al@501
|
177 # Module search
|
al@501
|
178 if [ -n "$search" ]; then
|
al@501
|
179 cat <<EOT
|
al@501
|
180 <section>
|
al@501
|
181 <header>$(_ 'Matching result(s) for: %s' $search)</header>
|
al@501
|
182 <pre class="scroll">
|
al@501
|
183 EOT
|
al@501
|
184 busybox modprobe -l | grep "$search" | while read line
|
pascal@81
|
185 do
|
pascal@81
|
186 name=$(basename $line)
|
al@501
|
187 mod=${name%.ko.xz}
|
al@558
|
188 echo "<span data-icon=\"@modules@\">$(_ 'Module:')</span> <a href='?modinfo=$mod'>$mod</a>"
|
pascal@81
|
189 done
|
al@501
|
190 echo '</pre></section>'
|
pascal@81
|
191 fi
|
al@501
|
192
|
al@419
|
193 cat <<EOT
|
al@419
|
194 <section>
|
al@426
|
195 <table class="zebra">
|
al@419
|
196 <thead>
|
al@419
|
197 <tr>
|
al@443
|
198 <td>$(_ 'Module')</td>
|
al@443
|
199 <td>$(_ 'Description')</td>
|
al@443
|
200 <td>$(_ 'Size')</td>
|
al@443
|
201 <td>$(_ 'Used')</td>
|
al@443
|
202 <td>$(_ 'by')</td>
|
al@419
|
203 </tr>
|
al@419
|
204 <thead>
|
al@419
|
205 <tbody>
|
pankso@46
|
206 EOT
|
pankso@46
|
207 # Get the list of modules and link to modinfo
|
al@419
|
208 lsmod | tail -n+2 | awk '{
|
al@419
|
209 gsub(",", " ", $4);
|
al@419
|
210 printf("<tr><td><a href=\"?modinfo=%s\">%s</a></td><td>", $1, $1);
|
al@419
|
211 system("modinfo -d " $1);
|
al@419
|
212 printf("</td><td>%s</td><td>%s</td><td>%s</td></tr>", $2, $3, $4);
|
al@419
|
213 }'
|
al@419
|
214 cat <<EOT
|
al@419
|
215 </thead>
|
al@419
|
216 </table>
|
al@419
|
217 </section>
|
pankso@46
|
218 EOT
|
al@419
|
219 ;;
|
al@419
|
220
|
al@419
|
221
|
al@363
|
222 *\ lsusb\ *)
|
al@363
|
223 xhtml_header
|
al@363
|
224 vidpid="$(GET lsusb)"
|
al@419
|
225 cat <<EOT
|
al@443
|
226 <h2>$(_ 'Information for USB Device %s' $vidpid)</h2>
|
al@419
|
227
|
al@443
|
228 <p>$(_ 'Detailed information about specified device.')</p>
|
al@419
|
229
|
al@419
|
230 <section>$(lsusb_table)</section>
|
al@426
|
231 EOT
|
al@426
|
232 [ "$vidpid" != 'lsusb' ] && cat <<EOT
|
al@419
|
233 <section>
|
pascal@473
|
234 <pre style="white-space: pre-wrap">$(lsusb_vd $vidpid)</pre>
|
al@419
|
235 </section>
|
al@363
|
236 EOT
|
al@363
|
237 ;;
|
al@419
|
238
|
al@419
|
239
|
al@363
|
240 *\ lspci\ *)
|
al@363
|
241 xhtml_header
|
al@363
|
242 slot="$(GET lspci)"
|
al@419
|
243 cat <<EOT
|
al@443
|
244 <h2>$(_ 'Information for PCI Device %s' $slot)</h2>
|
al@419
|
245
|
al@443
|
246 <p>$(_ 'Detailed information about specified device.')</p>
|
al@419
|
247
|
al@419
|
248 <section>$(lspci_table)</section>
|
al@426
|
249 EOT
|
al@426
|
250 [ "$slot" != 'lspci' ] && cat <<EOT
|
al@419
|
251 <section>
|
al@426
|
252 <pre style="white-space: pre-wrap">$(lspci -vs $slot | syntax_highlighter lspci)</pre>
|
al@419
|
253 </section>
|
al@363
|
254 EOT
|
al@363
|
255 ;;
|
al@419
|
256
|
al@419
|
257
|
pankso@66
|
258 *)
|
pascal@217
|
259 [ -n "$(GET brightness)" ] &&
|
al@426
|
260 echo -n $(GET brightness) > /sys/devices/virtual/backlight/$(GET dev)/brightness
|
al@292
|
261
|
pankso@66
|
262 #
|
pankso@66
|
263 # Default to summary with mounted filesystem, loaded modules
|
pankso@66
|
264 #
|
al@501
|
265 xhtml_header "$(_ 'Drivers & Devices')"
|
al@419
|
266 cat <<EOT
|
al@443
|
267 <p>$(_ 'Manage your computer hardware')</p>
|
al@419
|
268
|
al@419
|
269 <form><!--
|
al@558
|
270 --><button name="modules" data-icon="@modules@">$(_ 'Kernel modules')</button><!--
|
al@558
|
271 --><button name="detect" data-icon="@detect@" data-root>$(_ 'Detect PCI/USB')</button><!--
|
al@558
|
272 --><button name="tazx" data-icon="@tazx@" data-root>$(_ 'Auto-install Xorg video driver')</button><!--
|
al@437
|
273 --></form>
|
pascal@219
|
274
|
pascal@217
|
275 EOT
|
al@419
|
276
|
al@419
|
277
|
al@419
|
278 # Battery state
|
al@419
|
279 if [ -n "$(ls /proc/acpi/battery/*/info 2>/dev/null)" ]; then
|
al@419
|
280 cat <<EOT
|
al@419
|
281 <section>
|
al@443
|
282 <header>$(_ 'Battery')</header>
|
al@419
|
283 <div>
|
al@419
|
284 <table class="wide">
|
al@419
|
285 EOT
|
pascal@219
|
286 for dev in /proc/acpi/battery/*; do
|
pascal@219
|
287 grep ^present $dev/info | grep -q yes || continue
|
al@419
|
288 design=$(sed '/design capacity:/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
|
al@419
|
289 remain=$(sed '/remaining capacity/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
|
al@419
|
290 rate=$(sed '/present rate/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/state)
|
al@419
|
291 full=$(sed '/last full capacity/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
|
al@303
|
292 warning=$(sed '/design capacity warning/!d;s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
|
al@419
|
293 low=$(sed '/design capacity low/!d; s/[^0-9]*\([0-9]*\).*/\1/' < $dev/info)
|
al@419
|
294 state=$(sed '/charging state/!d; s/\([^:]*:[ ]\+\)\([a-z]\+\)/\2/' < $dev/state)
|
al@303
|
295
|
al@303
|
296 rempct=$(( $remain * 100 / $full ))
|
al@419
|
297 cat <<EOT
|
al@419
|
298 <tr>
|
al@558
|
299 <td><span data-icon="@battery@">$(_ 'Battery')</span>
|
al@419
|
300 $(grep "^battery type" $dev/info | sed 's/.*: *//')
|
al@419
|
301 $(grep "^design capacity:" $dev/info | sed 's/.*: *//') </td>
|
al@443
|
302 <td>$(_ 'health') $(( (100*$full)/$design))%</td>
|
al@419
|
303 <td class="meter"><meter min="0" max="$full" value="$remain" low="$low"
|
al@419
|
304 high="$warning" optimum="$full"></meter>
|
al@419
|
305 <span>
|
pascal@219
|
306 EOT
|
al@303
|
307 case "$state" in
|
al@303
|
308 "discharging")
|
al@303
|
309 remtime=$(( $remain * 60 / $rate ))
|
al@303
|
310 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
|
al@443
|
311 _ 'Discharging %d%% - %s' $rempct $remtimef ;;
|
al@303
|
312 "charging")
|
al@303
|
313 remtime=$(( ($full - $remain) * 60 / $rate ))
|
al@303
|
314 remtimef=$(printf "%d:%02d" $(($remtime/60)) $(($remtime%60)))
|
pascal@468
|
315 _ 'Charging %d%% - %s' $rempct $remtimef ;;
|
al@303
|
316 "charged")
|
pascal@469
|
317 _ 'Charged 100%%' ;;
|
al@303
|
318 esac
|
al@419
|
319 cat <<EOT
|
al@419
|
320
|
al@419
|
321 </span>
|
al@419
|
322 </td>
|
al@419
|
323 </tr>
|
al@419
|
324 EOT
|
pascal@219
|
325 done
|
al@419
|
326 cat <<EOT
|
al@419
|
327 </table>
|
al@419
|
328 </div>
|
al@419
|
329 </section>
|
al@419
|
330 EOT
|
pascal@219
|
331 fi
|
al@303
|
332
|
al@419
|
333
|
al@419
|
334 # Thermal sensors
|
al@419
|
335 if [ -n "$(ls /sys/devices/virtual/thermal/*/temp 2>/dev/null)" ]; then
|
al@558
|
336 echo "<p><span data-icon=\"@temperature@\">$(_ 'Temperature:')</span>"
|
pascal@262
|
337 for temp in /sys/devices/virtual/thermal/*/temp; do
|
al@419
|
338 awk '{ print $1/1000 "℃" }' < $temp
|
pascal@219
|
339 done
|
al@303
|
340 echo '</p>'
|
pascal@219
|
341 fi
|
al@303
|
342
|
al@419
|
343
|
al@419
|
344 # Brightness
|
al@419
|
345 if [ -n "$(ls /sys/devices/virtual/backlight/*/brightness 2>/dev/null)" ]; then
|
al@419
|
346 echo '<form>'
|
al@419
|
347 for dev in /sys/devices/virtual/backlight/*/brightness; do
|
pascal@262
|
348 name=$(echo $dev | sed 's|.*/backlight/\([^/]*\).*|\1|')
|
pascal@217
|
349 cat <<EOT
|
al@419
|
350 <input type="hidden" name="dev" value="$name"/>
|
al@558
|
351 <span data-icon="@brightness@">$(_ 'Brightness')</span> \
|
pascal@263
|
352 $(sed 's/.*\.//;s/_*$//' < /sys/devices/virtual/backlight/$name/device/path):
|
al@419
|
353 <select name="brightness" onchange="submit();">
|
pascal@217
|
354 EOT
|
pascal@262
|
355 max=$(cat /sys/devices/virtual/backlight/$name/max_brightness)
|
pascal@262
|
356 for i in $(seq 0 $max); do
|
pascal@262
|
357 echo -n "<option value=\"$i\""
|
pascal@262
|
358 [ $i -eq $(cat /sys/devices/virtual/backlight/$name/actual_brightness) ] &&
|
pascal@262
|
359 echo -n " selected=\"selected\""
|
pascal@262
|
360 echo "> $(( (($i + 1) * 100) / ($max + 1) ))% </option>"
|
pascal@262
|
361 done
|
al@419
|
362 echo '</select>'
|
pascal@217
|
363 done
|
al@419
|
364 echo '</form>'
|
pascal@217
|
365 fi
|
pankso@152
|
366
|
al@363
|
367
|
al@419
|
368 cat <<EOT
|
al@419
|
369 <section>
|
al@419
|
370 <form action="#mount" class="wide">
|
al@443
|
371 <header id="disk">$(_ 'Filesystem usage statistics')</header>
|
al@419
|
372 <div>
|
pascal@431
|
373 <pre>$(disk_info)</pre>
|
al@419
|
374 </div>
|
pankso@66
|
375 EOT
|
al@303
|
376
|
al@303
|
377
|
pankso@153
|
378 #
|
pascal@376
|
379 # Loop device management actions
|
pascal@376
|
380 #
|
pascal@376
|
381 device=$(GET loopdev)
|
pascal@376
|
382 lib crypto $device
|
pascal@376
|
383 case "$device" in
|
pascal@425
|
384 /dev/*loop*)
|
pascal@376
|
385 set -- $(losetup | grep ^$device:)
|
pascal@376
|
386 [ -n "$3" ] && losetup -d $device
|
pascal@376
|
387 ro=""
|
pascal@376
|
388 [ -n "$(GET readonly)" ] && ro="-r"
|
pascal@376
|
389 file="$(GET backingfile)"
|
pascal@376
|
390 [ -n "$file" ] && losetup -o $(GET offset) $ro $device $file
|
pascal@376
|
391 esac
|
al@419
|
392
|
al@419
|
393
|
pascal@376
|
394 #
|
al@303
|
395 # Disk stats and management (mount, umount, check)
|
pankso@153
|
396 #
|
pascal@344
|
397 device=$(GET device)
|
pascal@373
|
398 lib crypto $device
|
pascal@344
|
399 case "$device" in
|
pascal@344
|
400 *[\;\`\&\|\$]*) ;;
|
pascal@344
|
401 mount\ *)
|
pascal@375
|
402 ro=""
|
pascal@375
|
403 [ -n "$(GET readonly)" ] && ro="-r"
|
pascal@389
|
404 mntdir="$(GET mountpoint)"
|
pascal@389
|
405 [ -d "$mntdir" ] || mkdir -p "$mntdir"
|
pascal@389
|
406 $device $ro "$mntdir";;
|
pascal@344
|
407 umount\ *|swapon\ *|swapoff\ *)
|
pascal@344
|
408 $device ;;
|
pascal@344
|
409 esac
|
al@419
|
410 cat <<EOT
|
al@419
|
411 <table id="mount" class="zebra wide center">
|
al@303
|
412 EOT
|
pankso@153
|
413 df_thead
|
al@303
|
414 echo '<tbody>'
|
pascal@621
|
415 bootdevs="$(fdisk -l | sed '/\*/!d;/^\/dev/!d;s/ .*//' | xargs)"
|
al@426
|
416 for fs in $(blkid | sort | sed 's/:.*//'); do
|
pascal@373
|
417 set -- $(df -h | grep "^$fs ")
|
pascal@343
|
418 size=$2
|
pascal@343
|
419 used=$3
|
pascal@343
|
420 av=$4
|
pascal@375
|
421 grep "^$fs " /proc/mounts | grep -q "[, ]ro[, ]" &&
|
pascal@375
|
422 av="<del>$av</del>"
|
pascal@343
|
423 pct=$5
|
pascal@343
|
424 mp=$6
|
al@419
|
425
|
al@419
|
426 # action
|
pascal@344
|
427 action="mount"
|
pascal@344
|
428 [ -n "$mp" ] && action="umount"
|
pascal@570
|
429 type=$(blkid $fs | sed '/ TYPE=/!d;s/.* TYPE="\([^"]*\).*/\1/')
|
pascal@570
|
430 [ -n "$type" ] || continue
|
pascal@344
|
431 [ "$type" == "swap" ] && action="swapon"
|
pascal@344
|
432 if grep -q "^$fs " /proc/swaps; then
|
pascal@344
|
433 action="swapoff"
|
pascal@344
|
434 set -- $(grep "^$fs " /proc/swaps)
|
pascal@364
|
435 size=$(blk2h $(($3*2)))
|
pascal@364
|
436 used=$(blk2h $(($4*2)))
|
pascal@364
|
437 av=$(blk2h $((2*($3-$4))))
|
pascal@344
|
438 pct=$(((100*$4)/$3))%
|
pascal@344
|
439 mp=swap
|
pascal@344
|
440 fi
|
al@419
|
441
|
al@419
|
442 # size
|
pascal@364
|
443 [ -z "$size" ] &&
|
pascal@622
|
444 size="$(blk2h $(cat /sys/block/${fs##*/}/size /sys/block/*/${fs##*/}/size))"
|
al@419
|
445
|
al@419
|
446 # image
|
al@558
|
447 disktype="@hdd@"
|
pascal@622
|
448 case "$(cat /sys/block/${fs##*/}/removable 2>/dev/null ||
|
al@419
|
449 cat /sys/block/${fs:5:3}/removable 2>/dev/null)" in
|
al@558
|
450 1) disktype="@removable@" ;;
|
pascal@373
|
451 esac
|
pascal@622
|
452 case "$(cat /sys/block/${fs##*/}/ro 2>/dev/null ||
|
al@419
|
453 cat /sys/block/${fs:5:3}/ro 2>/dev/null)" in
|
al@558
|
454 1) disktype="@cd@" ;;
|
pascal@373
|
455 esac
|
al@419
|
456
|
pascal@620
|
457 # boot flag
|
pascal@622
|
458 dsk="${fs##*/}"
|
pascal@620
|
459 case " $bootdevs " in *\ $fs\ *) dsk="<i>$dsk</i>";; esac
|
pascal@620
|
460
|
pascal@622
|
461 radio="<input type=\"radio\" name=\"device\" value=\"$action $fs\" id=\"${fs##*/}\"/>"
|
pascal@473
|
462 [ "$REMOTE_USER" == "root" ] || radio=""
|
al@419
|
463 cat <<EOT
|
al@419
|
464 <tr>
|
pascal@473
|
465 <td>$radio<!--
|
pascal@622
|
466 --><label for="${fs##*/}" data-icon="$disktype"> $dsk</label></td>
|
al@419
|
467 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
|
al@419
|
468 <td>$type</td>
|
al@419
|
469 <td>$size</td>
|
al@419
|
470 <td>$av</td>
|
pascal@343
|
471 EOT
|
pascal@343
|
472 if [ -n "$pct" ]; then
|
al@419
|
473 cat <<EOT
|
al@419
|
474 <td class="meter"><meter min="0" max="100" value="${pct%%%}" low="70"
|
al@419
|
475 high="90" optimum="10"></meter>
|
al@419
|
476 <span>$used - $pct</span>
|
al@419
|
477 </td>
|
pascal@343
|
478 EOT
|
pascal@343
|
479 else
|
al@419
|
480 cat <<EOT
|
al@419
|
481 <td> </td>
|
pascal@343
|
482 EOT
|
pascal@343
|
483 fi
|
al@419
|
484 cat <<EOT
|
al@419
|
485 <td>$mp</td>
|
al@419
|
486 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
|
al@419
|
487 </tr>
|
pankso@153
|
488 EOT
|
pankso@153
|
489 done
|
al@419
|
490 cat <<EOT
|
al@419
|
491 </tbody>
|
al@419
|
492 </table>
|
pascal@433
|
493 EOT
|
pascal@433
|
494 [ "$REMOTE_USER" == "root" ] && cat <<EOT
|
al@419
|
495 $(lib crypto input)
|
al@363
|
496
|
al@419
|
497 <footer>
|
al@419
|
498 <button type="submit">mount / umount</button> -
|
al@443
|
499 $(_ 'new mount point:') <input type="text" name="mountpoint" value="/media/usbdisk"/> -
|
al@443
|
500 <input type="checkbox" name="readonly" id="ro"><label for="ro"> $(_ 'read-only')</label>
|
al@419
|
501 </footer>
|
pascal@433
|
502 EOT
|
pascal@433
|
503 cat <<EOT
|
al@419
|
504 </form>
|
al@419
|
505 </section>
|
al@363
|
506 EOT
|
al@363
|
507
|
al@419
|
508
|
al@419
|
509 #
|
al@419
|
510 # /etc/fstab
|
al@419
|
511 #
|
al@419
|
512 cat <<EOT
|
al@419
|
513 <section>
|
al@426
|
514 <header>
|
al@443
|
515 $(_ 'Filesystems table')
|
pascal@523
|
516 $(edit_button /etc/fstab)
|
al@426
|
517 </header>
|
al@419
|
518 <table class="wide zebra center">
|
al@419
|
519 <thead>
|
al@419
|
520 <tr>
|
al@443
|
521 <td>$(_ 'Disk')</td>
|
al@443
|
522 <td>$(_ 'Mount point')</td>
|
al@443
|
523 <td>$(_ 'Type')</td>
|
al@443
|
524 <td>$(_ 'Options')</td>
|
al@443
|
525 <td>$(_ 'Freq')</td>
|
al@443
|
526 <td>$(_ 'Pass')</td>
|
al@419
|
527 </tr>
|
al@419
|
528 </thead>
|
al@419
|
529 <tbody>
|
al@419
|
530 EOT
|
al@419
|
531
|
al@419
|
532 grep -v '^#' /etc/fstab | awk '{
|
al@419
|
533 print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4
|
al@419
|
534 print "</td><td>" $5 "</td><td>" $6 "</td></tr>"
|
al@419
|
535 }
|
al@363
|
536 END{print "</tbody></table>"}'
|
al@363
|
537
|
al@419
|
538 cat <<EOT
|
al@419
|
539 </section>
|
al@419
|
540 EOT
|
al@363
|
541
|
al@363
|
542
|
al@419
|
543 #
|
al@419
|
544 # Loop device management GUI
|
al@419
|
545 #
|
al@419
|
546 cat <<EOT
|
al@419
|
547 <section>
|
al@443
|
548 <header>$(_ 'Loop devices')</header>
|
al@419
|
549
|
al@419
|
550 <form action="#loop" class="wide">
|
pascal@429
|
551 <div class="scroll">
|
pascal@429
|
552 <table id="loop" class="wide zebra scroll">
|
al@419
|
553 <thead>
|
al@419
|
554 <tr>
|
al@443
|
555 <td>$(_ 'Device')</td>
|
al@443
|
556 <td>$(_ 'Backing file')</td>
|
pascal@497
|
557 <td>$(_ 'Size')</td>
|
al@443
|
558 <td>$(_ 'Access')</td>
|
al@443
|
559 <td>$(_ 'Offset')</td>
|
al@419
|
560 </tr>
|
al@419
|
561 </thead>
|
al@419
|
562 <tbody>
|
pascal@373
|
563 EOT
|
pascal@425
|
564 for devloop in $(ls /dev/*loop[0-9]*); do
|
pascal@622
|
565 loop="${devloop##*/}"
|
pascal@497
|
566 dir=/sys/block/$loop
|
pascal@497
|
567 case "$(cat $dir/ro 2>/dev/null)" in
|
al@443
|
568 0) ro="$(_ "read/write")" ;;
|
al@443
|
569 1) ro="$(_ "read only")" ;;
|
pascal@373
|
570 *) ro="" ;;
|
pascal@373
|
571 esac
|
pascal@497
|
572 size=$(blk2h $(cat $dir/size))
|
pascal@497
|
573 [ "$size" == "0.0K" ] && size="" && ro=""
|
pascal@497
|
574 set -- $(losetup $devloop)
|
pascal@497
|
575 set -- "${3:-$(cat $dir/loop/backing_file)}" "${2:-$(cat $dir/loop/offset)}" ${ro// / }
|
al@419
|
576 cat <<EOT
|
al@419
|
577 <tr><td><input type="radio" name="loopdev" value="$devloop" id="$loop"/><!--
|
al@558
|
578 --><label for="$loop" data-icon="@loopback@">$loop</label></td>
|
pascal@497
|
579 <td>$1</td><td>$size</td><td align="center">$3</td><td align="right">$2</td>
|
al@419
|
580 </tr>
|
pascal@373
|
581 EOT
|
pascal@373
|
582 done
|
al@419
|
583 cat <<EOT
|
al@419
|
584 </tbody>
|
al@419
|
585 </table>
|
pascal@429
|
586 </div>
|
al@419
|
587
|
pascal@373
|
588 $(lib crypto input)
|
al@419
|
589
|
al@419
|
590 <footer>
|
al@558
|
591 <button type="submit" data-icon="@ok@">$(_ 'Setup')</button> -
|
al@443
|
592 $(_ 'new backing file:') <input type="text" name="backingfile"/> -
|
al@443
|
593 $(_ 'offset in bytes:') <input type="text" name="offset" value="0" size="8"/> -
|
al@443
|
594 <input type="checkbox" name="readonly" id="ro"/><label for="ro">$(_ 'read only')</label>
|
al@419
|
595 </footer>
|
al@419
|
596 </form>
|
al@419
|
597 </section>
|
pascal@373
|
598 EOT
|
pascal@373
|
599
|
al@419
|
600
|
al@419
|
601 #
|
al@419
|
602 # System memory
|
al@419
|
603 #
|
al@419
|
604 mem_total=$(free -m | awk '$1 ~ "M" {print $2}')
|
al@419
|
605 mem_used=$((100 * $(free -m | awk '$1 ~ "+" {print $3}') / mem_total))
|
al@419
|
606 mem_buff=$((100 * $(free -m | awk '$1 ~ "M" {print $6}') / mem_total))
|
al@419
|
607 mem_free=$((100 - mem_used - mem_buff))
|
al@419
|
608
|
al@419
|
609 cat <<EOT
|
al@419
|
610 <section>
|
al@443
|
611 <header>$(_ 'System memory')</header>
|
al@419
|
612
|
al@419
|
613 <div class="sysmem"><!--
|
al@443
|
614 --><span class="sysmem_used" style="width: ${mem_used}%" title="$(_ 'Used')" ><span>${mem_used}%</span></span><!--
|
al@419
|
615 EOT
|
al@419
|
616 [ $mem_buff != 0 ] && cat <<EOT
|
al@443
|
617 --><span class="sysmem_buff" style="width: ${mem_buff}%" title="$(_ 'Buffers')"><span>${mem_buff}%</span></span><!--
|
al@419
|
618 EOT
|
al@419
|
619 cat <<EOT
|
al@443
|
620 --><span class="sysmem_free" style="width: ${mem_free}%" title="$(_ 'Free')" ><span>${mem_free}%</span></span><!--
|
al@419
|
621 --></div>
|
al@419
|
622
|
al@419
|
623 <table class="wide zebra center">
|
al@419
|
624 <thead>
|
al@419
|
625 <tr>
|
al@419
|
626 <td> </td>
|
al@419
|
627 <td>total</td>
|
al@419
|
628 <td>used</td>
|
al@419
|
629 <td>free</td>
|
al@419
|
630 <td>shared</td>
|
al@419
|
631 <td>buffers</td>
|
al@419
|
632 </tr>
|
al@419
|
633 </thead>
|
al@419
|
634 <tbody>
|
al@303
|
635 EOT
|
al@303
|
636
|
al@419
|
637 free -m | awk '
|
al@419
|
638 $1 ~ "M" {print "<tr><td>"$1"</td><td>"$2"</td><td>"$3"</td><td>"$4"</td><td>"$5"</td><td>"$6"</td></tr>"}
|
al@419
|
639 $1 ~ "+" {print "<tr><td>"$1 $2"</td><td></td><td>"$3"</td><td>"$4"</td><td></td><td></td></tr>"}
|
al@419
|
640 $1 ~ "S" {print "<tr><td>"$1"</td><td>"$2"</td><td>"$3"</td><td>"$4"</td><td></td><td></td></tr>"}'
|
al@303
|
641
|
al@419
|
642 cat <<EOT
|
al@419
|
643 </tbody>
|
al@419
|
644 </table>
|
al@419
|
645 </section>
|
al@419
|
646 EOT
|
al@303
|
647
|
al@419
|
648
|
al@419
|
649 #
|
al@419
|
650 # lspci and lsusb summary tables
|
al@419
|
651 #
|
al@419
|
652 cat <<EOT
|
al@419
|
653 <section>
|
al@419
|
654 <header>lspci</header>
|
al@419
|
655 $(lspci_table)
|
al@419
|
656 </section>
|
al@419
|
657
|
al@419
|
658
|
al@419
|
659 <section>
|
al@419
|
660 <header>lsusb</header>
|
al@419
|
661 $(lsusb_table)
|
al@419
|
662 </section>
|
al@303
|
663 EOT
|
al@419
|
664 ;;
|
pankso@46
|
665 esac
|
pankso@46
|
666
|
pankso@46
|
667 xhtml_footer
|
pankso@46
|
668 exit 0
|