tazpanel view boot.cgi @ rev 452

Move some code from settings.cgi to new locale.cgi (under construction).
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 10 15:35:35 2015 +0300 (2015-04-10)
parents 169f1ccfb613
children 61395bbfe889
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" ] && logtype=messages
40 xhtml_header
41 cat <<EOT
42 <h2>$(_ 'System logs')</h2>
44 <ul id="tabs">
45 EOT
46 for i in $(sed '/var\/log/!d;s|.*/log/||' /etc/syslog.conf); do
47 unset act
48 [ "$i" == "$logtype" ] && act=' class="active"'
49 cat <<EOT
50 <li$act><a href="?syslog=$i" title="$(sed "/$i$/!d;s/[\t ].*//" /etc/syslog.conf)">$i</a></li>
51 EOT
52 done
53 cat <<EOT
54 </ul>
56 <section>
57 <div>
58 <pre>$(syntax_highlighter kernel < /var/log/$logtype | \
59 loghead /var/log/$logtype)</pre>
60 </div>
61 </section>
62 EOT
63 ;;
64 *\ log\ *)
65 unset actboot actslim actxlog actkernel colors
66 case "$(GET log)" in
67 boot)
68 actboot=' class="active"'
69 output="$(filter_taztools_msgs < /var/log/boot.log)"
70 colors=' class="term log"';;
71 slim)
72 actslim=' class="active"'
73 output="$(loghead /var/log/slim.log htmlize)" ;;
74 xlog)
75 actxlog=' class="active"'
76 output="$(syntax_highlighter xlog < /var/log/Xorg.0.log | loghead /var/log/Xorg.0.log)" ;;
77 *)
78 actkernel=' class="active"'
79 output="$(syntax_highlighter kernel < /var/log/dmesg.log | loghead /var/log/dmesg.log)" ;;
80 esac
81 xhtml_header
82 cat <<EOT
83 <h2>$(_ 'Boot log files')</h2>
85 <ul id="tabs">
86 <li$actkernel><a href="?log=kernel">$(_ 'Kernel messages')</a></li>
87 <li$actboot ><a href="?log=boot" >$(_ 'Boot scripts' )</a></li>
88 <li$actxlog ><a href="?log=xlog" >$(_ 'X server' )</a></li>
89 <li$actslim ><a href="?log=slim" >$(_ 'X session' )</a></li>
90 </ul>
92 <section>
93 <div>
94 <pre$colors>$output</pre>
95 </div>
96 </section>
97 EOT
98 ;;
101 *\ daemons\ *)
102 #
103 # Everything until user login
104 #
105 # Start and stop a daemon.
106 # (I think we don't need a 'restart' since 2 clicks and you are done)
107 . /etc/rcS.conf
108 xhtml_header
110 cat <<EOT
111 <h2>$(_ 'Manage daemons')</h2>
113 <p>$(_ 'Check, start and stop daemons on SliTaz')</p>
114 EOT
115 daemon=$(GET daemons)
116 case "$daemon" in
117 start=*)
118 sleep 1
119 /etc/init.d/${daemon#start=} start | log ;;
120 stop=*)
121 /etc/init.d/${daemon#stop=} stop | log ;;
122 pid=*)
123 echo "<pre>"
124 ps ww | sed 1q
125 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
126 ps ww | sed "/^ $i /!d"
127 done
128 echo "</pre>" ;;
129 esac
131 # Daemon list
132 cat <<EOT
133 <section>
134 <table class="zebra wide daemons">
135 <thead>
136 <tr>
137 <td>$(_ 'Name')</td>
138 <td>$(_ 'Description')</td>
139 <td>$(_ 'Configuration')</td>
140 <td>$(_ 'Status')</td>
141 <td>$(_ 'Action')</td>
142 <td>$(_ 'PID')</td>
143 </tr>
144 </thead>
145 <tbody>
146 EOT
147 cd /etc/init.d
148 list="$(ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d -e /firewall/d)"
149 for name in $list; do
150 unset pkg pid status SHORT_DESC boot cfg
151 echo '<tr>'
152 # Name
153 echo "<td>$name</td>"
154 # First check if daemon is started at boottime
155 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
156 # Standard SliTaz busybox daemons and firewall
157 echo -n "<td>"
158 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
159 for i in /etc/slitaz /etc /etc/$name ; do
160 [ -s $i/$name.conf ] && cfg="edit::$i/$name.conf|$cfg"
161 done
162 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
163 case "$name" in
164 firewall)
165 _ 'SliTaz Firewall with iptable rules' ;;
166 httpd)
167 _ 'Small and fast web server with CGI support' ;;
168 ntpd)
169 _ 'Network time protocol daemon' ;;
170 ftpd)
171 cfg="man|help|edit::/etc/inetd.conf"
172 _ 'Anonymous FTP server' ;;
173 udhcpd)
174 _ 'Busybox DHCP server' ;;
175 syslogd|klogd)
176 _ 'Linux Kernel log daemon' ;;
177 crond)
178 # FIXME crontab
179 _ 'Execute scheduled commands' ;;
180 dnsd)
181 cfg="man|help|edit|options::-d"
182 _ 'Small static DNS server daemon' ;;
183 tftpd)
184 cfg="man|help|edit::/etc/inetd.conf"
185 _ 'Transfer a file on tftp request' ;;
186 inetd)
187 _ 'Listen for network connections and launch programs' ;;
188 zcip)
189 cfg="man|help|edit:Script:/etc/zcip.script|options::eth0 /etc/zcip.script"
190 _ 'Manage a ZeroConf IPv4 link-local address' ;;
191 *)
192 # Description from receipt
193 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
194 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
195 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
196 if [ "$pkg" ]; then
197 unset SHORT_DESC TAZPANEL_DAEMON
198 #FIXME $PKGS_DB
199 . $LOCALSTATE/installed/$pkg/receipt
200 echo -n "$SHORT_DESC"
201 cfg="${TAZPANEL_DAEMON:-$cfg|web::$WEB_SITE}"
202 else
203 echo -n "----"
204 fi ;;
205 esac
206 echo "</td>"
207 # Attempt to get daemon status
208 pidfile=$(find /var/run -name *$name*.pid)
209 [ "$pidfile" ] && pid=$(cat $pidfile)
210 # Dbus
211 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
212 # Apache
213 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
214 # Pidof works for many daemons
215 [ "$pid" ] || pid=$(pidof $name)
217 echo -n "<td style='white-space: nowrap'>"
218 if [ -n "$cfg" ]; then
219 IFS="|"
220 for i in $cfg ; do
221 IFS=":"
222 set -- $i
223 case "$1" in
224 edit)
225 cat <<EOT
226 <a href="index.cgi?file=${3:-/etc/$name.conf}&amp;action=edit" title="${2:-$name Configuration}" data-img="conf"></a>
227 EOT
228 ;;
229 options)
230 key=$(echo -n $name | tr [a-z] [A-Z])_OPTIONS
231 cat <<EOT
232 <a href="index.cgi?file=/etc/daemons.conf&amp;action=setvar&amp;var=$key&amp;default=$3" title="${2:-$key}" data-img="opt"></a>
233 EOT
234 ;;
235 man)
236 cat <<EOT
237 <a href="index.cgi?exec=man ${3:-$name}&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Manual}" data-img="man"></a>
238 EOT
239 ;;
240 help)
241 help='--help'
242 case $name in
243 cupsd|dropbear|gpm|slim|wpa_supplicant) help='-h'
244 esac
245 cat <<EOT
246 <a href="index.cgi?exec=$(which ${3:-$name}) $help&amp;back=boot.cgi%3Fdaemons" title="${2:-$name Help}" data-img="help"></a>
247 EOT
248 ;;
249 web) cat <<EOT
250 <a href="${i#$1:$2:}" title="${2:-$name website:} ${i#$1:$2:}" target="_blank" data-img="web"></a>
251 EOT
252 ;;
253 esac
254 done
255 fi
256 echo "</td>"
257 if [ "$pid" ]; then
258 cat <<EOT
259 <td><span title="$(_ 'Started')" data-img="on"></span></td>
260 <td><a href="?daemons=stop=$name" title="$(_ 'Stop')" data-img="stop"></a></td>
261 <td>
262 EOT
263 for i in $pid; do
264 cat <<EOT
265 <a href="?daemons=pid=$i">$i</a>
266 EOT
267 done
268 else
269 cat <<EOT
270 <td><span title="$(_ 'Stopped')" data-img="off"></span></td>
271 <td><a href="?daemons=start=$name" title="$(_ 'Start')" data-img="start"></a></td>
272 <td>-----
273 EOT
274 fi
275 echo '</td></tr>'
276 done
277 echo '</thead></table></section>' ;;
280 *\ grub\ *)
281 GRUBMENU="/boot/grub/menu.lst"
282 if [ "$(GET splash)" ]; then
283 default=$(GET default)
284 timeout=$(GET timeout)
285 splash=$(GET splash)
286 sed -i \
287 -e s"|default .*|default $default # new|" \
288 -e s"|timeout .*|timeout $timeout|" \
289 -e s"|splashimage=.*|splashimage=$splash|" \
290 $GRUBMENU
291 fi
292 default=$(cat $GRUBMENU | grep ^default | cut -d' ' -f2)
293 timeout=$(cat $GRUBMENU | grep ^timeout | cut -d' ' -f2)
294 splash=$(cat $GRUBMENU | grep ^splashimage | cut -d' ' -f2)
295 xhtml_header
296 cat <<EOT
297 <h2>$(_ 'GRUB Boot loader')</h2>
299 <p>$(_ 'The first application started when the computer powers on')</p>
301 <form class="wide">
302 <section>
303 <div>
304 <input type="hidden" name="grub"/>
305 <table>
306 <tr><td>$(_ 'Default entry:')</td>
307 <td><input type="text" name="default" value="${default##*=}"/></td></tr>
308 <tr><td>$(_ 'Timeout:')</td>
309 <td><input type="text" name="timeout" value="${timeout##*=}"/></td></tr>
310 <tr><td>$(_ 'Splash image:')</td>
311 <td><input type="text" name="splash" value="${splash##*=}" size="40"/></td></tr>
312 </table>
313 </div>
314 <footer>
315 <button type="submit" data-icon="ok">$(_ 'Change')</button>
316 </footer>
317 </section>
318 </form>
320 <form action="index.cgi">
321 <input type="hidden" name="file" value="$GRUBMENU"/>
322 <button data-icon="text">$(_ 'View or edit menu.lst')</button>
323 </form>
326 <section>
327 <header>$(_ 'Boot entries')</header>
328 <div>
329 EOT
332 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU | \
333 sed -e "s|^$||g" | \
334 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" | \
335 sed '/^[ \t]*$/d' | \
336 tail -q -n +2)"</pre>"
338 entry='-1'
339 echo "$menu" | while read line
340 do
341 if [ -n "$(echo $line | grep '#</header>')" ]; then
342 entry=$(($entry + 1))
343 fi
344 echo $line | sed "s|#</header>|$entry</header>|"
345 done
347 echo '</section>'
350 # Here we could check if an entry for gpxe is present if not
351 # display a form to add it.
352 [ -f "/boot/gpxe" ] && cat <<EOT
353 <section>
354 <header>gPXE</header>
355 <div>$(_ 'Web boot is available with gPXE')</div>
356 </section>
357 EOT
358 ;;
361 *)
362 #
363 # Default content with summary
364 #
365 . /etc/rcS.conf
366 xhtml_header
367 cat <<EOT
368 <h2>$(_ 'Boot &amp; Start services')</h2>
370 <p>$(_ 'Everything that happens before user login')</p>
372 <form>
373 <button name="log" data-icon="logs" >$(_ 'Boot logs')</button>
374 <button name="syslog" data-icon="logs" >$(_ 'System logs')</button>
375 <button name="daemons" data-icon="daemons" data-root>$(_ 'Manage daemons')</button>
376 EOT
377 [ -w /boot/grub/menu.lst ] && cat <<EOT
378 <button name="grub" data-icon="grub" >$(_ 'Boot loader')</button>
379 EOT
380 cat <<EOT
381 </form>
384 <section>
385 <header>$(_ 'Configuration files')</header>
386 <form action="index.cgi" class="wide">
387 <table>
388 <tr><td>$(_ 'Main configuration file:') <b>rcS.conf</b></td>
389 <td><button name="file" value="/etc/rcS.conf" data-icon="view">$(_ 'View')</button></td></tr>
390 <tr><td>$(_ 'Login manager settings:') <b>slim.conf</b></td>
391 <td><button name="file" value="/etc/slim.conf" data-icon="view">$(_ 'View')</button></td></tr>
392 </table>
393 </form>
394 </section>
397 <section style="overflow-x: auto">
398 <header>$(_ 'Kernel cmdline')</header>
399 <pre>$(cat /proc/cmdline)</pre>
400 </section>
403 <section>
404 <header>
405 $(_ 'Local startup commands')
406 <form action="index.cgi">
407 <input type="hidden" name="file" value="/etc/init.d/local.sh"/>
408 EOT
409 [ -w /etc/init.d/local.sh ] && cat <<EOT
410 <button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
411 EOT
412 cat <<EOT
413 </form>
414 </header>
415 <pre>$(cat /etc/init.d/local.sh | syntax_highlighter sh)</pre>
416 </section>
417 EOT
418 ;;
419 esac
421 xhtml_footer
422 exit 0