slitaz-pizza view web/lib/libpizza @ rev 12

libpizza/highlighter: hide escape sequences
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Mar 26 10:21:18 2012 +0200 (2012-03-26)
parents 8b324cb2c5e2
children 3d50b39eb83d
line source
1 #!/bin/sh
2 #
3 # Common functions for Pizza CGI/SHell web interface.
4 #
6 [ -f "/etc/slitaz/pizza.conf" ] && . /etc/slitaz/pizza.conf
7 [ -f "../pizza.conf" ] && . ../pizza.conf
8 . ./db.conf
9 . /usr/lib/slitaz/httphelper
10 header
12 # xHTML header.
13 cat lib/header.html || exit 1
15 # Status function.
16 status() {
17 if [ $? = 0 ]; then
18 echo " <span class="span-ok">OK</span>"
19 else
20 echo " <span class="span-red">Failed</span>"
21 fi
22 }
24 # Put some colors in log and DB files.
25 highlighter() {
26 case $1 in
27 log)
28 sed -e ':a;s/^\(.\{1,73\}\)OK$/\1 OK/;ta' \
29 -e ':a;s/^\(.\{1,73\}\)Failed$/\1 Failed/;ta' |
30 sed -e 's|\[[0-9G\.KM]* .||g' -e 's|.\[18G| |' \
31 -e 's#OK#<span class="span-ok">OK</span>#g' \
32 -e 's#Failed#<span class="span-red">Failed</span>#g' ;;
33 activity)
34 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
35 esac
36 }
38 # Log activities, we want first letter capitalized.
39 log() {
40 grep ^[A-Z] | \
41 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
42 }
44 # Usage: error string
45 error() {
46 echo "<span class="span-red">ERROR: $@</span>"
47 }
49 # Pizza notification function: notify "message" "icon"
50 notify() {
51 img=info
52 [ "$2" ] && img=$2
53 cat << EOT
54 <script type="text/javascript">
55 document.write('<div id="notify"><img src="images/$img.png" />$1</div>');
56 fadeNotify('notify', 100, 0, 300);
57 setTimeout('hideNotify()', 6200);
58 </script>
59 EOT
60 }