tazpanel view boot.cgi @ rev 411

boot.cgi: display log files in tabs
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jan 18 18:59:01 2015 +0100 (2015-01-18)
parents 106b85c1951c
children 299f204b8f1f
line source
1 #!/bin/sh
2 #
3 # Boot CGI script - All what happens before login (grub, rcS, slim)
4 #
5 # Copyright (C) 2011-2014 SliTaz GNU/Linux - BSD License
6 #
8 # Common functions from libtazpanel and source main boot config file.
9 . lib/libtazpanel
10 . /etc/rcS.conf
11 header
12 get_config
14 TITLE=$(gettext 'TazPanel - Boot')
16 loghead()
17 {
18 tail -n 40 $1 | htmlize
19 [ $(wc -l < $1) -gt 40 ] && cat <<EOT
20 <hr /><a href="/index.cgi?file=$1">$(gettext 'Show more...')</a>
21 EOT
22 }
24 #
25 # Commands
26 #
28 case " $(GET) " in
29 *\ log\ *)
30 unset actboot actslim actxlog actkernel
31 case "$(GET log)" in
32 boot) actboot=' class="active"'
33 output="$(filter_taztools_msgs < /var/log/boot.log)"
34 ;;
35 slim) actslim=' class="active"'
36 output="$(loghead /var/log/slim.log)" ;;
37 xlog) actxlog=' class="active"'
38 output="$(loghead /var/log/Xorg.0.log)" ;;
39 *) actkernel=' class="active"'
40 output="$(syntax_highlighter kernel < /var/log/dmesg.log)"
41 esac
42 xhtml_header
43 cat << EOT
44 <div id="wrapper">
45 <h2>$(gettext 'Boot log files')</h2>
46 </div>
47 <ul id="tabs">
48 <li$actkernel><a href="?log=kernel">$(gettext 'Kernel messages')</a></li>
49 <li$actboot><a href="?log=boot">$(gettext 'Boot scripts')</a></li>
50 <li$actxlog><a href="?log=xlog">$(gettext 'X server')</a></li>
51 <li$actslim><a href="?log=slim">$(gettext 'X session')</a></li>
52 </ul>
53 <pre>
54 $output
55 </pre>
56 EOT
57 ;;
58 *\ daemons\ *)
59 #
60 # Everything until user login
61 #
62 # Start and stop a daemon. I think we don't need a restart since 2
63 # clicks and you are done
64 . /etc/rcS.conf
65 xhtml_header
67 cat << EOT
68 <div id="wrapper">
69 <h2>$(gettext 'Manage daemons')</h2>
70 <p>$(gettext 'Check, start and stop daemons on SliTaz')</p>
71 </div>
72 EOT
73 daemon=$(GET daemons)
74 case "$daemon" in
75 start=*)
76 sleep 1
77 /etc/init.d/${daemon#start=} start | log ;;
78 stop=*)
79 /etc/init.d/${daemon#stop=} stop | log ;;
80 pid=*)
81 echo "<pre>"
82 ps ww | sed 1q
83 for i in $(echo ${daemon#pid=} | sed 's/%20/ /g'); do
84 ps ww | sed "/^ $i /!d"
85 done
86 echo "</pre>" ;;
87 esac
88 # Daemon list
89 table_start
90 cat << EOT
91 <thead>
92 <tr>
93 <td>$(gettext 'Name')</td>
94 <td>$(gettext 'Description')</td>
95 <td>$(gettext 'Configuration')</td>
96 <td>$(gettext 'Status')</td>
97 <td>$(gettext 'Action')</td>
98 <td>$(gettext 'PID')</td>
99 </tr>
100 </thead>
101 EOT
102 cd /etc/init.d
103 list="`ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d \
104 -e /firewall/d`"
105 for name in $list
106 do
107 pkg=""
108 pid=""
109 status=""
110 SHORT_DESC=""
111 echo '<tr>'
112 # Name
113 echo "<td>$name</td>"
114 # First check if daemon is started at bootime
115 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
116 # Standard SliTaz busybox daemons and firewall
117 echo -n "<td>"
118 cfg=""
119 grep -qi "^${name}_OPTIONS=" /etc/daemons.conf && cfg="options|$cfg"
120 for i in /etc/slitaz /etc /etc/$name ; do
121 [ -s $i/$name.conf ] && cfg="edit::$i/$name.conf|$cfg"
122 done
123 [ -n "$(which $name)" ] && cfg="man|help|$cfg"
124 case "$name" in
125 firewall)
126 gettext 'SliTaz Firewall with iptable rules' ;;
127 httpd)
128 gettext 'Small and fast web server with CGI support' ;;
129 ntpd)
130 gettext 'Network time protocol daemon' ;;
131 ftpd)
132 cfg="man|help|edit::/etc/inetd.conf"
133 gettext 'Anonymous FTP server' ;;
134 udhcpd)
135 gettext 'Busybox DHCP server' ;;
136 syslogd|klogd)
137 gettext 'Linux Kernel log daemon' ;;
138 crond)
139 # FIXME crontab
140 gettext 'Execute scheduled commands' ;;
141 dnsd)
142 cfg="man|help|edit|options::-d"
143 gettext 'Small static DNS server daemon' ;;
144 tftpd)
145 cfg="man|help|edit::/etc/inetd.conf"
146 gettext 'Transfer a file on tftp request' ;;
147 inetd)
148 gettext 'Listen for network connections and launch programs' ;;
149 zcip)
150 cfg="man|help|edit:Script:/etc/zcip.script|options::eth0 /etc/zcip.script"
151 gettext 'Manage a ZeroConf IPv4 link-local address' ;;
152 *)
153 # Description from receipt
154 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
155 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
156 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
157 if [ "$pkg" ]; then
158 unset SHORT_DESC TAZPANEL_DAEMON
159 . $LOCALSTATE/installed/$pkg/receipt
160 echo -n "$SHORT_DESC"
161 cfg="${TAZPANEL_DAEMON:-$cfg|web::$WEB_SITE}"
162 else
163 echo -n "----"
164 fi ;;
165 esac
166 echo "</td>"
167 # Attempt to get daemon status
168 pidfile=$(find /var/run -name *$name*.pid)
169 [ "$pidfile" ] && pid=$(cat $pidfile)
170 # dbus
171 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
172 # apache
173 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
174 # Pidof works for many daemons
175 [ "$pid" ] || pid=$(pidof $name)
176 echo -n "<td>"
177 if [ "$cfg" ]; then
178 IFS="|"
179 for i in $cfg ; do
180 IFS=":"
181 set -- $i
182 case "$1" in
183 edit) cat <<EOT
184 <a href="index.cgi?file=${3:-/etc/$name.conf}&amp;action=edit">
185 <img title="${2:-$name Configuration}" src="$IMAGES/edit.png" /></a>
186 EOT
187 ;;
188 options)
189 key=$(echo $name | tr [a-z] [A-Z])_OPTIONS
190 cat <<EOT
191 <a href="index.cgi?file=/etc/daemons.conf&amp;action=setvar&amp;var=$key&amp;default=$3">
192 <img title="${2:-$key}" src="$IMAGES/tux.png" /></a>
193 EOT
194 ;;
195 man) cat <<EOT
196 <a href="index.cgi?exec=man ${3:-$name}">
197 <img title="${2:-$name Manual}" src="$IMAGES/text.png" /></a>
198 EOT
199 ;;
200 help) cat <<EOT
201 <a href="index.cgi?exec=$(which ${3:-$name}) --help">
202 <img title="${2:-$name Help}" src="$IMAGES/help.png" /></a>
203 EOT
204 ;;
205 web) cat <<EOT
206 <a href="${i#$1:$2:}">
207 <img title="${2:-$name website:} ${i#$1:$2:}" src="$IMAGES/browser.png" /></a>
208 EOT
209 ;;
210 esac
211 done
212 fi
213 echo "</td>"
214 if [ "$pid" ]; then
215 cat << EOT
216 <td><img src="$IMAGES/started.png" alt="Started" title="$(gettext 'Started')" /></td>
217 <td><a href="?daemons=stop=$name">
218 <img src="$IMAGES/stop.png" alt="Stop" title="$(gettext 'Stop')" /></a></td>
219 <td>
220 EOT
221 for i in $pid; do
222 cat << EOT
223 <a href="?daemons=pid=$i">$i</a>
224 EOT
225 done
226 else
227 cat << EOT
228 <td><img src="$IMAGES/stopped.png" alt="Stopped" title="$(gettext 'Stopped')" /></td>
229 <td><a href="?daemons=start=$name">
230 <img src="$IMAGES/start.png" alt="Start" title="$(gettext 'Start')" /></a></td>
231 <td>-----
232 EOT
233 fi
234 echo '</td></tr>'
235 done
236 table_end ;;
238 *\ grub\ *)
239 GRUBMENU="/boot/grub/menu.lst"
240 if [ "$(GET splash)" ]; then
241 default=$(GET default)
242 timeout=$(GET timeout)
243 splash=$(GET splash)
244 sed -i \
245 -e s"|default .*|default $default # new|" \
246 -e s"|timeout .*|timeout $timeout|" \
247 -e s"|splashimage=.*|splashimage=$splash|" \
248 $GRUBMENU
249 fi
250 default=$(cat $GRUBMENU | grep ^default | cut -d " " -f 2)
251 timeout=$(cat $GRUBMENU | grep ^timeout | cut -d " " -f 2)
252 splash=$(cat $GRUBMENU | grep ^splashimage | cut -d "=" -f 2)
253 xhtml_header
254 cat << EOT
255 <div id="wrapper">
256 <h2>$(gettext 'GRUB Boot loader')</h2>
258 <p>$(gettext 'The first application started when the computer powers on')</p>
259 </div>
261 <form method="get" action="">
262 <input type="hidden" name="grub" />
263 <table>
264 <tr><td>$(gettext 'Default entry:')</td>
265 <td><input type="text" name="default" value="$default" /></td></tr>
266 <tr><td>$(gettext 'Timeout:')</td>
267 <td><input type="text" name="timeout" value="$timeout" /></td></tr>
268 <tr><td>$(gettext 'Splash image:')</td>
269 <td><input type="text" name="splash" value="$splash" size="40" /></td></tr>
270 </table>
271 <input type="submit" value="$(gettext 'Change')" />
272 <a class="button" href="index.cgi?file=$GRUBMENU">
273 <img src="$IMAGES/text.png" />$(gettext 'View or edit menu.lst')</a>
274 </form>
276 <h3>$(gettext 'Boot entries')</h3>
277 EOT
280 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU \
281 | sed -e "s|^$||g" \
282 | sed -e "s|^title|</pre></li>\n<p><strong>$(gettext 'Entry') #</strong></p>\n<pre>\0|g" \
283 | sed '/^[ \t]*$/d' \
284 | tail -q -n +2)"</pre>"
286 entry='-1'
287 echo "$menu" | while read line
288 do
289 if [ -n "$(echo $line | grep '#</strong>')" ]; then
290 entry=$(($entry + 1))
291 fi
292 echo $line | sed "s|#</strong>|$entry</strong>|"
293 done
295 # Here we could check if an entry for gpxe is present if not
296 # display a form to add it.
297 [ -f "/boot/gpxe" ] && echo "<h3>gPXE</h3>" && \
298 gettext 'Web boot is available with gPXE'
299 ;;
300 *)
301 #
302 # Default content with summary
303 #
304 . /etc/rcS.conf
305 xhtml_header
306 cat << EOT
307 <div id="wrapper">
308 <h2>$(gettext 'Boot &amp; Start services')</h2>
309 <p>$(gettext 'Everything that happens before user login')</p>
310 </div>
311 <div>
312 <a class="button" href="?log">
313 <img src="$IMAGES/text.png" />$(gettext 'Boot logs')</a>
314 <a class="button" href="?daemons">
315 <img src="$IMAGES/recharge.png" />$(gettext 'Manage daemons')</a>
316 <a class="button" href="?grub">$(gettext 'Boot loader')</a>
317 </div>
319 <h3>$(gettext 'Configuration files')</h3>
320 <ul>
321 <li>$(gettext 'Main configuration file:')
322 <a href="index.cgi?file=/etc/rcS.conf">rcS.conf</a></li>
323 <li>$(gettext 'Login manager settings:')
324 <a href="index.cgi?file=/etc/slim.conf">slim.conf</a></li>
325 </ul>
327 <h3>$(gettext 'Kernel cmdline')</h3>
329 <pre>$(cat /proc/cmdline)</pre>
331 <h3>$(gettext 'Local startup commands')</h3>
333 <pre>$(cat /etc/init.d/local.sh | syntax_highlighter sh)</pre>
335 <a class="button" href="index.cgi?file=/etc/init.d/local.sh&amp;action=edit">
336 <img src="$IMAGES/edit.png" />$(gettext 'Edit script')</a>
337 EOT
338 ;;
339 esac
341 xhtml_footer
342 exit 0