tazpanel view boot.cgi @ rev 567

hardware.cgi: fix detect-usb output
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 14 10:14:04 2016 +0100 (2016-02-14)
parents a15373a181ff
children 21f625d5ebbb
line source
1 #!/bin/sh
2 #
3 # Boot CGI script - All what happens before login (grub, rcS, slim)
4 #
5 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
6 #
9 # Common functions from libtazpanel and source main boot config file.
11 . lib/libtazpanel
12 . /etc/rcS.conf
13 get_config
14 header
16 TITLE=$(_ 'Boot')
19 # Print last 40 lines of given file with "more" link
21 loghead() {
22 case $2 in
23 htmlize) tail -n40 $1 | htmlize;;
24 *) tail -n40;;
25 esac
26 [ $(wc -l < $1) -gt 40 ] && cat <<EOT
27 <hr/><a data-icon="@view@" href="index.cgi?file=$1">$(_ 'Show more...')</a>
28 EOT
29 }
32 #
33 # Commands
34 #
36 case " $(GET) " in
37 *\ syslog\ *)
38 logtype="$(GET syslog)"
39 [ "${logtype:-syslog}" == 'syslog' ] && logtype='messages'
40 xhtml_header "$(_ 'System logs')"
42 cat <<EOT
43 <section>
44 <header>
45 $(_ 'System logs')
46 EOT
48 edit_button /etc/syslog.conf syslog.conf
50 cat <<EOT
51 </header>
53 <ul id="tabs">
54 EOT
55 for i in $(sed '/var\/log/!d;s|.*/log/||' /etc/syslog.conf); do
56 unset act
57 [ "$i" == "$logtype" ] && act=' class="active"'
58 cat <<EOT
59 <li$act><a href="?syslog=$i" title="$(sed "/$i$/!d;s/[\t ].*//" /etc/syslog.conf)">$i</a></li>
60 EOT
61 done
62 cat <<EOT
63 </ul>
65 <pre style="overflow-x: auto">$(syntax_highlighter kernel < /var/log/$logtype | \
66 loghead /var/log/$logtype)</pre>
67 </section>
68 EOT
69 ;;
72 *\ log\ *)
73 unset actboot actslim actxlog actkernel colors
74 case "$(GET log)" in
75 boot)
76 actboot=' class="active"'
77 output="$(filter_taztools_msgs < /var/log/boot.log)"
78 colors=' class="term log"';;
79 slim)
80 actslim=' class="active"'
81 output="$(loghead /var/log/slim.log htmlize)" ;;
82 xlog)
83 actxlog=' class="active"'
84 output="$(syntax_highlighter xlog < /var/log/Xorg.0.log | loghead /var/log/Xorg.0.log)" ;;
85 *)
86 actkernel=' class="active"'
87 output="$(syntax_highlighter kernel < /var/log/dmesg.log | loghead /var/log/dmesg.log)" ;;
88 esac
90 xhtml_header "$(_ 'Boot log files')"
91 cat <<EOT
92 <ul id="tabs">
93 <li$actkernel><a href="?log=kernel">$(_ 'Kernel messages')</a></li>
94 <li$actboot ><a href="?log=boot" >$(_ 'Boot scripts' )</a></li>
95 <li$actxlog ><a href="?log=xlog" >$(_ 'X server' )</a></li>
96 <li$actslim ><a href="?log=slim" >$(_ 'X session' )</a></li>
97 </ul>
99 <section>
100 <div>
101 <pre$colors style="overflow-x: auto">$output</pre>
102 </div>
103 </section>
104 EOT
105 ;;
108 *\ daemons\ *)
109 #
110 # Everything until user login
111 #
112 # Start and stop a daemon.
113 # (I think we don't need a 'restart' since 2 clicks and you are done)
114 . /etc/rcS.conf
115 xhtml_header "$(_ 'Manage daemons')"
117 cat <<EOT
118 <p>$(_ 'Check, start and stop daemons on SliTaz')</p>
119 EOT
120 daemon=$(GET daemons)
121 case "$daemon" in
122 start=*)
123 sleep 1
124 /etc/init.d/${daemon#start=} start | log ;;
125 stop=*)
126 /etc/init.d/${daemon#stop=} stop | log ;;
127 pid=*)
128 echo "<pre>"
129 ps ww | sed 1q
130 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
131 ps ww | sed "/^ $i /!d"
132 done
133 echo "</pre>" ;;
134 esac
136 # Daemon list
137 cat <<EOT
138 <section>
139 <table class="zebra wide daemons">
140 <thead>
141 <tr>
142 <td>$(_ 'Name')</td>
143 <td>$(_ 'Description')</td>
144 <td>$(_ 'Configuration')</td>
145 <td>$(_ 'Status')</td>
146 <td>$(_ 'Action')</td>
147 <td>$(_ 'PID')</td>
148 </tr>
149 </thead>
150 <tbody>
151 EOT
152 cd /etc/init.d
153 list="$(ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d -e /firewall/d)"
154 for name in $list; do
155 unset pkg pid status SHORT_DESC boot cfg
156 echo '<tr>'
157 # Name
158 echo "<td>$name</td>"
159 # First check if daemon is started at boottime
160 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
161 # Standard SliTaz busybox daemons and firewall
162 echo -n "<td>"
163 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
164 for i in /etc/slitaz /etc /etc/$name ; do
165 for j in $i/$name.conf $i/${name}d.conf ; do
166 [ -s $j ] && cfg="edit::$j|$cfg"
167 done
168 done
169 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
170 case "$name" in
171 firewall)
172 _ 'SliTaz Firewall with iptable rules' ;;
173 httpd)
174 _ 'Small and fast web server with CGI support' ;;
175 ntpd)
176 cfg="man|help|edit::/etc/ntp.conf|options"
177 _ 'Network time protocol daemon' ;;
178 ftpd)
179 cfg="man|help|edit::/etc/inetd.conf"
180 _ 'Anonymous FTP server' ;;
181 udhcpd)
182 cfg="man|help|edit|options"
183 _ 'Busybox DHCP server' ;;
184 syslogd|klogd)
185 cfg="man|help|edit::/etc/syslog.conf|options"
186 _ 'Linux Kernel log daemon' ;;
187 crond)
188 # FIXME crontab
189 _ 'Execute scheduled commands' ;;
190 dnsd)
191 cfg="man|help|edit|options::-d"
192 _ 'Small static DNS server daemon' ;;
193 tftpd)
194 cfg="man|help|edit::/etc/inetd.conf|options"
195 _ 'Transfer a file on tftp request' ;;
196 lpd)
197 cfg="man|help|options"
198 _ 'Printer daemon' ;;
199 inetd)
200 _ 'Listen for network connections and launch programs' ;;
201 zcip)
202 cfg="man|help|edit:Script:/etc/zcip.script|options::eth0 /etc/zcip.script"
203 _ 'Manage a ZeroConf IPv4 link-local address' ;;
204 *)
205 # Description from receipt
206 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
207 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
208 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
209 if [ "$pkg" ]; then
210 unset SHORT_DESC TAZPANEL_DAEMON
211 #FIXME $PKGS_DB
212 . $LOCALSTATE/installed/$pkg/receipt
213 echo -n "$SHORT_DESC"
214 cfg="${TAZPANEL_DAEMON:-$cfg|web::$WEB_SITE}"
215 else
216 echo -n "----"
217 fi ;;
218 esac
219 echo "</td>"
220 # Attempt to get daemon status
221 pidfile=$(find /run /var/run -name *$name*.pid)
222 [ "$pidfile" ] && pid=$(cat $pidfile)
223 # Dbus
224 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
225 # Apache
226 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
227 # Pidof works for many daemons
228 [ "$pid" ] || pid=$(pidof $name)
230 echo -n "<td style='white-space: nowrap'>"
231 if [ -n "$cfg" ]; then
232 IFS="|"
233 for i in $cfg ; do
234 IFS=":"
235 set -- $i
236 case "$1" in
237 edit)
238 cat <<EOT
239 <a href="index.cgi?file=${3:-/etc/$name.conf}&amp;action=edit" title="${2:-$name configuration} in ${3:-/etc/$name.conf}" data-img="@conf@"></a>
240 EOT
241 ;;
242 options)
243 key=$(echo -n $name | tr [a-z] [A-Z])_OPTIONS
244 cat <<EOT
245 <a href="index.cgi?file=/etc/daemons.conf&amp;action=setvar&amp;var=$key&amp;default=$3" title="${2:-$key}" data-img="@opt@"></a>
246 EOT
247 ;;
248 man)
249 cat <<EOT
250 <a href="index.cgi?exec=man ${3:-$name}&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Manual}" data-img="@man@"></a>
251 EOT
252 ;;
253 help)
254 help='--help'
255 case $name in
256 cupsd|dropbear|gpm|slim|wpa_supplicant) help='-h'
257 esac
258 cat <<EOT
259 <a href="index.cgi?exec=$(which ${3:-$name}) $help&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Help}" data-img="@help@"></a>
260 EOT
261 ;;
262 web) cat <<EOT
263 <a href="${i#$1:$2:}" title="${2:-$name website:} ${i#$1:$2:}" target="_blank" data-img="@web@"></a>
264 EOT
265 ;;
266 esac
267 done
268 fi
269 echo "</td>"
270 if [ "$pid" ]; then
271 cat <<EOT
272 <td><span title="$(_ 'Started')" data-img="@on@"></span></td>
273 <td><a href="?daemons=stop=$name" title="$(_ 'Stop')" data-img="@stop@"></a></td>
274 <td>
275 EOT
276 for i in $pid; do
277 cat <<EOT
278 <a href="?daemons=pid=$i">$i</a>
279 EOT
280 done
281 else
282 cat <<EOT
283 <td><span title="$(_ 'Stopped')" data-img="@off@"></span></td>
284 <td><a href="?daemons=start=$name" title="$(_ 'Start')" data-img="@start@"></a></td>
285 <td>-----
286 EOT
287 fi
288 echo '</td></tr>'
289 done
290 echo '</thead></table></section>' ;;
293 *\ grub\ *)
294 GRUBMENU="/boot/grub/menu.lst"
295 if [ "$(GET splash)" ]; then
296 default=$(GET default)
297 timeout=$(GET timeout)
298 splash=$(GET splash)
299 sed -i \
300 -e s"|default .*|default $default # new|" \
301 -e s"|timeout .*|timeout $timeout|" \
302 -e s"|splashimage=.*|splashimage=$splash|" \
303 $GRUBMENU
304 fi
305 default=$(grep ^default $GRUBMENU | cut -d' ' -f2)
306 timeout=$(grep ^timeout $GRUBMENU | cut -d' ' -f2)
307 splash=$(grep ^splashimage $GRUBMENU | cut -d' ' -f2)
309 xhtml_header "$(_ 'GRUB Boot loader')"
310 cat <<EOT
311 <p>$(_ 'The first application started when the computer powers on')</p>
313 <form class="wide">
314 <section>
315 <div>
316 <input type="hidden" name="grub"/>
317 <table>
318 <tr><td>$(_ 'Default entry:')</td>
319 <td><input type="text" name="default" value="${default##*=}"/></td></tr>
320 <tr><td>$(_ 'Timeout:')</td>
321 <td><input type="text" name="timeout" value="${timeout##*=}"/></td></tr>
322 <tr><td>$(_ 'Splash image:')</td>
323 <td><input type="text" name="splash" value="${splash##*=}" size="40"/></td></tr>
324 </table>
325 </div>
326 <footer>
327 <button type="submit" data-icon="@ok@">$(_ 'Change')</button>
328 </footer>
329 </section>
330 </form>
332 <form action="index.cgi">
333 <input type="hidden" name="file" value="$GRUBMENU"/>
334 <button data-icon="@text@">$(_ 'View or edit menu.lst')</button>
335 </form>
338 <section>
339 <header>$(_ 'Boot entries')</header>
340 <div>
341 EOT
344 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU | \
345 sed -e "s|^$||g" | \
346 sed -e "s|^title|</pre></div>\n</section>\n\n<section>\n\t<header>$(_ 'Entry') #</header>\n<div><pre style=\"white-space:pre-wrap\">\0|g" | \
347 sed '/^[ \t]*$/d' | \
348 tail -q -n +2)"</pre>"
350 entry='-1'
351 echo "$menu" | while read line
352 do
353 if [ -n "$(echo $line | grep '#</header>')" ]; then
354 entry=$(($entry + 1))
355 fi
356 echo $line | sed "s|#</header>|$entry</header>|"
357 done
359 echo '</section>'
362 # Here we could check if an entry for gpxe is present if not
363 # display a form to add it.
364 [ -f "/boot/gpxe" ] && cat <<EOT
365 <section>
366 <header>gPXE</header>
367 <div>$(_ 'Web boot is available with gPXE')</div>
368 </section>
369 EOT
370 ;;
373 *\ iso\ *)
374 xhtml_header
375 iso=$(POST iso); [ -s "$iso" ] || unset iso
376 action=$(POST action); [ "$action" ] || action=$(GET action)
377 workdir=$(POST workdir)
378 [ -d $workdir ] || workdir=$(dirname $workdir)
379 [ -w $workdir -a "$workdir" ] || workdir=/tmp
381 echo "<h2>$(_ 'ISO mine')</h2>"
383 [ "$iso" ] || msg err "$(_ 'Invalid ISO image.')"
385 if [ "$iso" -a "$action" -a "$action" != "nop" ]; then
386 case "$action" in
387 install*) dev=$(POST instdev) ;;
388 *) dev=$(POST usbkeydev) ;;
389 esac
390 cd $workdir
391 cat <<EOT
392 <section>
393 <pre>
394 $(taziso $iso $action $dev 2>&1 | htmlize)
395 </pre>
396 </section>
397 EOT
398 fi
399 cat <<EOT
400 <section>
401 <form method="post" action="?iso" class="wide">
402 <table>
403 <tr><td>$(_ 'ISO image file full path')
404 <span data-img="@info@" title="$(_ 'set /dev/cdrom for a physical CD-ROM')"></span>
405 </td>
406 <td>$(file_chooser "iso" "$iso")</td></tr>
407 <tr><td>$(_ 'Working directory')</td>
408 <td>$(dir_chooser "workdir" "$workdir")</td></tr>
409 </td></tr>
410 <tr><td>$(_ 'Target partition')
411 <span data-img="@info@" title="$(_ 'For hard disk installation only. Will create /slitaz tree and keep other files. No partitioning and no formatting.')"></span>
412 </td>
413 <td><select name="instdev">
414 <option value="/dev/null">$(_ 'Choose a partition (optional)')</option>
415 EOT
416 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
417 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
418 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
419 while read dev label type; do
420 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
421 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
422 done
423 cat <<EOT
424 </select></td></tr>
425 <tr><td>$(_ 'USB key device')
426 <span data-img="@info@" title="$(_ 'For USB boot key only. Will erase the full device.')"></span>
427 </td>
428 <td><select name="usbkeydev">
429 <option value="/dev/null">$(_ 'Choose a USB key (optional)')</option>
430 EOT
431 grep -l 1 /sys/block/*/removable | \
432 sed 's|/sys/block/\(.*\)/removable|\1|' | while read dev; do
433 grep -qs 1 /sys/block/$dev/ro && continue
434 [ -d /sys/block/$dev/device/scsi_disk ] || continue
435 echo -n "<option value=\"/dev/$dev\">/dev/$dev "
436 echo -n "$(blk2h < /sys/block/$dev/size) "
437 echo -n "$(cat /sys/block/$dev/device/model 2>/dev/null) "
438 blkid | grep $dev | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/"\1"/;q'
439 echo "</option>"
440 done
441 cat <<EOT
442 </select></td></tr>
443 </table>
444 <footer>
445 EOT
447 if [ "$iso" ]; then
448 cat <<EOT
449 <select name="action">
450 <option value="nop">$(_ 'Choose an action')</option>
451 $(taziso $iso list | sed -e \
452 's/"\(.*\)"[\t ]*"\(.*\)"/<option value="\1\">\2<\/option>/' -e \
453 "s|value=\"$action\"|& selected|")
454 </select>
455 EOT
456 elif [ "$action" ]; then
457 cat <<EOT
458 <input type="hidden" name="action" value="$action" />
459 EOT
460 fi
462 cat <<EOT
463 <button data-icon="@cd@" name="mine">$(_ 'Mine')</button>
464 </footer>
465 </form>
466 </section>
467 EOT
468 ;;
471 *)
472 #
473 # Default content with summary
474 #
475 . /etc/rcS.conf
476 xhtml_header "$(_ 'Boot &amp; Start services')"
477 cat <<EOT
478 <p>$(_ 'Everything that happens before user login')</p>
480 <form>
481 <button name="log" data-icon="@logs@">$(_ 'Boot logs')</button>
482 <button name="syslog" data-icon="@logs@">$(_ 'System logs')</button>
483 <button name="daemons" data-icon="@daemons@" data-root>$(_ 'Manage daemons')</button>
484 EOT
485 [ "$REMOTE_USER" == "root" -a -x /usr/bin/taziso ] && cat <<EOT
486 <button name="iso" data-icon="@cd@">$(_ 'ISO mine')</button>
487 EOT
488 [ -w /boot/grub/menu.lst ] && cat <<EOT
489 <button name="grub" data-icon="@grub@">$(_ 'Boot loader')</button>
490 EOT
491 cat <<EOT
492 </form>
495 <section>
496 <header>$(_ 'Configuration files')</header>
497 <form action="index.cgi" class="wide">
498 <table>
499 <tr><td>$(_ 'Main configuration file:') <b>rcS.conf</b></td>
500 <td><button name="file" value="/etc/rcS.conf" data-icon="@view@">$(_ 'View')</button></td></tr>
501 <tr><td>$(_ 'Login manager settings:') <b>slim.conf</b></td>
502 <td><button name="file" value="/etc/slim.conf" data-icon="@view@">$(_ 'View')</button></td></tr>
503 </table>
504 </form>
505 </section>
508 <section style="overflow-x: auto">
509 <header>$(_ 'Kernel cmdline')</header>
510 <pre>$(cat /proc/cmdline)</pre>
511 </section>
514 <section>
515 <header>
516 $(_ 'Local startup commands')
517 $(edit_button /etc/init.d/local.sh)
518 </header>
519 <pre><code class="language-bash">$(htmlize < /etc/init.d/local.sh)</code></pre>
520 </section>
521 EOT
522 ;;
523 esac
525 xhtml_footer
526 exit 0