tazpanel view boot.cgi @ rev 458

boot.cgi/ISO mine: install in Linux partition
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 13 11:11:51 2015 +0200 (2015-04-13)
parents 864a144f1b14
children 5d33b8aaf36d
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=$(_ 'TazPanel - 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 }
31 disksize()
32 {
33 size=$(($(cat /sys/block/$1/size)/2048))
34 for i in MB GB TB ; do
35 [ $size -lt 2048 ] && break
36 size=$(((512+$size)/1024))
37 done
38 echo "$size$i"
39 }
41 #
42 # Commands
43 #
45 case " $(GET) " in
46 *\ syslog\ *)
47 logtype="$(GET syslog)"
48 [ "${logtype:-syslog}" == "syslog" ] && logtype=messages
49 xhtml_header
50 [ -w /etc/syslog.conf ] && cat <<EOT
51 <a href="index.cgi?file=/etc/syslog.conf&amp;action=edit" data-img="conf"></a>syslog.conf
52 EOT
53 cat <<EOT
54 <h2>$(_ 'System logs')</h2>
56 <ul id="tabs">
57 EOT
58 for i in $(sed '/var\/log/!d;s|.*/log/||' /etc/syslog.conf); do
59 unset act
60 [ "$i" == "$logtype" ] && act=' class="active"'
61 cat <<EOT
62 <li$act><a href="?syslog=$i" title="$(sed "/$i$/!d;s/[\t ].*//" /etc/syslog.conf)">$i</a></li>
63 EOT
64 done
65 cat <<EOT
66 </ul>
68 <section>
69 <div>
70 <pre>$(syntax_highlighter kernel < /var/log/$logtype | \
71 loghead /var/log/$logtype)</pre>
72 </div>
73 </section>
74 EOT
75 ;;
76 *\ log\ *)
77 unset actboot actslim actxlog actkernel colors
78 case "$(GET log)" in
79 boot)
80 actboot=' class="active"'
81 output="$(filter_taztools_msgs < /var/log/boot.log)"
82 colors=' class="term log"';;
83 slim)
84 actslim=' class="active"'
85 output="$(loghead /var/log/slim.log htmlize)" ;;
86 xlog)
87 actxlog=' class="active"'
88 output="$(syntax_highlighter xlog < /var/log/Xorg.0.log | loghead /var/log/Xorg.0.log)" ;;
89 *)
90 actkernel=' class="active"'
91 output="$(syntax_highlighter kernel < /var/log/dmesg.log | loghead /var/log/dmesg.log)" ;;
92 esac
93 xhtml_header
94 cat <<EOT
95 <h2>$(_ 'Boot log files')</h2>
97 <ul id="tabs">
98 <li$actkernel><a href="?log=kernel">$(_ 'Kernel messages')</a></li>
99 <li$actboot ><a href="?log=boot" >$(_ 'Boot scripts' )</a></li>
100 <li$actxlog ><a href="?log=xlog" >$(_ 'X server' )</a></li>
101 <li$actslim ><a href="?log=slim" >$(_ 'X session' )</a></li>
102 </ul>
104 <section>
105 <div>
106 <pre$colors>$output</pre>
107 </div>
108 </section>
109 EOT
110 ;;
113 *\ daemons\ *)
114 #
115 # Everything until user login
116 #
117 # Start and stop a daemon.
118 # (I think we don't need a 'restart' since 2 clicks and you are done)
119 . /etc/rcS.conf
120 xhtml_header
122 cat <<EOT
123 <h2>$(_ 'Manage daemons')</h2>
125 <p>$(_ 'Check, start and stop daemons on SliTaz')</p>
126 EOT
127 daemon=$(GET daemons)
128 case "$daemon" in
129 start=*)
130 sleep 1
131 /etc/init.d/${daemon#start=} start | log ;;
132 stop=*)
133 /etc/init.d/${daemon#stop=} stop | log ;;
134 pid=*)
135 echo "<pre>"
136 ps ww | sed 1q
137 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
138 ps ww | sed "/^ $i /!d"
139 done
140 echo "</pre>" ;;
141 esac
143 # Daemon list
144 cat <<EOT
145 <section>
146 <table class="zebra wide daemons">
147 <thead>
148 <tr>
149 <td>$(_ 'Name')</td>
150 <td>$(_ 'Description')</td>
151 <td>$(_ 'Configuration')</td>
152 <td>$(_ 'Status')</td>
153 <td>$(_ 'Action')</td>
154 <td>$(_ 'PID')</td>
155 </tr>
156 </thead>
157 <tbody>
158 EOT
159 cd /etc/init.d
160 list="$(ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d -e /firewall/d)"
161 for name in $list; do
162 unset pkg pid status SHORT_DESC boot cfg
163 echo '<tr>'
164 # Name
165 echo "<td>$name</td>"
166 # First check if daemon is started at boottime
167 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
168 # Standard SliTaz busybox daemons and firewall
169 echo -n "<td>"
170 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
171 for i in /etc/slitaz /etc /etc/$name ; do
172 [ -s $i/$name.conf ] && cfg="edit::$i/$name.conf|$cfg"
173 done
174 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
175 case "$name" in
176 firewall)
177 _ 'SliTaz Firewall with iptable rules' ;;
178 httpd)
179 _ 'Small and fast web server with CGI support' ;;
180 ntpd)
181 _ 'Network time protocol daemon' ;;
182 ftpd)
183 cfg="man|help|edit::/etc/inetd.conf"
184 _ 'Anonymous FTP server' ;;
185 udhcpd)
186 _ 'Busybox DHCP server' ;;
187 syslogd|klogd)
188 _ 'Linux Kernel log daemon' ;;
189 crond)
190 # FIXME crontab
191 _ 'Execute scheduled commands' ;;
192 dnsd)
193 cfg="man|help|edit|options::-d"
194 _ 'Small static DNS server daemon' ;;
195 tftpd)
196 cfg="man|help|edit::/etc/inetd.conf"
197 _ 'Transfer a file on tftp request' ;;
198 inetd)
199 _ 'Listen for network connections and launch programs' ;;
200 zcip)
201 cfg="man|help|edit:Script:/etc/zcip.script|options::eth0 /etc/zcip.script"
202 _ 'Manage a ZeroConf IPv4 link-local address' ;;
203 *)
204 # Description from receipt
205 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
206 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
207 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
208 if [ "$pkg" ]; then
209 unset SHORT_DESC TAZPANEL_DAEMON
210 #FIXME $PKGS_DB
211 . $LOCALSTATE/installed/$pkg/receipt
212 echo -n "$SHORT_DESC"
213 cfg="${TAZPANEL_DAEMON:-$cfg|web::$WEB_SITE}"
214 else
215 echo -n "----"
216 fi ;;
217 esac
218 echo "</td>"
219 # Attempt to get daemon status
220 pidfile=$(find /var/run -name *$name*.pid)
221 [ "$pidfile" ] && pid=$(cat $pidfile)
222 # Dbus
223 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
224 # Apache
225 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
226 # Pidof works for many daemons
227 [ "$pid" ] || pid=$(pidof $name)
229 echo -n "<td style='white-space: nowrap'>"
230 if [ -n "$cfg" ]; then
231 IFS="|"
232 for i in $cfg ; do
233 IFS=":"
234 set -- $i
235 case "$1" in
236 edit)
237 cat <<EOT
238 <a href="index.cgi?file=${3:-/etc/$name.conf}&amp;action=edit" title="${2:-$name Configuration}" data-img="conf"></a>
239 EOT
240 ;;
241 options)
242 key=$(echo -n $name | tr [a-z] [A-Z])_OPTIONS
243 cat <<EOT
244 <a href="index.cgi?file=/etc/daemons.conf&amp;action=setvar&amp;var=$key&amp;default=$3" title="${2:-$key}" data-img="opt"></a>
245 EOT
246 ;;
247 man)
248 cat <<EOT
249 <a href="index.cgi?exec=man ${3:-$name}&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Manual}" data-img="man"></a>
250 EOT
251 ;;
252 help)
253 help='--help'
254 case $name in
255 cupsd|dropbear|gpm|slim|wpa_supplicant) help='-h'
256 esac
257 cat <<EOT
258 <a href="index.cgi?exec=$(which ${3:-$name}) $help&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Help}" data-img="help"></a>
259 EOT
260 ;;
261 web) cat <<EOT
262 <a href="${i#$1:$2:}" title="${2:-$name website:} ${i#$1:$2:}" target="_blank" data-img="web"></a>
263 EOT
264 ;;
265 esac
266 done
267 fi
268 echo "</td>"
269 if [ "$pid" ]; then
270 cat <<EOT
271 <td><span title="$(_ 'Started')" data-img="on"></span></td>
272 <td><a href="?daemons=stop=$name" title="$(_ 'Stop')" data-img="stop"></a></td>
273 <td>
274 EOT
275 for i in $pid; do
276 cat <<EOT
277 <a href="?daemons=pid=$i">$i</a>
278 EOT
279 done
280 else
281 cat <<EOT
282 <td><span title="$(_ 'Stopped')" data-img="off"></span></td>
283 <td><a href="?daemons=start=$name" title="$(_ 'Start')" data-img="start"></a></td>
284 <td>-----
285 EOT
286 fi
287 echo '</td></tr>'
288 done
289 echo '</thead></table></section>' ;;
292 *\ grub\ *)
293 GRUBMENU="/boot/grub/menu.lst"
294 if [ "$(GET splash)" ]; then
295 default=$(GET default)
296 timeout=$(GET timeout)
297 splash=$(GET splash)
298 sed -i \
299 -e s"|default .*|default $default # new|" \
300 -e s"|timeout .*|timeout $timeout|" \
301 -e s"|splashimage=.*|splashimage=$splash|" \
302 $GRUBMENU
303 fi
304 default=$(cat $GRUBMENU | grep ^default | cut -d' ' -f2)
305 timeout=$(cat $GRUBMENU | grep ^timeout | cut -d' ' -f2)
306 splash=$(cat $GRUBMENU | grep ^splashimage | cut -d' ' -f2)
307 xhtml_header
308 cat <<EOT
309 <h2>$(_ 'GRUB Boot loader')</h2>
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)
395 </pre>
396 </section>
397 EOT
398 fi
399 cat <<EOT
400 <section>
401 <form method="post" action="?iso" class="wide">
402 EOT
403 cat <<EOT
404 <table>
405 <tr><td>ISO image file full path
406 <span data-img="info" title="set /dev/cdrom for a physical CD-ROM"></span>
407 </td>
408 <td><input type="text" name="iso" value="$iso" size="50"/></td></tr>
409 <tr><td>Working directory</td>
410 <td><input type="text" name="workdir" value="$workdir" size="50"/></td></tr>
411 <tr><td>Target partition
412 <span data-img="info" title="For hard disk installation only. Will create /slitaz tree and keep other files. No partitioning and no formatting."></span>
413 </td>
414 <td><select name="instdev">
415 <option value="/dev/null">Choose a partition (optional)</option>
416 EOT
417 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
418 sed 's|^/dev/\(.*\):.*LABEL="\([^"]*\).* TYPE="\([^"]*\).*|\1 "\2" \3|' | \
419 while read dev label type; do
420 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label "
421 echo "$(disksize ${dev:0:3}/$dev) $type</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 echo -n "<option value=\"/dev/$dev\">/dev/$dev "
435 echo "$(disksize $dev) $(cat \
436 /sys/block/$i/device/model 2>/dev/null)</option>"
437 done
438 cat <<EOT
439 </select></td></tr>
440 </table>
441 <footer>
442 EOT
444 if [ "$iso" ]; then
445 cat <<EOT
446 <select name="action">
447 <option value="nop">Choose an action</option>
448 $(taziso $iso list | sed -e \
449 's/"\(.*\)"[\t ]*"\(.*\)"/<option value="\1\">\2<\/option>/' -e \
450 "s|value=\"$action\"|& selected|")
451 </select>
452 EOT
453 elif [ "$action" ]; then
454 cat <<EOT
455 <input type="hidden" name="action" value="$action" />
456 EOT
457 fi
459 cat <<EOT
460 <button data-icon="cd" name="mine">Mine</button>
461 </footer>
462 </form>
463 </section>
464 EOT
465 ;;
468 *)
469 #
470 # Default content with summary
471 #
472 . /etc/rcS.conf
473 xhtml_header
474 cat <<EOT
475 <h2>$(_ 'Boot &amp; Start services')</h2>
477 <p>$(_ 'Everything that happens before user login')</p>
479 <form>
480 <button name="log" data-icon="logs" >$(_ 'Boot logs')</button>
481 <button name="syslog" data-icon="logs" >$(_ 'System logs')</button>
482 <button name="daemons" data-icon="daemons" data-root>$(_ 'Manage daemons')</button>
483 EOT
484 [ "$REMOTE_USER" == "root" -a -x /usr/bin/taziso ] && cat <<EOT
485 <button name="iso" data-icon="cd" >$(_ 'ISO mine')</button>
486 EOT
487 [ -w /boot/grub/menu.lst ] && cat <<EOT
488 <button name="grub" data-icon="grub" >$(_ 'Boot loader')</button>
489 EOT
490 cat <<EOT
491 </form>
494 <section>
495 <header>$(_ 'Configuration files')</header>
496 <form action="index.cgi" class="wide">
497 <table>
498 <tr><td>$(_ 'Main configuration file:') <b>rcS.conf</b></td>
499 <td><button name="file" value="/etc/rcS.conf" data-icon="view">$(_ 'View')</button></td></tr>
500 <tr><td>$(_ 'Login manager settings:') <b>slim.conf</b></td>
501 <td><button name="file" value="/etc/slim.conf" data-icon="view">$(_ 'View')</button></td></tr>
502 </table>
503 </form>
504 </section>
507 <section style="overflow-x: auto">
508 <header>$(_ 'Kernel cmdline')</header>
509 <pre>$(cat /proc/cmdline)</pre>
510 </section>
513 <section>
514 <header>
515 $(_ 'Local startup commands')
516 <form action="index.cgi">
517 <input type="hidden" name="file" value="/etc/init.d/local.sh"/>
518 EOT
519 [ -w /etc/init.d/local.sh ] && cat <<EOT
520 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
521 EOT
522 cat <<EOT
523 </form>
524 </header>
525 <pre>$(cat /etc/init.d/local.sh | syntax_highlighter sh)</pre>
526 </section>
527 EOT
528 ;;
529 esac
531 xhtml_footer
532 exit 0