tazpanel view boot.cgi @ rev 472
boot.cgi: change look of "System logs" page; index.cgi: return "Diff" button back.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu Apr 30 02:25:59 2015 +0300 (2015-04-30) |
parents | 5d33b8aaf36d |
children | de34ca9d1417 |
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 [ -s $i/$name.conf ] && cfg="edit::$i/$name.conf|$cfg"
174 done
175 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
176 case "$name" in
177 firewall)
178 _ 'SliTaz Firewall with iptable rules' ;;
179 httpd)
180 _ 'Small and fast web server with CGI support' ;;
181 ntpd)
182 _ 'Network time protocol daemon' ;;
183 ftpd)
184 cfg="man|help|edit::/etc/inetd.conf"
185 _ 'Anonymous FTP server' ;;
186 udhcpd)
187 _ 'Busybox DHCP server' ;;
188 syslogd|klogd)
189 _ 'Linux Kernel log daemon' ;;
190 crond)
191 # FIXME crontab
192 _ 'Execute scheduled commands' ;;
193 dnsd)
194 cfg="man|help|edit|options::-d"
195 _ 'Small static DNS server daemon' ;;
196 tftpd)
197 cfg="man|help|edit::/etc/inetd.conf"
198 _ 'Transfer a file on tftp request' ;;
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 /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}&action=edit" title="${2:-$name Configuration}" 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&action=setvar&var=$key&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}&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&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=$(cat $GRUBMENU | grep ^default | cut -d' ' -f2)
306 timeout=$(cat $GRUBMENU | grep ^timeout | cut -d' ' -f2)
307 splash=$(cat $GRUBMENU | grep ^splashimage | cut -d' ' -f2)
308 xhtml_header
309 cat <<EOT
310 <h2>$(_ 'GRUB Boot loader')</h2>
312 <p>$(_ 'The first application started when the computer powers on')</p>
314 <form class="wide">
315 <section>
316 <div>
317 <input type="hidden" name="grub"/>
318 <table>
319 <tr><td>$(_ 'Default entry:')</td>
320 <td><input type="text" name="default" value="${default##*=}"/></td></tr>
321 <tr><td>$(_ 'Timeout:')</td>
322 <td><input type="text" name="timeout" value="${timeout##*=}"/></td></tr>
323 <tr><td>$(_ 'Splash image:')</td>
324 <td><input type="text" name="splash" value="${splash##*=}" size="40"/></td></tr>
325 </table>
326 </div>
327 <footer>
328 <button type="submit" data-icon="ok">$(_ 'Change')</button>
329 </footer>
330 </section>
331 </form>
333 <form action="index.cgi">
334 <input type="hidden" name="file" value="$GRUBMENU"/>
335 <button data-icon="text">$(_ 'View or edit menu.lst')</button>
336 </form>
339 <section>
340 <header>$(_ 'Boot entries')</header>
341 <div>
342 EOT
345 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU | \
346 sed -e "s|^$||g" | \
347 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" | \
348 sed '/^[ \t]*$/d' | \
349 tail -q -n +2)"</pre>"
351 entry='-1'
352 echo "$menu" | while read line
353 do
354 if [ -n "$(echo $line | grep '#</header>')" ]; then
355 entry=$(($entry + 1))
356 fi
357 echo $line | sed "s|#</header>|$entry</header>|"
358 done
360 echo '</section>'
363 # Here we could check if an entry for gpxe is present if not
364 # display a form to add it.
365 [ -f "/boot/gpxe" ] && cat <<EOT
366 <section>
367 <header>gPXE</header>
368 <div>$(_ 'Web boot is available with gPXE')</div>
369 </section>
370 EOT
371 ;;
374 *\ iso\ *)
375 xhtml_header
376 iso=$(POST iso); [ -s "$iso" ] || unset iso
377 action=$(POST action); [ "$action" ] || action=$(GET action)
378 workdir=$(POST workdir)
379 [ -d $workdir ] || workdir=$(dirname $workdir)
380 [ -w $workdir -a "$workdir" ] || workdir=/tmp
382 echo "<h2>$(_ 'ISO mine')</h2>"
384 [ "$iso" ] || msg err 'Invalid ISO image.'
386 if [ "$iso" -a "$action" -a "$action" != "nop" ]; then
387 case "$action" in
388 install*) dev=$(POST instdev) ;;
389 *) dev=$(POST usbkeydev) ;;
390 esac
391 cd $workdir
392 cat <<EOT
393 <section>
394 <pre>
395 $(taziso $iso $action $dev 2>&1)
396 </pre>
397 </section>
398 EOT
399 fi
400 cat <<EOT
401 <section>
402 <form method="post" action="?iso" class="wide">
403 EOT
404 cat <<EOT
405 <table>
406 <tr><td>ISO image file full path
407 <span data-img="info" title="set /dev/cdrom for a physical CD-ROM"></span>
408 </td>
409 <td><input type="text" name="iso" value="$iso" size="50"/></td></tr>
410 <tr><td>Working directory</td>
411 <td><input type="text" name="workdir" value="$workdir" size="50"/></td></tr>
412 <tr><td>Target partition
413 <span data-img="info" title="For hard disk installation only. Will create /slitaz tree and keep other files. No partitioning and no formatting."></span>
414 </td>
415 <td><select name="instdev">
416 <option value="/dev/null">Choose a partition (optional)</option>
417 EOT
418 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
419 sed 's|^/dev/\(.*\):.*LABEL="\([^"]*\).* TYPE="\([^"]*\).*|\1 "\2" \3|' | \
420 while read dev label type; do
421 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label "
422 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size) $type</option>"
423 done
424 cat <<EOT
425 </select></td></tr>
426 <tr><td>USB key device
427 <span data-img="info" title="For USB boot key only. Will erase the full device."></span>
428 </td>
429 <td><select name="usbkeydev">
430 <option value="/dev/null">Choose a USB key (optional)</option>
431 EOT
432 grep -l 1 /sys/block/*/removable | \
433 sed 's|/sys/block/\(.*\)/removable|\1|' | while read dev; do
434 grep -qs 1 /sys/block/$DEV/ro && continue
435 echo -n "<option value=\"/dev/$dev\">/dev/$dev "
436 echo "$(blk2h < /sys/block/$dev/size) $(cat \
437 /sys/block/$i/device/model 2>/dev/null)</option>"
438 done
439 cat <<EOT
440 </select></td></tr>
441 </table>
442 <footer>
443 EOT
445 if [ "$iso" ]; then
446 cat <<EOT
447 <select name="action">
448 <option value="nop">Choose an action</option>
449 $(taziso $iso list | sed -e \
450 's/"\(.*\)"[\t ]*"\(.*\)"/<option value="\1\">\2<\/option>/' -e \
451 "s|value=\"$action\"|& selected|")
452 </select>
453 EOT
454 elif [ "$action" ]; then
455 cat <<EOT
456 <input type="hidden" name="action" value="$action" />
457 EOT
458 fi
460 cat <<EOT
461 <button data-icon="cd" name="mine">Mine</button>
462 </footer>
463 </form>
464 </section>
465 EOT
466 ;;
469 *)
470 #
471 # Default content with summary
472 #
473 . /etc/rcS.conf
474 xhtml_header
475 cat <<EOT
476 <h2>$(_ 'Boot & Start services')</h2>
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 <form action="index.cgi">
518 <input type="hidden" name="file" value="/etc/init.d/local.sh"/>
519 EOT
520 [ -w /etc/init.d/local.sh ] && cat <<EOT
521 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
522 EOT
523 cat <<EOT
524 </form>
525 </header>
526 <pre><code class="language-bash">$(cat /etc/init.d/local.sh | htmlize)</code></pre>
527 </section>
528 EOT
529 ;;
530 esac
532 xhtml_footer
533 exit 0