tazpanel view boot.cgi @ rev 499

settings.cgi: disable live hardware clock on the page; base.css: fix statusbar height.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat May 23 17:20:17 2015 +0300 (2015-05-23)
parents e6181f0521c8
children 3117717c007d
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 }
32 #
33 # Commands
34 #
36 case " $(GET) " in
37 *\ syslog\ *)
38 logtype="$(GET syslog)"
39 [ "${logtype:-syslog}" == "syslog" ] && logtype=messages
40 xhtml_header
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
94 xhtml_header
95 cat <<EOT
96 <h2>$(_ 'Boot log files')</h2>
98 <ul id="tabs">
99 <li$actkernel><a href="?log=kernel">$(_ 'Kernel messages')</a></li>
100 <li$actboot ><a href="?log=boot" >$(_ 'Boot scripts' )</a></li>
101 <li$actxlog ><a href="?log=xlog" >$(_ 'X server' )</a></li>
102 <li$actslim ><a href="?log=slim" >$(_ 'X session' )</a></li>
103 </ul>
105 <section>
106 <div>
107 <pre$colors style="overflow-x: auto">$output</pre>
108 </div>
109 </section>
110 EOT
111 ;;
114 *\ daemons\ *)
115 #
116 # Everything until user login
117 #
118 # Start and stop a daemon.
119 # (I think we don't need a 'restart' since 2 clicks and you are done)
120 . /etc/rcS.conf
121 xhtml_header
123 cat <<EOT
124 <h2>$(_ 'Manage daemons')</h2>
126 <p>$(_ 'Check, start and stop daemons on SliTaz')</p>
127 EOT
128 daemon=$(GET daemons)
129 case "$daemon" in
130 start=*)
131 sleep 1
132 /etc/init.d/${daemon#start=} start | log ;;
133 stop=*)
134 /etc/init.d/${daemon#stop=} stop | log ;;
135 pid=*)
136 echo "<pre>"
137 ps ww | sed 1q
138 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
139 ps ww | sed "/^ $i /!d"
140 done
141 echo "</pre>" ;;
142 esac
144 # Daemon list
145 cat <<EOT
146 <section>
147 <table class="zebra wide daemons">
148 <thead>
149 <tr>
150 <td>$(_ 'Name')</td>
151 <td>$(_ 'Description')</td>
152 <td>$(_ 'Configuration')</td>
153 <td>$(_ 'Status')</td>
154 <td>$(_ 'Action')</td>
155 <td>$(_ 'PID')</td>
156 </tr>
157 </thead>
158 <tbody>
159 EOT
160 cd /etc/init.d
161 list="$(ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d -e /firewall/d)"
162 for name in $list; do
163 unset pkg pid status SHORT_DESC boot cfg
164 echo '<tr>'
165 # Name
166 echo "<td>$name</td>"
167 # First check if daemon is started at boottime
168 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
169 # Standard SliTaz busybox daemons and firewall
170 echo -n "<td>"
171 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
172 for i in /etc/slitaz /etc /etc/$name ; do
173 for j in $i/$name.conf $i/${name}d.conf ; do
174 [ -s $j ] && cfg="edit::$j|$cfg"
175 done
176 done
177 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
178 case "$name" in
179 firewall)
180 _ 'SliTaz Firewall with iptable rules' ;;
181 httpd)
182 _ 'Small and fast web server with CGI support' ;;
183 ntpd)
184 cfg="man|help|edit::/etc/ntp.conf|options"
185 _ 'Network time protocol daemon' ;;
186 ftpd)
187 cfg="man|help|edit::/etc/inetd.conf"
188 _ 'Anonymous FTP server' ;;
189 udhcpd)
190 cfg="man|help|edit|options"
191 _ 'Busybox DHCP server' ;;
192 syslogd|klogd)
193 cfg="man|help|edit::/etc/syslog.conf|options"
194 _ 'Linux Kernel log daemon' ;;
195 crond)
196 # FIXME crontab
197 _ 'Execute scheduled commands' ;;
198 dnsd)
199 cfg="man|help|edit|options::-d"
200 _ 'Small static DNS server daemon' ;;
201 tftpd)
202 cfg="man|help|edit::/etc/inetd.conf|options"
203 _ 'Transfer a file on tftp request' ;;
204 lpd)
205 cfg="man|help|options"
206 _ 'Printer daemon' ;;
207 inetd)
208 _ 'Listen for network connections and launch programs' ;;
209 zcip)
210 cfg="man|help|edit:Script:/etc/zcip.script|options::eth0 /etc/zcip.script"
211 _ 'Manage a ZeroConf IPv4 link-local address' ;;
212 *)
213 # Description from receipt
214 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
215 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
216 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
217 if [ "$pkg" ]; then
218 unset SHORT_DESC TAZPANEL_DAEMON
219 #FIXME $PKGS_DB
220 . $LOCALSTATE/installed/$pkg/receipt
221 echo -n "$SHORT_DESC"
222 cfg="${TAZPANEL_DAEMON:-$cfg|web::$WEB_SITE}"
223 else
224 echo -n "----"
225 fi ;;
226 esac
227 echo "</td>"
228 # Attempt to get daemon status
229 pidfile=$(find /var/run -name *$name*.pid)
230 [ "$pidfile" ] && pid=$(cat $pidfile)
231 # Dbus
232 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
233 # Apache
234 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
235 # Pidof works for many daemons
236 [ "$pid" ] || pid=$(pidof $name)
238 echo -n "<td style='white-space: nowrap'>"
239 if [ -n "$cfg" ]; then
240 IFS="|"
241 for i in $cfg ; do
242 IFS=":"
243 set -- $i
244 case "$1" in
245 edit)
246 cat <<EOT
247 <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>
248 EOT
249 ;;
250 options)
251 key=$(echo -n $name | tr [a-z] [A-Z])_OPTIONS
252 cat <<EOT
253 <a href="index.cgi?file=/etc/daemons.conf&amp;action=setvar&amp;var=$key&amp;default=$3" title="${2:-$key}" data-img="opt"></a>
254 EOT
255 ;;
256 man)
257 cat <<EOT
258 <a href="index.cgi?exec=man ${3:-$name}&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Manual}" data-img="man"></a>
259 EOT
260 ;;
261 help)
262 help='--help'
263 case $name in
264 cupsd|dropbear|gpm|slim|wpa_supplicant) help='-h'
265 esac
266 cat <<EOT
267 <a href="index.cgi?exec=$(which ${3:-$name}) $help&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Help}" data-img="help"></a>
268 EOT
269 ;;
270 web) cat <<EOT
271 <a href="${i#$1:$2:}" title="${2:-$name website:} ${i#$1:$2:}" target="_blank" data-img="web"></a>
272 EOT
273 ;;
274 esac
275 done
276 fi
277 echo "</td>"
278 if [ "$pid" ]; then
279 cat <<EOT
280 <td><span title="$(_ 'Started')" data-img="on"></span></td>
281 <td><a href="?daemons=stop=$name" title="$(_ 'Stop')" data-img="stop"></a></td>
282 <td>
283 EOT
284 for i in $pid; do
285 cat <<EOT
286 <a href="?daemons=pid=$i">$i</a>
287 EOT
288 done
289 else
290 cat <<EOT
291 <td><span title="$(_ 'Stopped')" data-img="off"></span></td>
292 <td><a href="?daemons=start=$name" title="$(_ 'Start')" data-img="start"></a></td>
293 <td>-----
294 EOT
295 fi
296 echo '</td></tr>'
297 done
298 echo '</thead></table></section>' ;;
301 *\ grub\ *)
302 GRUBMENU="/boot/grub/menu.lst"
303 if [ "$(GET splash)" ]; then
304 default=$(GET default)
305 timeout=$(GET timeout)
306 splash=$(GET splash)
307 sed -i \
308 -e s"|default .*|default $default # new|" \
309 -e s"|timeout .*|timeout $timeout|" \
310 -e s"|splashimage=.*|splashimage=$splash|" \
311 $GRUBMENU
312 fi
313 default=$(cat $GRUBMENU | grep ^default | cut -d' ' -f2)
314 timeout=$(cat $GRUBMENU | grep ^timeout | cut -d' ' -f2)
315 splash=$(cat $GRUBMENU | grep ^splashimage | cut -d' ' -f2)
316 xhtml_header
317 cat <<EOT
318 <h2>$(_ 'GRUB Boot loader')</h2>
320 <p>$(_ 'The first application started when the computer powers on')</p>
322 <form class="wide">
323 <section>
324 <div>
325 <input type="hidden" name="grub"/>
326 <table>
327 <tr><td>$(_ 'Default entry:')</td>
328 <td><input type="text" name="default" value="${default##*=}"/></td></tr>
329 <tr><td>$(_ 'Timeout:')</td>
330 <td><input type="text" name="timeout" value="${timeout##*=}"/></td></tr>
331 <tr><td>$(_ 'Splash image:')</td>
332 <td><input type="text" name="splash" value="${splash##*=}" size="40"/></td></tr>
333 </table>
334 </div>
335 <footer>
336 <button type="submit" data-icon="ok">$(_ 'Change')</button>
337 </footer>
338 </section>
339 </form>
341 <form action="index.cgi">
342 <input type="hidden" name="file" value="$GRUBMENU"/>
343 <button data-icon="text">$(_ 'View or edit menu.lst')</button>
344 </form>
347 <section>
348 <header>$(_ 'Boot entries')</header>
349 <div>
350 EOT
353 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU | \
354 sed -e "s|^$||g" | \
355 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" | \
356 sed '/^[ \t]*$/d' | \
357 tail -q -n +2)"</pre>"
359 entry='-1'
360 echo "$menu" | while read line
361 do
362 if [ -n "$(echo $line | grep '#</header>')" ]; then
363 entry=$(($entry + 1))
364 fi
365 echo $line | sed "s|#</header>|$entry</header>|"
366 done
368 echo '</section>'
371 # Here we could check if an entry for gpxe is present if not
372 # display a form to add it.
373 [ -f "/boot/gpxe" ] && cat <<EOT
374 <section>
375 <header>gPXE</header>
376 <div>$(_ 'Web boot is available with gPXE')</div>
377 </section>
378 EOT
379 ;;
382 *\ iso\ *)
383 xhtml_header
384 iso=$(POST iso); [ -s "$iso" ] || unset iso
385 action=$(POST action); [ "$action" ] || action=$(GET action)
386 workdir=$(POST workdir)
387 [ -d $workdir ] || workdir=$(dirname $workdir)
388 [ -w $workdir -a "$workdir" ] || workdir=/tmp
390 echo "<h2>$(_ 'ISO mine')</h2>"
392 [ "$iso" ] || msg err 'Invalid ISO image.'
394 if [ "$iso" -a "$action" -a "$action" != "nop" ]; then
395 case "$action" in
396 install*) dev=$(POST instdev) ;;
397 *) dev=$(POST usbkeydev) ;;
398 esac
399 cd $workdir
400 cat <<EOT
401 <section>
402 <pre>
403 $(taziso $iso $action $dev 2>&1)
404 </pre>
405 </section>
406 EOT
407 fi
408 cat <<EOT
409 <section>
410 <form method="post" action="?iso" class="wide">
411 EOT
412 cat <<EOT
413 <table>
414 <tr><td>ISO image file full path
415 <span data-img="info" title="set /dev/cdrom for a physical CD-ROM"></span>
416 </td>
417 <td><input type="text" name="iso" value="$iso" size="50"/></td></tr>
418 <tr><td>Working directory</td>
419 <td><input type="text" name="workdir" value="$workdir" size="50"/></td></tr>
420 <tr><td>Target partition
421 <span data-img="info" title="For hard disk installation only. Will create /slitaz tree and keep other files. No partitioning and no formatting."></span>
422 </td>
423 <td><select name="instdev">
424 <option value="/dev/null">Choose a partition (optional)</option>
425 EOT
426 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
427 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
428 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
429 while read dev label type; do
430 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
431 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
432 done
433 cat <<EOT
434 </select></td></tr>
435 <tr><td>USB key device
436 <span data-img="info" title="For USB boot key only. Will erase the full device."></span>
437 </td>
438 <td><select name="usbkeydev">
439 <option value="/dev/null">Choose a USB key (optional)</option>
440 EOT
441 grep -l 1 /sys/block/*/removable | \
442 sed 's|/sys/block/\(.*\)/removable|\1|' | while read dev; do
443 grep -qs 1 /sys/block/$dev/ro && continue
444 [ -d /sys/block/$dev/device/scsi_disk ] || continue
445 echo -n "<option value=\"/dev/$dev\">/dev/$dev "
446 echo "$(blk2h < /sys/block/$dev/size) $(cat \
447 /sys/block/$i/device/model 2>/dev/null)</option>"
448 done
449 cat <<EOT
450 </select></td></tr>
451 </table>
452 <footer>
453 EOT
455 if [ "$iso" ]; then
456 cat <<EOT
457 <select name="action">
458 <option value="nop">Choose an action</option>
459 $(taziso $iso list | sed -e \
460 's/"\(.*\)"[\t ]*"\(.*\)"/<option value="\1\">\2<\/option>/' -e \
461 "s|value=\"$action\"|& selected|")
462 </select>
463 EOT
464 elif [ "$action" ]; then
465 cat <<EOT
466 <input type="hidden" name="action" value="$action" />
467 EOT
468 fi
470 cat <<EOT
471 <button data-icon="cd" name="mine">Mine</button>
472 </footer>
473 </form>
474 </section>
475 EOT
476 ;;
479 *)
480 #
481 # Default content with summary
482 #
483 . /etc/rcS.conf
484 xhtml_header
485 cat <<EOT
486 <h2>$(_ 'Boot &amp; Start services')</h2>
488 <p>$(_ 'Everything that happens before user login')</p>
490 <form>
491 <button name="log" data-icon="logs" >$(_ 'Boot logs')</button>
492 <button name="syslog" data-icon="logs" >$(_ 'System logs')</button>
493 <button name="daemons" data-icon="daemons" data-root>$(_ 'Manage daemons')</button>
494 EOT
495 [ "$REMOTE_USER" == "root" -a -x /usr/bin/taziso ] && cat <<EOT
496 <button name="iso" data-icon="cd" >$(_ 'ISO mine')</button>
497 EOT
498 [ -w /boot/grub/menu.lst ] && cat <<EOT
499 <button name="grub" data-icon="grub" >$(_ 'Boot loader')</button>
500 EOT
501 cat <<EOT
502 </form>
505 <section>
506 <header>$(_ 'Configuration files')</header>
507 <form action="index.cgi" class="wide">
508 <table>
509 <tr><td>$(_ 'Main configuration file:') <b>rcS.conf</b></td>
510 <td><button name="file" value="/etc/rcS.conf" data-icon="view">$(_ 'View')</button></td></tr>
511 <tr><td>$(_ 'Login manager settings:') <b>slim.conf</b></td>
512 <td><button name="file" value="/etc/slim.conf" data-icon="view">$(_ 'View')</button></td></tr>
513 </table>
514 </form>
515 </section>
518 <section style="overflow-x: auto">
519 <header>$(_ 'Kernel cmdline')</header>
520 <pre>$(cat /proc/cmdline)</pre>
521 </section>
524 <section>
525 <header>
526 $(_ 'Local startup commands')
527 <form action="index.cgi">
528 <input type="hidden" name="file" value="/etc/init.d/local.sh"/>
529 EOT
530 [ -w /etc/init.d/local.sh ] && cat <<EOT
531 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
532 EOT
533 cat <<EOT
534 </form>
535 </header>
536 <pre><code class="language-bash">$(cat /etc/init.d/local.sh | htmlize)</code></pre>
537 </section>
538 EOT
539 ;;
540 esac
542 xhtml_footer
543 exit 0