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