tazpanel view index.cgi @ rev 387
Added tag 1.8 for changeset 334a80c8d235
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Feb 24 01:08:15 2014 +0100 (2014-02-24) |
parents | b3f5245b1e90 |
children | 106b85c1951c |
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for TazPanel. In on word: KISS. Use the main css form
4 # command so we are faster and do not load unneeded functions. If necessary
5 # you can use the lib/ dir to handle external resources.
6 #
7 # Copyright (C) 2011-2014 SliTaz GNU/Linux - BSD License
8 #
10 # Common functions from libtazpanel
11 . lib/libtazpanel
12 get_config
13 header
15 TITLE="TazPanel"
17 # Check whether a configuration file has been modified after installation
18 file_is_modified()
19 {
20 grep -l " $1$" $INSTALLED/*/md5sum | while read file; do
22 # Found, but can we do diff ?
23 [ "$(grep -h " $1$" $file)" != "$(md5sum $1)" ] || break
24 org=$(dirname $file)/volatile.cpio.gz
25 zcat $org 2>/dev/null | cpio -t 2>/dev/null | \
26 grep -q "^${1#/}$" || break
28 case "$2" in
29 diff)
30 tmp=/tmp/tazpanel$$
31 mkdir -p $tmp
32 ( cd $tmp ; zcat $org | cpio -id ${1#/} )
33 diff -abu $tmp$1 $1 | sed "s|$tmp||"
34 rm -rf $tmp ;;
35 button)
36 cat <<EOT
37 <a class="button" href='$SCRIPT_NAME?file=$1&action=diff'>
38 <img src="$IMAGES/help.png" />$(gettext 'Differences')</a>
39 EOT
40 esac
41 break
42 done
43 }
46 # OK status in table
47 ok_status_t() {
48 echo " <td>[<span class='diff-add'> OK </span>]</td></tr>"
49 }
52 #
53 # Things to do before displaying the page
54 #
56 [ -n "$(GET panel_pass)" ] &&
57 sed -i s@/:root:.*@/:root:$(GET panel_pass)@ $HTTPD_CONF
59 #
60 # Commands
61 #
63 case " $(GET) " in
64 *\ exec\ *)
65 exec="$(GET exec)"
66 TITLE=$(gettext 'TazPanel - exec')
67 xhtml_header
68 cat << EOT
69 <h2>$exec</h2>
70 <pre>
71 $($exec 2>&1 | htmlize)
72 </pre>
73 EOT
74 ;;
75 *\ file\ *)
76 #
77 # Handle files
78 #
79 file="$(GET file)"
80 case $file in
81 *.html)
82 cat $file && exit 0 ;;
83 *)
84 TITLE=$(gettext 'TazPanel - File')
85 xhtml_header
86 echo "<h2>$file</h2>" ;;
87 esac
89 if [ "$(GET action)" == "edit" ]; then
90 cat <<EOT
91 <form method="post" action="$SCRIPT_NAME?file=$file">
92 <img src="$IMAGES/edit.png" />
93 <input type="submit" value="$(gettext 'Save')">
94 <a class="button" href='$SCRIPT_NAME?file=$file&action=diff'>
95 <img src="$IMAGES/help.png" />$(gettext 'Differences')</a>
96 <textarea name="content" rows="30" style="width: 100%;">
97 $(cat $file | htmlize)
98 </textarea>
99 </form>
100 EOT
101 #The space before textarea gets muddled when the form is submitted.
102 #It prevents anything else from getting messed up
103 elif [ "$(GET action)" == "setvar" ]; then
104 data="$(. $(GET file) ;eval echo \$$(GET var))"
105 cat <<EOT
106 <form method="post" action="$SCRIPT_NAME?file=$file">
107 <img src="$IMAGES/edit.png" />
108 <input type="submit" value="$(gettext 'Save')">
109 $(GET var) :
110 <input type="hidden" name="var" value="$(GET var)">
111 <input type="text" name="content" value="${data:-$(GET default)}">
112 </form>
113 EOT
114 elif [ "$(GET action)" == "diff" ]; then
115 echo '<pre id="diff">'
116 file_is_modified $file diff | syntax_highlighter diff
117 echo '</pre>'
118 else
119 R=$(echo -en '\r')
120 if [ -n "$(POST content)" ]; then
121 if [ -n "$(POST var)" ]; then
122 sed -i "s|^\\($(POST var)=\\).*|\1\"$(POST content)\"|" $file
123 else
124 sed "s/$R /\n/g;s/$R%0//g" > $file <<EOT
125 $(POST content)
126 EOT
127 fi
128 fi
129 cat <<EOT
130 <div id="actions">
131 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
132 <img src="$IMAGES/edit.png" />$(gettext 'Edit')</a>
133 EOT
134 file_is_modified $file button
135 cat << EOT
136 </div>
137 <pre>
138 EOT
139 # Handle file type by extension as a Web Server does it.
140 case "$file" in
141 *.conf|*.lst)
142 syntax_highlighter conf ;;
143 *.sh|*.cgi)
144 syntax_highlighter sh ;;
145 *)
146 cat | htmlize ;;
147 esac < $file
148 echo '</pre>'
149 fi ;;
152 *\ terminal\ *|*\ cmd\ *)
153 # Cmdline terminal.
154 commands='cat du help ls ping pwd who wget'
155 cmd=$(GET cmd)
156 TITLE=$(gettext 'TazPanel - Terminal')
157 xhtml_header
158 cat << EOT
159 <section>
160 <form method="get" action="$SCRIPT_NAME">
161 <div class="box">
162 root@$(hostname):~# <input autofocus type="text" name="cmd" style="width: 80%;" />
163 </div>
164 </form>
165 EOT
166 echo '<pre id="terminal">'
167 # Allow only a few commands for the moment.
168 case "$cmd" in
169 usage|help)
170 gettext 'Small terminal emulator, commands options are supported.'
171 echo ""
172 eval_gettext 'Commands: $commands'
173 echo ;;
174 wget*)
175 dl=/var/cache/downloads
176 [ ! -d "$dl" ] && mkdir -p $dl
177 eval_gettext 'Downloading to: $dl' && echo
178 cd $dl && $cmd ;;
179 du*|ls*|ping*|pwd|who)
180 $cmd ;;
181 cat*)
182 # Cmd must be used with an arg.
183 arg=$(echo $cmd | awk '{print $2}')
184 [ "$arg" == "" ] && eval_gettext '$cmd needs an argument' && break
185 $cmd ;;
186 *)
187 [ "$cmd" == "" ] || \
188 eval_gettext 'Unknown command: $cmd' && echo
189 eval_gettext 'Commands: $commands' ;;
190 esac
191 echo '</pre></section>'
192 ;;
195 *\ top\ *)
196 TITLE=$(gettext 'TazPanel - Process activity')
197 xhtml_header
198 echo $(gettext 'Refresh:') $(GET refresh)
199 cat << EOT
200 <br/>
201 <form method="get">
202 <input type="hidden" name="top"/>
203 <input type="submit" name="refresh" value="$(gettext '1s')"/>
204 <input type="submit" name="refresh" value="$(gettext '5s')"/>
205 <input type="submit" name="refresh" value="$(gettext '10s')"/>
206 <input type="submit" value="$(gettext 'none')"/>
207 </form>
208 EOT
209 if [ -n "$(GET refresh)" ]; then
210 echo -n '<meta http-equiv="refresh" content="'
211 echo -n "$(GET refresh)" | sed 's|\([^0-9]*\)\([0-9]\+\).*|\2|'
212 echo '">'
213 fi
215 echo '<pre>'
216 top -n1 -b | htmlize | sed \
217 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
218 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
219 echo '</pre>' ;;
222 *\ debug\ *)
223 TITLE=$(gettext 'TazPanel - Debug')
224 xhtml_header
225 cat << EOT
226 <h2>$(gettext 'HTTP Environment')</h2>
228 <pre>$(httpinfo)</pre>
229 EOT
230 ;;
233 *\ report\ *)
234 TITLE=$(gettext 'TazPanel - System report')
235 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
236 output=/var/cache/slitaz/sys-report.html
237 xhtml_header
238 cat << EOT
239 <h2>$(eval_gettext 'Reporting to: $output')</h2>
240 <table class="zebra outbox">
241 <tbody>
242 <tr><td>$(gettext 'Creating report header...')</td>
243 EOT
244 cat > $output << EOT
245 <!DOCTYPE html>
246 <html xmlns="http://www.w3.org/1999/xhtml">
247 <head>
248 <meta charset="utf-8" />
249 <title>$(gettext 'SliTaz system report')</title>
250 <style type="text/css">
251 body { padding: 20px 60px; font-size: 13px; }
252 h1, h2 { color: #444; }
253 pre { background: #f1f1f1; border: 1px solid #ddd;
254 padding: 10px; border-radius: 4px; }
255 span.diff-rm { color: red; }
256 span.diff-add { color: green; }
257 </style>
258 </head>
259 <body>
260 EOT
261 cat << EOT
262 $(ok_status_t)
263 <tr><td>$(gettext 'Creating system summary...')</td>
264 EOT
265 cat >> $output << EOT
266 <h1>$(gettext 'SliTaz system report')</h1>
267 $(gettext 'Date:') $(date)
268 <pre>
269 uptime : $(uptime)
270 cmdline : $(cat /proc/cmdline)
271 version : $(cat /etc/slitaz-release)
272 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
273 kernel : $(uname -r)
274 </pre>
275 EOT
276 cat << EOT
277 $(ok_status_t)
278 <tr><td>$(gettext 'Getting hardware info...')</td>
279 EOT
280 cat >> $output << EOT
281 <h2>free</h2>
282 <pre>$(free)</pre>
284 <h2>lspci -k</h2>
285 <pre>$(lspci -k)</pre>
287 <h2>lsusb</h2>
288 <pre>$(lsusb)</pre>
290 <h2>lsmod</h2>
291 <pre>$(lsmod)</pre>
293 EOT
294 cat << EOT
295 $(ok_status_t)
296 <tr><td>$(gettext 'Getting networking info...')</td>
297 EOT
298 cat >> $output << EOT
299 <h2>ifconfig -a</h2>
300 <pre>$(ifconfig -a)</pre>
302 <h2>route -n</h2>
303 <pre>$(route -n)</pre>
305 <h2>/etc/resolv.conf</h2>
306 <pre>$(cat /etc/resolv.conf)</pre>
307 EOT
308 cat << EOT
309 $(ok_status_t)
310 <tr><td>$(gettext 'Getting filesystems info...')</td>
311 EOT
312 cat >> $output << EOT
313 <h2>blkid</h2>
314 <pre>$(blkid)</pre>
316 <h2>fdisk -l</h2>
317 <pre>$(fdisk -l)</pre>
319 <h2>mount</h2>
320 <pre>$(mount)</pre>
322 <h2>df -h</h2>
323 <pre>$(df -h)</pre>
325 <h2>df -i</h2>
326 <pre>$(df -i)</pre>
327 EOT
328 cat << EOT
329 $(ok_status_t)
330 <tr><td>$(gettext 'Getting boot logs...')</td>
331 EOT
332 cat >> $output << EOT
333 <h2>$(gettext 'Kernel messages')</h2>
334 <pre>$(cat /var/log/dmesg.log)</pre>
336 <h2>$(gettext 'Boot scripts')</h2>
337 <pre>$(cat /var/log/boot.log | filter_taztools_msgs)</pre>
338 EOT
339 cat << EOT
340 $(ok_status_t)
341 <tr><td>$(gettext 'Creating report footer...')</td>
342 EOT
343 cat cat >> $output << EOT
344 </body>
345 </html>
346 EOT
347 cat << EOT
348 $(ok_status_t)
349 </tbody>
350 </table>
351 <p><a class="button" href="$SCRIPT_NAME?file=$output">
352 <img src="/styles/default/images/browser.png" />
353 $(gettext 'View report')</a>
354 $(msg tip "$(gettext 'This report can be attached with a bug report on:')
355 <a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>")
356 EOT
357 ;;
360 *)
361 #
362 # Default xHTML content
363 #
364 xhtml_header
365 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
366 [ -n "$(GET rdate)" ] && echo ""
367 hostname=$(hostname)
368 cat << EOT
369 <div id="wrapper">
370 <h2>$(eval_gettext 'Host: $hostname')</h2>
371 <p>$(gettext 'SliTaz administration and configuration Panel')<p>
372 </div>
373 <div id="actions">
374 <a class="button" href="$SCRIPT_NAME?terminal">
375 <img src="$IMAGES/terminal.png" />$(gettext 'Terminal')</a>
376 <a class="button" href="$SCRIPT_NAME?top">
377 <img src="$IMAGES/monitor.png" />$(gettext 'Process activity')</a>
378 <a class="button" href="$SCRIPT_NAME?report">
379 <img src="$IMAGES/text.png" />$(gettext 'Create a report')</a>
380 </div>
382 <section>
383 <h3>$(gettext 'Summary')</h3>
384 <div id="summary">
385 <table>
386 <tr><td>$(gettext 'Uptime:')</td>
387 <td>$(uptime)</td>
388 </tr>
389 <tr><td>$(gettext 'Memory in Mb:')</td>
390 EOT
391 free -m | grep Mem: | awk '{print $2, $3, $4}' | while read memtotal memused memfree
392 do
393 cat << EOT
394 <td>$(eval_gettext 'Total: $memtotal, Used: $memused, Free: $memfree')</td>
395 EOT
396 done
397 cat << EOT
398 </tr>
399 <tr><td>$(gettext 'Linux kernel:')</td>
400 <td>$(uname -r)</td>
401 </tr>
402 </table>
403 <!-- Close summary -->
404 </div>
405 </section>
407 <section>
408 <h4>$(gettext 'Network status')</h4>
409 $(list_network_interfaces)
410 </section>
412 <section>
413 <h4>$(gettext 'Filesystem usage statistics')</h4>
414 EOT
415 # Disk stats (management is done as hardware.cgi)
416 cat << EOT
417 <table class="zebra outbox">
418 EOT
419 df_thead
420 echo '<tbody>'
421 df -h | grep ^/dev | while read fs size used av pct mp
422 do
423 cat << EOT
424 <tr>
425 <td><a href="hardware.cgi">
426 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</a></td>
427 <td>$(blkid $fs | sed '/LABEL=/!d;s/.*LABEL="\([^"]*\).*/\1/')</td>
428 <td>$(blkid $fs | sed '/TYPE=/!d;s/.*TYPE="\([^"]*\).*/\1/')</td>
429 <td>$size</td>
430 <td>$av</td>
431 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
432 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
433 <span>$used - $pct</span>
434 </td>
435 <td>$mp</td>
436 <td>$(blkid $fs | sed '/UUID=/!d;s/.*UUID="\([^"]*\).*/\1/')</td>
437 </tr>
438 EOT
439 done
440 cat << EOT
441 </tbody>
442 </table>
443 </section>
445 <section>
446 <h3>$(gettext 'Panel Activity')</h3>
447 <pre id="panel-activity">
448 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
449 </pre>
450 </section>
451 EOT
452 ;;
453 esac
455 xhtml_footer
456 exit 0