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