tazpanel view index.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 42367a53cf50
children b33228b5874d
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-2012 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 -u $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 *\ file\ *)
65 #
66 # Handle files
67 #
68 file="$(GET file)"
69 case $file in
70 *.html)
71 cat $file && exit 0 ;;
72 *)
73 TITLE=$(gettext 'TazPanel - File')
74 xhtml_header
75 echo "<h2>$file</h2>" ;;
76 esac
78 if [ "$(GET action)" == "edit" ]; then
79 cat <<EOT
80 <form method="post" action="$SCRIPT_NAME?file=$file">
81 <img src="$IMAGES/edit.png" />
82 <input type="submit" value="$(gettext 'Save')">
83 <a class="button" href='$SCRIPT_NAME?file=$file&action=diff'>
84 <img src="$IMAGES/help.png" />$(gettext 'Differences')</a>
85 <textarea name="content" rows="30" style="width: 100%;">
86 $(cat $file | htmlize)
87 </textarea>
88 </form>
89 EOT
90 #The space before textarea gets muddled when the form is submitted.
91 #It prevents anything else from getting messed up
92 elif [ "$(GET action)" == "diff" ]; then
93 echo '<pre id="diff">'
94 file_is_modified $file diff | syntax_highlighter diff
95 echo '</pre>'
96 else
97 [ -n "$(POST content)" ] &&
98 sed "s/`echo -en '\r'` /\n/g" > $file <<EOT
99 $(POST content)
100 EOT
101 cat <<EOT
102 <div id="actions">
103 <a class="button" href='$SCRIPT_NAME?file=$file&action=edit'>
104 <img src="$IMAGES/edit.png" />$(gettext 'Edit')</a>
105 EOT
106 file_is_modified $file button
107 cat << EOT
108 </div>
109 <pre>
110 EOT
111 # Handle file type by extension as a Web Server does it.
112 case "$file" in
113 *.conf|*.lst)
114 syntax_highlighter conf ;;
115 *.sh|*.cgi)
116 syntax_highlighter sh ;;
117 *)
118 cat | htmlize ;;
119 esac < $file
120 echo '</pre>'
121 fi ;;
124 *\ terminal\ *|*\ cmd\ *)
125 # Cmdline terminal.
126 commands='cat du help ls ping pwd who wget'
127 cmd=$(GET cmd)
128 TITLE=$(gettext 'TazPanel - Terminal')
129 xhtml_header
130 cat << EOT
131 <section>
132 <form method="get" action="$SCRIPT_NAME">
133 <div class="box">
134 root@$(hostname):~# <input autofocus type="text" name="cmd" style="width: 80%;" />
135 </div>
136 </form>
137 EOT
138 echo '<pre id="terminal">'
139 # Allow only a few commands for the moment.
140 case "$cmd" in
141 usage|help)
142 gettext 'Small terminal emulator, commands options are supported.'
143 echo ""
144 eval_gettext 'Commands: $commands'
145 echo ;;
146 wget*)
147 dl=/var/cache/downloads
148 [ ! -d "$dl" ] && mkdir -p $dl
149 eval_gettext 'Downloading to: $dl' && echo
150 cd $dl && $cmd ;;
151 du*|ls*|ping*|pwd|who)
152 $cmd ;;
153 cat*)
154 # Cmd must be used with an arg.
155 arg=$(echo $cmd | awk '{print $2}')
156 [ "$arg" == "" ] && eval_gettext '$cmd needs an argument' && break
157 $cmd ;;
158 *)
159 [ "$cmd" == "" ] || \
160 eval_gettext 'Unknown command: $cmd' && echo
161 eval_gettext 'Commands: $commands' ;;
162 esac
163 echo '</pre></section>'
164 ;;
167 *\ top\ *)
168 TITLE=$(gettext 'TazPanel - Process activity')
169 xhtml_header
170 echo $(gettext 'Refresh:') $(GET refresh)
171 cat << EOT
172 <br/>
173 <form method="get">
174 <input type="hidden" name="top"/>
175 <input type="submit" name="refresh" value="$(gettext '1s')"/>
176 <input type="submit" name="refresh" value="$(gettext '5s')"/>
177 <input type="submit" name="refresh" value="$(gettext '10s')"/>
178 <input type="submit" value="$(gettext 'none')"/>
179 </form>
180 EOT
181 if [ -n "$(GET refresh)" ]; then
182 echo -n '<meta http-equiv="refresh" content="'
183 echo -n "$(GET refresh)" | sed 's|\([^0-9]*\)\([0-9]\+\).*|\2|'
184 echo '">'
185 fi
187 echo '<pre>'
188 top -n1 -b | htmlize | sed \
189 -e s"#^[A-Z].*:\([^']\)#<span class='sh-comment'>\0</span>#"g \
190 -e s"#PID.*\([^']\)#<span class='top'>\0</span>#"g
191 echo '</pre>' ;;
194 *\ debug\ *)
195 TITLE=$(gettext 'TazPanel - Debug')
196 xhtml_header
197 cat << EOT
198 <h2>$(gettext 'HTTP Environment')</h2>
200 <pre>$(httpinfo)</pre>
201 EOT
202 ;;
205 *\ report\ *)
206 TITLE=$(gettext 'TazPanel - System report')
207 [ -d /var/cache/slitaz ] || mkdir -p /var/cache/slitaz
208 output=/var/cache/slitaz/sys-report.html
209 xhtml_header
210 cat << EOT
211 <h2>$(eval_gettext 'Reporting to: $output')</h2>
212 <table class="zebra outbox">
213 <tbody>
214 <tr><td>$(gettext 'Creating report header...')</td>
215 EOT
216 cat > $output << EOT
217 <!DOCTYPE html>
218 <html xmlns="http://www.w3.org/1999/xhtml">
219 <head>
220 <meta charset="utf-8" />
221 <title>$(gettext 'SliTaz system report')</title>
222 <style type="text/css">
223 body { padding: 20px 60px; font-size: 13px; }
224 h1, h2 { color: #444; }
225 pre { background: #f1f1f1; border: 1px solid #ddd;
226 padding: 10px; border-radius: 4px; }
227 span.diff-rm { color: red; }
228 span.diff-add { color: green; }
229 </style>
230 </head>
231 <body>
232 EOT
233 cat << EOT
234 $(ok_status_t)
235 <tr><td>$(gettext 'Creating system summary...')</td>
236 EOT
237 cat >> $output << EOT
238 <h1>$(gettext 'SliTaz system report')</h1>
239 $(gettext 'Date:') $(date)
240 <pre>
241 uptime : $(uptime)
242 cmdline : $(cat /proc/cmdline)
243 version : $(cat /etc/slitaz-release)
244 packages : $(ls /var/lib/tazpkg/installed | wc -l) installed
245 kernel : $(uname -r)
246 </pre>
247 EOT
248 cat << EOT
249 $(ok_status_t)
250 <tr><td>$(gettext 'Getting hardware info...')</td>
251 EOT
252 cat >> $output << EOT
253 <h2>free</h2>
254 <pre>$(free)</pre>
256 <h2>lspci -k</h2>
257 <pre>$(lspci -k)</pre>
259 <h2>lsusb</h2>
260 <pre>$(lsusb)</pre>
262 <h2>lsmod</h2>
263 <pre>$(lsmod)</pre>
265 EOT
266 cat << EOT
267 $(ok_status_t)
268 <tr><td>$(gettext 'Getting networking info...')</td>
269 EOT
270 cat >> $output << EOT
271 <h2>ifconfig -a</h2>
272 <pre>$(ifconfig -a)</pre>
274 <h2>route -n</h2>
275 <pre>$(route -n)</pre>
277 <h2>/etc/resolv.conf</h2>
278 <pre>$(cat /etc/resolv.conf)</pre>
279 EOT
280 cat << EOT
281 $(ok_status_t)
282 <tr><td>$(gettext 'Getting filesystems info...')</td>
283 EOT
284 cat >> $output << EOT
285 <h2>blkid</h2>
286 <pre>$(blkid)</pre>
288 <h2>fdisk -l</h2>
289 <pre>$(fdisk -l)</pre>
291 <h2>mount</h2>
292 <pre>$(mount)</pre>
294 <h2>df -h</h2>
295 <pre>$(df -h)</pre>
297 <h2>df -i</h2>
298 <pre>$(df -i)</pre>
299 EOT
300 cat << EOT
301 $(ok_status_t)
302 <tr><td>$(gettext 'Getting boot logs...')</td>
303 EOT
304 cat >> $output << EOT
305 <h2>$(gettext 'Kernel messages')</h2>
306 <pre>$(cat /var/log/dmesg.log)</pre>
308 <h2>$(gettext 'Boot scripts')</h2>
309 <pre>$(cat /var/log/boot.log | filter_taztools_msgs)</pre>
310 EOT
311 cat << EOT
312 $(ok_status_t)
313 <tr><td>$(gettext 'Creating report footer...')</td>
314 EOT
315 cat cat >> $output << EOT
316 </body>
317 </html>
318 EOT
319 cat << EOT
320 $(ok_status_t)
321 </tbody>
322 </table>
323 <p><a class="button" href="$SCRIPT_NAME?file=$output">
324 <img src="/styles/default/images/browser.png" />
325 $(gettext 'View report')</a>
326 $(msg tip "$(gettext 'This report can be attached with a bug report on:')
327 <a href="http://bugs.slitaz.org/">bugs.slitaz.org</a></p>")
328 EOT
329 ;;
332 *)
333 #
334 # Default xHTML content
335 #
336 xhtml_header
337 [ -n "$(GET gen_locale)" ] && new_locale=$(GET gen_locale)
338 [ -n "$(GET rdate)" ] && echo ""
339 hostname=$(hostname)
340 cat << EOT
341 <div id="wrapper">
342 <h2>$(eval_gettext 'Host: $hostname')</h2>
343 <p>$(gettext 'SliTaz administration and configuration Panel')<p>
344 </div>
345 <div id="actions">
346 <a class="button" href="$SCRIPT_NAME?terminal">
347 <img src="$IMAGES/terminal.png" />$(gettext 'Terminal')</a>
348 <a class="button" href="$SCRIPT_NAME?top">
349 <img src="$IMAGES/monitor.png" />$(gettext 'Process activity')</a>
350 <a class="button" href="$SCRIPT_NAME?report">
351 <img src="$IMAGES/text.png" />$(gettext 'Create a report')</a>
352 </div>
354 <section>
355 <h3>$(gettext 'Summary')</h3>
356 <div id="summary">
357 <table>
358 <tr><td>$(gettext 'Uptime:')</td>
359 <td>$(uptime)</td>
360 </tr>
361 <tr><td>$(gettext 'Memory in Mb:')</td>
362 EOT
363 free -m | grep Mem: | awk '{print $2, $3, $4}' | while read memtotal memused memfree
364 do
365 cat << EOT
366 <td>$(eval_gettext 'Total: $memtotal, Used: $memused, Free: $memfree')</td>
367 EOT
368 done
369 cat << EOT
370 </tr>
371 <tr><td>$(gettext 'Linux kernel:')</td>
372 <td>$(uname -r)</td>
373 </tr>
374 </table>
375 <!-- Close summary -->
376 </div>
377 </section>
379 <section>
380 <h4>$(gettext 'Network status')</h4>
381 $(list_network_interfaces)
382 </section>
384 <section>
385 <h4>$(gettext 'Filesystem usage statistics')</h4>
386 EOT
387 # Disk stats (management is done as hardware.cgi)
388 cat << EOT
389 <table class="zebra outbox">
390 EOT
391 df_thead
392 echo '<tbody>'
393 df -h | grep ^/dev | while read fs size used av pct mp
394 do
395 cat << EOT
396 <tr>
397 <td><a href="hardware.cgi">
398 <img src="$IMAGES/harddisk.png" />${fs#/dev/}</a></td>
399 <td>$(blkid -o value $fs | head -n1)</td>
400 <td>$(blkid -o value $fs | tail -n1)</td>
401 <td>$size</td>
402 <td>$av</td>
403 <td class="meter"><meter min="0" max="100" value="$(echo $pct | cut -d% -f1)"
404 low="$DU_WARN" high="$DU_CRIT" optimum="10"></meter>
405 <span>$used - $pct</span>
406 </td>
407 <td>$mp</td>
408 </tr>
409 EOT
410 done
411 cat << EOT
412 </tbody>
413 </table>
414 </section>
416 <section>
417 <h3>$(gettext 'Panel Activity')</h3>
418 <pre id="panel-activity">
419 $(cat $LOG_FILE | tail -n 8 | sort -r | syntax_highlighter activity)
420 </pre>
421 </section>
422 EOT
423 ;;
424 esac
426 xhtml_footer
427 exit 0