tazpanel view boot.cgi @ rev 446

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