tazpanel view boot.cgi @ rev 520

PROVIDE support in package list report
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 04 11:16:14 2015 +0200 (2015-08-04)
parents 14fdd304f33f
children c0997cc494ed
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 [ -w /etc/syslog.conf ] && cat <<EOT
49 <form action="index.cgi">
50 <input type="hidden" name="file" value="/etc/syslog.conf"/>
51 <button name="action" value="edit" data-icon="edit">syslog.conf</button>
52 </form>
53 EOT
55 cat <<EOT
56 </header>
58 <ul id="tabs">
59 EOT
60 for i in $(sed '/var\/log/!d;s|.*/log/||' /etc/syslog.conf); do
61 unset act
62 [ "$i" == "$logtype" ] && act=' class="active"'
63 cat <<EOT
64 <li$act><a href="?syslog=$i" title="$(sed "/$i$/!d;s/[\t ].*//" /etc/syslog.conf)">$i</a></li>
65 EOT
66 done
67 cat <<EOT
68 </ul>
70 <pre style="overflow-x: auto">$(syntax_highlighter kernel < /var/log/$logtype | \
71 loghead /var/log/$logtype)</pre>
72 </section>
73 EOT
74 ;;
77 *\ log\ *)
78 unset actboot actslim actxlog actkernel colors
79 case "$(GET log)" in
80 boot)
81 actboot=' class="active"'
82 output="$(filter_taztools_msgs < /var/log/boot.log)"
83 colors=' class="term log"';;
84 slim)
85 actslim=' class="active"'
86 output="$(loghead /var/log/slim.log htmlize)" ;;
87 xlog)
88 actxlog=' class="active"'
89 output="$(syntax_highlighter xlog < /var/log/Xorg.0.log | loghead /var/log/Xorg.0.log)" ;;
90 *)
91 actkernel=' class="active"'
92 output="$(syntax_highlighter kernel < /var/log/dmesg.log | loghead /var/log/dmesg.log)" ;;
93 esac
95 xhtml_header "$(_ 'Boot log files')"
96 cat <<EOT
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 style="overflow-x: auto">$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 "$(_ 'Manage daemons')"
122 cat <<EOT
123 <p>$(_ 'Check, start and stop daemons on SliTaz')</p>
124 EOT
125 daemon=$(GET daemons)
126 case "$daemon" in
127 start=*)
128 sleep 1
129 /etc/init.d/${daemon#start=} start | log ;;
130 stop=*)
131 /etc/init.d/${daemon#stop=} stop | log ;;
132 pid=*)
133 echo "<pre>"
134 ps ww | sed 1q
135 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
136 ps ww | sed "/^ $i /!d"
137 done
138 echo "</pre>" ;;
139 esac
141 # Daemon list
142 cat <<EOT
143 <section>
144 <table class="zebra wide daemons">
145 <thead>
146 <tr>
147 <td>$(_ 'Name')</td>
148 <td>$(_ 'Description')</td>
149 <td>$(_ 'Configuration')</td>
150 <td>$(_ 'Status')</td>
151 <td>$(_ 'Action')</td>
152 <td>$(_ 'PID')</td>
153 </tr>
154 </thead>
155 <tbody>
156 EOT
157 cd /etc/init.d
158 list="$(ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d -e /firewall/d)"
159 for name in $list; do
160 unset pkg pid status SHORT_DESC boot cfg
161 echo '<tr>'
162 # Name
163 echo "<td>$name</td>"
164 # First check if daemon is started at boottime
165 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
166 # Standard SliTaz busybox daemons and firewall
167 echo -n "<td>"
168 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
169 for i in /etc/slitaz /etc /etc/$name ; do
170 for j in $i/$name.conf $i/${name}d.conf ; do
171 [ -s $j ] && cfg="edit::$j|$cfg"
172 done
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 cfg="man|help|edit::/etc/ntp.conf|options"
182 _ 'Network time protocol daemon' ;;
183 ftpd)
184 cfg="man|help|edit::/etc/inetd.conf"
185 _ 'Anonymous FTP server' ;;
186 udhcpd)
187 cfg="man|help|edit|options"
188 _ 'Busybox DHCP server' ;;
189 syslogd|klogd)
190 cfg="man|help|edit::/etc/syslog.conf|options"
191 _ 'Linux Kernel log daemon' ;;
192 crond)
193 # FIXME crontab
194 _ 'Execute scheduled commands' ;;
195 dnsd)
196 cfg="man|help|edit|options::-d"
197 _ 'Small static DNS server daemon' ;;
198 tftpd)
199 cfg="man|help|edit::/etc/inetd.conf|options"
200 _ 'Transfer a file on tftp request' ;;
201 lpd)
202 cfg="man|help|options"
203 _ 'Printer daemon' ;;
204 inetd)
205 _ 'Listen for network connections and launch programs' ;;
206 zcip)
207 cfg="man|help|edit:Script:/etc/zcip.script|options::eth0 /etc/zcip.script"
208 _ 'Manage a ZeroConf IPv4 link-local address' ;;
209 *)
210 # Description from receipt
211 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
212 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
213 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
214 if [ "$pkg" ]; then
215 unset SHORT_DESC TAZPANEL_DAEMON
216 #FIXME $PKGS_DB
217 . $LOCALSTATE/installed/$pkg/receipt
218 echo -n "$SHORT_DESC"
219 cfg="${TAZPANEL_DAEMON:-$cfg|web::$WEB_SITE}"
220 else
221 echo -n "----"
222 fi ;;
223 esac
224 echo "</td>"
225 # Attempt to get daemon status
226 pidfile=$(find /var/run -name *$name*.pid)
227 [ "$pidfile" ] && pid=$(cat $pidfile)
228 # Dbus
229 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
230 # Apache
231 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
232 # Pidof works for many daemons
233 [ "$pid" ] || pid=$(pidof $name)
235 echo -n "<td style='white-space: nowrap'>"
236 if [ -n "$cfg" ]; then
237 IFS="|"
238 for i in $cfg ; do
239 IFS=":"
240 set -- $i
241 case "$1" in
242 edit)
243 cat <<EOT
244 <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>
245 EOT
246 ;;
247 options)
248 key=$(echo -n $name | tr [a-z] [A-Z])_OPTIONS
249 cat <<EOT
250 <a href="index.cgi?file=/etc/daemons.conf&amp;action=setvar&amp;var=$key&amp;default=$3" title="${2:-$key}" data-img="opt"></a>
251 EOT
252 ;;
253 man)
254 cat <<EOT
255 <a href="index.cgi?exec=man ${3:-$name}&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Manual}" data-img="man"></a>
256 EOT
257 ;;
258 help)
259 help='--help'
260 case $name in
261 cupsd|dropbear|gpm|slim|wpa_supplicant) help='-h'
262 esac
263 cat <<EOT
264 <a href="index.cgi?exec=$(which ${3:-$name}) $help&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Help}" data-img="help"></a>
265 EOT
266 ;;
267 web) cat <<EOT
268 <a href="${i#$1:$2:}" title="${2:-$name website:} ${i#$1:$2:}" target="_blank" data-img="web"></a>
269 EOT
270 ;;
271 esac
272 done
273 fi
274 echo "</td>"
275 if [ "$pid" ]; then
276 cat <<EOT
277 <td><span title="$(_ 'Started')" data-img="on"></span></td>
278 <td><a href="?daemons=stop=$name" title="$(_ 'Stop')" data-img="stop"></a></td>
279 <td>
280 EOT
281 for i in $pid; do
282 cat <<EOT
283 <a href="?daemons=pid=$i">$i</a>
284 EOT
285 done
286 else
287 cat <<EOT
288 <td><span title="$(_ 'Stopped')" data-img="off"></span></td>
289 <td><a href="?daemons=start=$name" title="$(_ 'Start')" data-img="start"></a></td>
290 <td>-----
291 EOT
292 fi
293 echo '</td></tr>'
294 done
295 echo '</thead></table></section>' ;;
298 *\ grub\ *)
299 GRUBMENU="/boot/grub/menu.lst"
300 if [ "$(GET splash)" ]; then
301 default=$(GET default)
302 timeout=$(GET timeout)
303 splash=$(GET splash)
304 sed -i \
305 -e s"|default .*|default $default # new|" \
306 -e s"|timeout .*|timeout $timeout|" \
307 -e s"|splashimage=.*|splashimage=$splash|" \
308 $GRUBMENU
309 fi
310 default=$(grep ^default $GRUBMENU | cut -d' ' -f2)
311 timeout=$(grep ^timeout $GRUBMENU | cut -d' ' -f2)
312 splash=$(grep ^splashimage $GRUBMENU | cut -d' ' -f2)
314 xhtml_header "$(_ 'GRUB Boot loader')"
315 cat <<EOT
316 <p>$(_ 'The first application started when the computer powers on')</p>
318 <form class="wide">
319 <section>
320 <div>
321 <input type="hidden" name="grub"/>
322 <table>
323 <tr><td>$(_ 'Default entry:')</td>
324 <td><input type="text" name="default" value="${default##*=}"/></td></tr>
325 <tr><td>$(_ 'Timeout:')</td>
326 <td><input type="text" name="timeout" value="${timeout##*=}"/></td></tr>
327 <tr><td>$(_ 'Splash image:')</td>
328 <td><input type="text" name="splash" value="${splash##*=}" size="40"/></td></tr>
329 </table>
330 </div>
331 <footer>
332 <button type="submit" data-icon="ok">$(_ 'Change')</button>
333 </footer>
334 </section>
335 </form>
337 <form action="index.cgi">
338 <input type="hidden" name="file" value="$GRUBMENU"/>
339 <button data-icon="text">$(_ 'View or edit menu.lst')</button>
340 </form>
343 <section>
344 <header>$(_ 'Boot entries')</header>
345 <div>
346 EOT
349 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU | \
350 sed -e "s|^$||g" | \
351 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" | \
352 sed '/^[ \t]*$/d' | \
353 tail -q -n +2)"</pre>"
355 entry='-1'
356 echo "$menu" | while read line
357 do
358 if [ -n "$(echo $line | grep '#</header>')" ]; then
359 entry=$(($entry + 1))
360 fi
361 echo $line | sed "s|#</header>|$entry</header>|"
362 done
364 echo '</section>'
367 # Here we could check if an entry for gpxe is present if not
368 # display a form to add it.
369 [ -f "/boot/gpxe" ] && cat <<EOT
370 <section>
371 <header>gPXE</header>
372 <div>$(_ 'Web boot is available with gPXE')</div>
373 </section>
374 EOT
375 ;;
378 *\ iso\ *)
379 xhtml_header
380 iso=$(POST iso); [ -s "$iso" ] || unset iso
381 action=$(POST action); [ "$action" ] || action=$(GET action)
382 workdir=$(POST workdir)
383 [ -d $workdir ] || workdir=$(dirname $workdir)
384 [ -w $workdir -a "$workdir" ] || workdir=/tmp
386 echo "<h2>$(_ 'ISO mine')</h2>"
388 [ "$iso" ] || msg err "$(_ 'Invalid ISO image.')"
390 if [ "$iso" -a "$action" -a "$action" != "nop" ]; then
391 case "$action" in
392 install*) dev=$(POST instdev) ;;
393 *) dev=$(POST usbkeydev) ;;
394 esac
395 cd $workdir
396 cat <<EOT
397 <section>
398 <pre>
399 $(taziso $iso $action $dev 2>&1)
400 </pre>
401 </section>
402 EOT
403 fi
404 cat <<EOT
405 <section>
406 <form method="post" action="?iso" class="wide">
407 <table>
408 <tr><td>$(_ 'ISO image file full path')
409 <span data-img="info" title="$(_ 'set /dev/cdrom for a physical CD-ROM')"></span>
410 </td>
411 <td><input type="text" name="iso" value="$iso" size="50"/></td></tr>
412 <tr><td>$(_ 'Working directory')</td>
413 <td><input type="text" name="workdir" value="$workdir" size="50"/></td></tr>
414 <tr><td>$(_ 'Target partition')
415 <span data-img="info" title="$(_ 'For hard disk installation only. Will create /slitaz tree and keep other files. No partitioning and no formatting.')"></span>
416 </td>
417 <td><select name="instdev">
418 <option value="/dev/null">$(_ 'Choose a partition (optional)')</option>
419 EOT
420 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
421 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
422 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
423 while read dev label type; do
424 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
425 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
426 done
427 cat <<EOT
428 </select></td></tr>
429 <tr><td>$(_ 'USB key device')
430 <span data-img="info" title="$(_ 'For USB boot key only. Will erase the full device.')"></span>
431 </td>
432 <td><select name="usbkeydev">
433 <option value="/dev/null">$(_ 'Choose a USB key (optional)')</option>
434 EOT
435 grep -l 1 /sys/block/*/removable | \
436 sed 's|/sys/block/\(.*\)/removable|\1|' | while read dev; do
437 grep -qs 1 /sys/block/$dev/ro && continue
438 [ -d /sys/block/$dev/device/scsi_disk ] || continue
439 echo -n "<option value=\"/dev/$dev\">/dev/$dev "
440 echo -n "$(blk2h < /sys/block/$dev/size) "
441 echo -n "$(cat /sys/block/$dev/device/model 2>/dev/null) "
442 blkid | grep $dev | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/"\1"/;q'
443 echo "</option>"
444 done
445 cat <<EOT
446 </select></td></tr>
447 </table>
448 <footer>
449 EOT
451 if [ "$iso" ]; then
452 cat <<EOT
453 <select name="action">
454 <option value="nop">$(_ 'Choose an action')</option>
455 $(taziso $iso list | sed -e \
456 's/"\(.*\)"[\t ]*"\(.*\)"/<option value="\1\">\2<\/option>/' -e \
457 "s|value=\"$action\"|& selected|")
458 </select>
459 EOT
460 elif [ "$action" ]; then
461 cat <<EOT
462 <input type="hidden" name="action" value="$action" />
463 EOT
464 fi
466 cat <<EOT
467 <button data-icon="cd" name="mine">$(_ 'Mine')</button>
468 </footer>
469 </form>
470 </section>
471 EOT
472 ;;
475 *)
476 #
477 # Default content with summary
478 #
479 . /etc/rcS.conf
480 xhtml_header "$(_ 'Boot &amp; Start services')"
481 cat <<EOT
482 <p>$(_ 'Everything that happens before user login')</p>
484 <form>
485 <button name="log" data-icon="logs" >$(_ 'Boot logs')</button>
486 <button name="syslog" data-icon="logs" >$(_ 'System logs')</button>
487 <button name="daemons" data-icon="daemons" data-root>$(_ 'Manage daemons')</button>
488 EOT
489 [ "$REMOTE_USER" == "root" -a -x /usr/bin/taziso ] && cat <<EOT
490 <button name="iso" data-icon="cd" >$(_ 'ISO mine')</button>
491 EOT
492 [ -w /boot/grub/menu.lst ] && cat <<EOT
493 <button name="grub" data-icon="grub" >$(_ 'Boot loader')</button>
494 EOT
495 cat <<EOT
496 </form>
499 <section>
500 <header>$(_ 'Configuration files')</header>
501 <form action="index.cgi" class="wide">
502 <table>
503 <tr><td>$(_ 'Main configuration file:') <b>rcS.conf</b></td>
504 <td><button name="file" value="/etc/rcS.conf" data-icon="view">$(_ 'View')</button></td></tr>
505 <tr><td>$(_ 'Login manager settings:') <b>slim.conf</b></td>
506 <td><button name="file" value="/etc/slim.conf" data-icon="view">$(_ 'View')</button></td></tr>
507 </table>
508 </form>
509 </section>
512 <section style="overflow-x: auto">
513 <header>$(_ 'Kernel cmdline')</header>
514 <pre>$(cat /proc/cmdline)</pre>
515 </section>
518 <section>
519 <header>
520 $(_ 'Local startup commands')
521 <form action="index.cgi">
522 <input type="hidden" name="file" value="/etc/init.d/local.sh"/>
523 EOT
524 [ -w /etc/init.d/local.sh ] && cat <<EOT
525 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
526 EOT
527 cat <<EOT
528 </form>
529 </header>
530 <pre><code class="language-bash">$(htmlize < /etc/init.d/local.sh)</code></pre>
531 </section>
532 EOT
533 ;;
534 esac
536 xhtml_footer
537 exit 0