tazpanel view boot.cgi @ rev 337

settings.cgi: set date manualy
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jan 02 13:35:40 2013 +0100 (2013-01-02)
parents 72e9955ebdff
children 4a8f56bb08cb
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 'Status')</td>
85 <td>$(gettext 'Action')</td>
86 <td>$(gettext 'PID')</td>
87 </tr>
88 </thead>
89 EOT
90 cd /etc/init.d
91 list="`ls | sed -e /.sh/d -e /rc./d -e /RE/d -e /daemon/d \
92 -e /firewall/d`"
93 for name in $list
94 do
95 pkg=""
96 pid=""
97 status=""
98 SHORT_DESC=""
99 echo '<tr>'
100 # Name
101 echo "<td>$name</td>"
102 # First check if daemon is started at bootime
103 [ echo "RUN_DAEMONS" | fgrep $name ] && boot="on boot"
104 # Standard SliTaz busybox daemons and firewall
105 echo -n "<td>"
106 case "$name" in
107 firewall)
108 gettext 'SliTaz Firewall with iptable rules' ;;
109 httpd)
110 gettext 'Small and fast web server with CGI support' ;;
111 ntpd)
112 gettext 'Network time protocol daemon' ;;
113 ftpd)
114 gettext 'Anonymous FTP server' ;;
115 udhcpd)
116 gettext 'Busybox DHCP server' ;;
117 syslogd|klogd)
118 gettext 'Linux Kernel log daemon' ;;
119 crond)
120 gettext 'Execute scheduled commands' ;;
121 dnsd)
122 gettext 'Small static DNS server daemon' ;;
123 tftpd)
124 gettext 'Transfer a file on tftp request' ;;
125 inetd)
126 gettext 'Listen for network connections and launch programs' ;;
127 zcip)
128 gettext 'Manage a ZeroConf IPv4 link-local address' ;;
129 *)
130 # Description from receipt
131 [ -d "$LOCALSTATE/installed/$name" ] && pkg=$name
132 [ -d "$LOCALSTATE/installed/${name%d}" ] && pkg=${name%d}
133 [ -d "$LOCALSTATE/installed/${name}-pam" ] && pkg=${name}-pam
134 if [ "$pkg" ]; then
135 . $LOCALSTATE/installed/$pkg/receipt
136 echo -n "$SHORT_DESC"
137 else
138 echo -n "----"
139 fi ;;
140 esac
141 echo "</td>"
142 # Attempt to get daemon status
143 pidfile=$(find /var/run -name *$name*.pid)
144 [ "$pidfile" ] && pid=$(cat $pidfile)
145 # dbus
146 [ -f /var/run/${name}/pid ] && pid=$(cat /var/run/${name}/pid)
147 # apache
148 [ "$name" = "apache" ] && pid=$(cat /var/run/$name/httpd.pid)
149 # Pidof works for many daemons
150 [ "$pid" ] || pid=$(pidof $name)
151 if [ "$pid" ]; then
152 cat << EOT
153 <td><img src="$IMAGES/started.png" alt="Started" title="$(gettext 'Started')" /></td>
154 <td><a href="$SCRIPT_NAME?daemons=stop=$name">
155 <img src="$IMAGES/stop.png" alt="Stop" title="$(gettext 'Stop')" /></a></td>
156 <td>
157 EOT
158 for i in $pid; do
159 cat << EOT
160 <a href="$SCRIPT_NAME?daemons=pid=$i">$i</a>
161 EOT
162 done
163 else
164 cat << EOT
165 <td><img src="$IMAGES/stopped.png" alt="Stopped" title="$(gettext 'Stopped')" /></td>
166 <td><a href="$SCRIPT_NAME?daemons=start=$name">
167 <img src="$IMAGES/start.png" alt="Start" title="$(gettext 'Start')" /></a></td>
168 <td>-----
169 EOT
170 fi
171 echo '</td></tr>'
172 done
173 table_end ;;
175 *\ grub\ *)
176 GRUBMENU="/boot/grub/menu.lst"
177 if [ "$(GET splash)" ]; then
178 default=$(GET default)
179 timeout=$(GET timeout)
180 splash=$(GET splash)
181 sed -i \
182 -e s"|default .*|default $default # new|" \
183 -e s"|timeout .*|timeout $timeout|" \
184 -e s"|splashimage=.*|splashimage=$splash|" \
185 $GRUBMENU
186 fi
187 default=$(cat $GRUBMENU | grep ^default | cut -d " " -f 2)
188 timeout=$(cat $GRUBMENU | grep ^timeout | cut -d " " -f 2)
189 splash=$(cat $GRUBMENU | grep ^splashimage | cut -d "=" -f 2)
190 xhtml_header
191 cat << EOT
192 <div id="wrapper">
193 <h2>$(gettext 'GRUB Boot loader')</h2>
195 <p>$(gettext 'The first application started when the computer powers on')</p>
196 </div>
198 <form method="get" action="$SCRIPT_NAME">
199 <input type="hidden" name="grub" />
200 <table>
201 <tr><td>$(gettext 'Default entry:')</td>
202 <td><input type="text" name="default" value="$default" /></td></tr>
203 <tr><td>$(gettext 'Timeout:')</td>
204 <td><input type="text" name="timeout" value="$timeout" /></td></tr>
205 <tr><td>$(gettext 'Splash image:')</td>
206 <td><input type="text" name="splash" value="$splash" size="40" /></td></tr>
207 </table>
208 <input type="submit" value="$(gettext 'Change')" />
209 <a class="button" href="index.cgi?file=$GRUBMENU">
210 <img src="$IMAGES/text.png" />$(gettext 'View or edit menu.lst')</a>
211 </form>
213 <h3>$(gettext 'Boot entries')</h3>
214 EOT
217 menu=$(tail -q -n +$(grep -n ^title $GRUBMENU | head -n1 | cut -d: -f1) $GRUBMENU \
218 | sed -e "s|^$||g" \
219 | sed -e "s|^title|</pre></li>\n<p><strong>$(gettext 'Entry') #</strong></p>\n<pre>\0|g" \
220 | sed '/^[ \t]*$/d' \
221 | tail -q -n +2)"</pre>"
223 entry='-1'
224 echo "$menu" | while read line
225 do
226 if [ -n "$(echo $line | grep '#</strong>')" ]; then
227 entry=$(($entry + 1))
228 fi
229 echo $line | sed "s|#</strong>|$entry</strong>|"
230 done
232 # Here we could check if an entry for gpxe is present if not
233 # display a form to add it.
234 [ -f "/boot/gpxe" ] && echo "<h3>gPXE</h3>" && \
235 gettext 'Web boot is available with gPXE'
236 ;;
237 *)
238 #
239 # Default content with summary
240 #
241 . /etc/rcS.conf
242 xhtml_header
243 cat << EOT
244 <div id="wrapper">
245 <h2>$(gettext 'Boot &amp; Start services')</h2>
246 <p>$(gettext 'Everything that happens before user login')</p>
247 </div>
248 <div>
249 <a class="button" href="$SCRIPT_NAME?log">
250 <img src="$IMAGES/text.png" />$(gettext 'Boot logs')</a>
251 <a class="button" href="$SCRIPT_NAME?daemons">
252 <img src="$IMAGES/recharge.png" />$(gettext 'Manage daemons')</a>
253 <a class="button" href="$SCRIPT_NAME?grub">$(gettext 'Boot loader')</a>
254 </div>
256 <h3>$(gettext 'Configuration files')</h3>
257 <ul>
258 <li>$(gettext 'Main configuration file:')
259 <a href="index.cgi?file=/etc/rcS.conf">rcS.conf</a></li>
260 <li>$(gettext 'Login manager settings:')
261 <a href="index.cgi?file=/etc/slim.conf">slim.conf</a></li>
262 </ul>
264 <h3>$(gettext 'Kernel cmdline')</h3>
266 <pre>$(cat /proc/cmdline)</pre>
268 <h3>$(gettext 'Local startup commands')</h3>
270 <pre>$(cat /etc/init.d/local.sh | syntax_highlighter sh)</pre>
272 <a class="button" href="index.cgi?file=/etc/init.d/local.sh&amp;action=edit">
273 <img src="$IMAGES/edit.png" />$(gettext 'Edit script')</a>
274 EOT
275 ;;
276 esac
278 xhtml_footer
279 exit 0