tazpanel view boot.cgi @ rev 455

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