tazpanel view boot.cgi @ rev 373

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