tazpanel view boot.cgi @ rev 364

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