tazpanel view index.cgi @ rev 303

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