tazpanel view boot.cgi @ rev 383

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