tazpanel view boot.cgi @ rev 633

Remove vpn.desktop: a ppp extention
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 16 11:43:15 2020 +0100 (2020-02-16)
parents bf8941ab3cc3
children 8e4c1fe85462
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 edit_button /etc/syslog.conf syslog.conf
50 cat <<EOT
51 </header>
53 <ul id="tabs">
54 EOT
55 for i in $(sed '/var\/log/!d;s|.*/log/||' /etc/syslog.conf); do
56 unset act
57 [ "$i" = "$logtype" ] && act=' class="active"'
58 cat <<EOT
59 <li$act><a href="?syslog=$i" title="$(sed "/$i$/!d;s/[\t ].*//" /etc/syslog.conf)">$i</a></li>
60 EOT
61 done
62 cat <<EOT
63 </ul>
65 <pre style="overflow-x: auto">$(syntax_highlighter kernel < /var/log/$logtype | \
66 loghead /var/log/$logtype)</pre>
67 </section>
68 EOT
69 ;;
72 *\ log\ *)
73 unset actboot actslim actxlog actkernel colors
74 case "$(GET log)" in
75 boot)
76 actboot=' class="active"'
77 output="$(filter_taztools_msgs < /var/log/boot.log)"
78 colors=' class="term log"';;
79 slim)
80 actslim=' class="active"'
81 output="$(loghead /var/log/slim.log htmlize)" ;;
82 xlog)
83 actxlog=' class="active"'
84 output="$(syntax_highlighter xlog < /var/log/Xorg.0.log | loghead /var/log/Xorg.0.log)" ;;
85 *)
86 actkernel=' class="active"'
87 output="$(syntax_highlighter kernel < /var/log/dmesg.log | loghead /var/log/dmesg.log)" ;;
88 esac
90 xhtml_header "$(_ 'Boot log files')"
91 cat <<EOT
92 <ul id="tabs">
93 <li$actkernel><a href="?log=kernel">$(_ 'Kernel messages')</a></li>
94 <li$actboot ><a href="?log=boot" >$(_ 'Boot scripts' )</a></li>
95 <li$actxlog ><a href="?log=xlog" >$(_ 'X server' )</a></li>
96 <li$actslim ><a href="?log=slim" >$(_ 'X session' )</a></li>
97 </ul>
99 <section>
100 <div>
101 <pre$colors style="overflow-x: auto">$output</pre>
102 </div>
103 </section>
104 EOT
105 ;;
108 *\ daemons\ *)
109 #
110 # Everything until user login
111 #
112 # Start and stop a daemon.
113 # (I think we don't need a 'restart' since 2 clicks and you are done)
114 . /etc/rcS.conf
115 xhtml_header "$(_ 'Manage daemons')"
117 cat <<EOT
118 <p>$(_ 'Check, start and stop daemons on SliTaz')</p>
119 EOT
120 daemon=$(GET daemons)
121 case "$daemon" in
122 start=*)
123 sleep 1
124 /etc/init.d/${daemon#start=} start | log ;;
125 stop=*)
126 /etc/init.d/${daemon#stop=} stop | log ;;
127 pid=*)
128 echo "<pre>"
129 ps ww 2>/dev/null | sed 1q
130 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
131 ps ww 2>/dev/null | sed "/^ $i /!d"
132 done
133 echo "</pre>" ;;
134 esac
136 # Daemon list
137 cat <<EOT
138 <section>
139 <table class="zebra wide daemons">
140 <thead>
141 <tr>
142 <td>$(_ 'Name')</td>
143 <td>$(_ 'Description')</td>
144 <td>$(_ 'Configuration')</td>
145 <td>$(_ 'Status')</td>
146 <td>$(_ 'Action')</td>
147 <td>$(_ 'PID')</td>
148 </tr>
149 </thead>
150 <tbody>
151 EOT
152 cd /etc/init.d
153 list="$(ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d -e /firewall/d)"
154 for name in $list; do
155 unset pkg pid status SHORT_DESC boot cfg
156 echo '<tr>'
157 # Name
158 echo "<td>$name</td>"
159 # First check if daemon is started at boottime
160 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
161 # Standard SliTaz busybox daemons and firewall
162 echo -n "<td>"
163 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
164 for i in /etc/slitaz /etc /etc/$name ; do
165 for j in $i/$name.conf $i/${name}d.conf ; do
166 [ -s $j ] && cfg="edit::$j|$cfg"
167 done
168 done
169 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
170 case "$name" in
171 firewall)
172 _ 'SliTaz Firewall with iptables rules' ;;
173 httpd)
174 _ 'Small and fast web server with CGI support' ;;
175 ntpd)
176 cfg="man|help|edit::/etc/ntp.conf|options"
177 _ 'Network time protocol daemon' ;;
178 ftpd)
179 cfg="man|help|edit::/etc/inetd.conf"
180 _ 'Anonymous FTP server' ;;
181 udhcpd)
182 cfg="man|help|edit|options"
183 _ 'Busybox DHCP server' ;;
184 syslogd|klogd)
185 cfg="man|help|edit::/etc/syslog.conf|options"
186 _ 'Linux Kernel log daemon' ;;
187 crond)
188 # FIXME crontab
189 _ 'Execute scheduled commands' ;;
190 dnsd)
191 cfg="man|help|edit|options::-d"
192 _ 'Small static DNS server daemon' ;;
193 tftpd)
194 cfg="man|help|edit::/etc/inetd.conf|options"
195 _ 'Transfer a file on tftp request' ;;
196 lpd)
197 cfg="man|help|options"
198 _ 'Printer daemon' ;;
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 /run /var/run -maxdepth 2 -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}&amp;action=edit" title="${2:-$name configuration} in ${3:-/etc/$name.conf}" 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&amp;action=setvar&amp;var=$key&amp;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}&amp;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&amp;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" rel="noopener" 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=$(grep ^default $GRUBMENU | cut -d' ' -f2)
306 timeout=$(grep ^timeout $GRUBMENU | cut -d' ' -f2)
307 splash=$(grep ^splashimage $GRUBMENU | cut -d' ' -f2)
309 xhtml_header "$(_ 'GRUB Boot loader')"
310 cat <<EOT
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/ipxe is present if not
363 # display a form to add it.
364 while read bin name ; do
365 [ -f "/boot/$bin" ] && cat <<EOT
366 <section>
367 <header>$name</header>
368 <div>$(_ 'Web boot is available with %s' "$name")</div>
369 </section>
370 EOT
371 done <<EOT
372 gpxe gPXE
373 ipxe iPXE
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 | htmlize)
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>$(file_chooser "iso" "$iso")</td></tr>
412 <tr><td>$(_ 'Working directory')</td>
413 <td>$(dir_chooser "workdir" "$workdir")</td></tr>
414 </td></tr>
415 <tr><td>$(_ 'Target partition')
416 <span data-img="@info@" title="$(_ 'For hard disk installation only. Will create /slitaz tree and keep other files. No partitioning and no formatting.')"></span>
417 </td>
418 <td><select name="instdev">
419 <option value="/dev/null">$(_ 'Choose a partition (optional)')</option>
420 EOT
421 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
422 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
423 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
424 while read dev label type; do
425 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
426 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
427 done
428 cat <<EOT
429 </select></td></tr>
430 <tr><td>$(_ 'USB key device')
431 <span data-img="@info@" title="$(_ 'For USB boot key only. Will erase the full device.')"></span>
432 </td>
433 <td><select name="usbkeydev">
434 <option value="/dev/null">$(_ 'Choose a USB key (optional)')</option>
435 EOT
436 grep -l 1 /sys/block/*/removable | \
437 sed 's|/sys/block/\(.*\)/removable|\1|' | while read dev; do
438 grep -qs 1 /sys/block/$dev/ro && continue
439 [ -d /sys/block/$dev/device/scsi_disk ] || continue
440 echo -n "<option value=\"/dev/$dev\">/dev/$dev "
441 echo -n "$(blk2h < /sys/block/$dev/size) "
442 echo -n "$(cat /sys/block/$dev/device/model 2>/dev/null) "
443 blkid | grep $dev | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/"\1"/;q'
444 echo "</option>"
445 done
446 cat <<EOT
447 </select></td></tr>
448 </table>
449 <footer>
450 EOT
452 if [ "$iso" ]; then
453 cat <<EOT
454 <select name="action">
455 <option value="nop">$(_ 'Choose an action')</option>
456 $(taziso $iso list | sed -e \
457 's/"\(.*\)"[\t ]*"\(.*\)"/<option value="\1\">\2<\/option>/' -e \
458 "s|value=\"$action\"|& selected|")
459 </select>
460 EOT
461 elif [ "$action" ]; then
462 cat <<EOT
463 <input type="hidden" name="action" value="$action" />
464 EOT
465 fi
467 cat <<EOT
468 <button data-icon="@cd@" name="mine">$(_ 'Mine')</button>
469 </footer>
470 </form>
471 </section>
472 EOT
473 ;;
476 *)
477 #
478 # Default content with summary
479 #
480 . /etc/rcS.conf
481 xhtml_header "$(_ 'Boot \&amp; Start services')"
482 cat <<EOT
483 <p>$(_ 'Everything that happens before user login')</p>
485 <form>
486 <button name="log" data-icon="@logs@">$(_ 'Boot logs')</button>
487 <button name="syslog" data-icon="@logs@">$(_ 'System logs')</button>
488 <button name="daemons" data-icon="@daemons@" data-root>$(_ 'Manage daemons')</button>
489 EOT
490 [ "$REMOTE_USER" = "root" -a -x /usr/bin/taziso ] && cat <<EOT
491 <button name="iso" data-icon="@cd@">$(_ 'ISO mine')</button>
492 EOT
493 [ -w /boot/grub/menu.lst ] && cat <<EOT
494 <button name="grub" data-icon="@grub@">$(_ 'Boot loader')</button>
495 EOT
496 cat <<EOT
497 </form>
500 <section>
501 <header>$(_ 'Configuration files')</header>
502 <form action="index.cgi" class="wide">
503 <table>
504 <tr><td>$(_ 'Main configuration file:') <b>rcS.conf</b></td>
505 <td><button name="file" value="/etc/rcS.conf" data-icon="@view@">$(_ 'View')</button></td></tr>
506 <tr><td>$(_ 'Login manager settings:') <b>slim.conf</b></td>
507 <td><button name="file" value="/etc/slim.conf" data-icon="@view@">$(_ 'View')</button></td></tr>
508 </table>
509 </form>
510 </section>
513 <section style="overflow-x: auto">
514 <header>$(_ 'Kernel cmdline')</header>
515 <pre>$(cat /proc/cmdline)</pre>
516 </section>
519 <section>
520 <header>
521 $(_ 'Local startup commands')
522 $(edit_button /etc/init.d/local.sh)
523 </header>
524 <pre><code class="language-bash">$(htmlize < /etc/init.d/local.sh)</code></pre>
525 </section>
526 EOT
527 ;;
528 esac
530 xhtml_footer
531 exit 0