slitaz-pizza diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/web/lib/libpizza Sat Mar 24 23:12:44 2012 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# Common functions for Pizza CGI/SHell web interface. 1.7 +# 1.8 + 1.9 +[ -f "/etc/slitaz/pizza.conf" ] && . /etc/slitaz/pizza.conf 1.10 +[ -f "../pizza.conf" ] && . ../pizza.conf 1.11 +. ./db.conf 1.12 +. /usr/lib/slitaz/httphelper 1.13 +header 1.14 + 1.15 +# xHTML header. 1.16 +cat lib/header.html || exit 1 1.17 + 1.18 +# Status function. 1.19 +status() { 1.20 + if [ $? = 0 ]; then 1.21 + echo " <span class="span-ok">OK</span>" 1.22 + else 1.23 + echo " <span class="span-red">Failed</span>" 1.24 + fi 1.25 +} 1.26 + 1.27 +# Put some colors in log and DB files. 1.28 +highlighter() { 1.29 + case $1 in 1.30 + log) 1.31 + sed -e 's#OK#<span class="span-ok">OK</span>#g' \ 1.32 + -e 's#Failed#<span class="span-red">Failed</span>#g' ;; 1.33 + activity) 1.34 + sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;; 1.35 + esac 1.36 +} 1.37 + 1.38 +# Log activities, we want first letter capitalized. 1.39 +log() { 1.40 + grep ^[A-Z] | \ 1.41 + sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity 1.42 +} 1.43 + 1.44 +# Usage: error string 1.45 +error() { 1.46 + echo "<span class="span-red">ERROR: $@</span>" 1.47 +} 1.48 + 1.49 +# Pizza notification function: notify "message" "icon" 1.50 +notify() { 1.51 + img=info 1.52 + [ "$2" ] && img=$2 1.53 + cat << EOT 1.54 +<script type="text/javascript"> 1.55 + document.write('<div id="notify"><img src="images/$img.png" />$1</div>'); 1.56 + fadeNotify('notify', 100, 0, 300); 1.57 + setTimeout('hideNotify()', 6200); 1.58 +</script> 1.59 +EOT 1.60 +}