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

Add the web interface
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 24 23:12:44 2012 +0100 (2012-03-24)
parents
children 2ea0527e3c3d
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 's#OK#<span class="span-ok">OK</span>#g' \
29 -e 's#Failed#<span class="span-red">Failed</span>#g' ;;
30 activity)
31 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
32 esac
33 }
35 # Log activities, we want first letter capitalized.
36 log() {
37 grep ^[A-Z] | \
38 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
39 }
41 # Usage: error string
42 error() {
43 echo "<span class="span-red">ERROR: $@</span>"
44 }
46 # Pizza notification function: notify "message" "icon"
47 notify() {
48 img=info
49 [ "$2" ] && img=$2
50 cat << EOT
51 <script type="text/javascript">
52 document.write('<div id="notify"><img src="images/$img.png" />$1</div>');
53 fadeNotify('notify', 100, 0, 300);
54 setTimeout('hideNotify()', 6200);
55 </script>
56 EOT
57 }