cookutils rev 319
Add Cookiso CGI/Web interface
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Mar 15 03:02:59 2012 +0100 (2012-03-15) |
parents | 26f8f693b916 |
children | 2fdceaad6903 |
files | web/cookiso.cgi |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/web/cookiso.cgi Thu Mar 15 03:02:59 2012 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# SliTaz Cookiso CGI/web interface. 1.7 +# 1.8 +echo "Content-Type: text/html" 1.9 +echo "" 1.10 + 1.11 +[ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf 1.12 +[ -f "cook.conf" ] && . ./cook.conf 1.13 + 1.14 +# Cookiso DB files. 1.15 +cache="$CACHE/cookiso" 1.16 +iso="$SLITAZ/iso" 1.17 +activity="$cache/activity" 1.18 +command="$cache/command" 1.19 +rollog="$cache/rolling.log" 1.20 + 1.21 +# 1.22 +# Functions 1.23 +# 1.24 + 1.25 +# Put some colors in log and DB files. 1.26 +syntax_highlighter() { 1.27 + case $1 in 1.28 + log) 1.29 + sed -e 's#OK#<span class="span-ok">OK</span>#g' \ 1.30 + -e 's#Failed#<span class="span-red">Failed</span>#g' \ 1.31 + -e 's|\(Filesystem size:\).*G\([0-9\.]*M\) *$|\1 \2|' \ 1.32 + -e 's|.\[1m|<b>|' -e 's|.\[0m|</b>|' -e 's|.\[[0-9Gm;]*||g' ;; 1.33 + activity) 1.34 + sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;; 1.35 + esac 1.36 +} 1.37 + 1.38 +# Latest build pkgs. 1.39 +list_isos() { 1.40 + cd $iso 1.41 + ls -1t *.iso | head -6 | \ 1.42 + while read file 1.43 + do 1.44 + echo -n $(stat -c '%y' $file | cut -d . -f 1 | sed s/:[0-9]*$//) 1.45 + echo " : $file" 1.46 + done 1.47 +} 1.48 + 1.49 +# xHTML header. Pages can be customized with a separated html.header file. 1.50 +if [ -f "header.html" ]; then 1.51 + cat header.html | sed s'/Cooker/ISO Cooker/' 1.52 +else 1.53 + cat << EOT 1.54 +<!DOCTYPE html> 1.55 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.56 +<head> 1.57 + <title>SliTaz ISO Cooker</title> 1.58 + <meta charset="utf-8" /> 1.59 + <link rel="shortcut icon" href="favicon.ico" /> 1.60 + <link rel="stylesheet" type="text/css" href="style.css" /> 1.61 +</head> 1.62 +<body> 1.63 + 1.64 +<div id="header"> 1.65 + <div id="logo"></div> 1.66 + <h1><a href="cookiso.cgi">SliTaz ISO Cooker</a></h1> 1.67 +</div> 1.68 + 1.69 +<!-- Content --> 1.70 +<div id="content"> 1.71 +EOT 1.72 +fi 1.73 + 1.74 +# 1.75 +# Load requested page 1.76 +# 1.77 + 1.78 +case "${QUERY_STRING}" in 1.79 + distro=*) 1.80 + distro=${QUERY_STRING#distro=} 1.81 + log=$iso/slitaz-$distro.log 1.82 + . $SLITAZ/flavors/${distro#*-}/receipt 1.83 + echo "<h2>Distro: $distro</h2>" 1.84 + echo "<p>Description: $SHORT_DESC</p>" 1.85 + echo '<h3>Cookiso log</h3>' 1.86 + echo '<pre>' 1.87 + cat $log | syntax_highlighter log 1.88 + echo '</pre>' ;; 1.89 + *) 1.90 + # Main page with summary. 1.91 + echo -n "Running command : " 1.92 + if [ -f "$command" ]; then 1.93 + cat $command 1.94 + else 1.95 + echo "Not running" 1.96 + fi 1.97 + cat << EOT 1.98 +<h2>Activity</h2> 1.99 +<pre> 1.100 +$(tac $activity | head -n 12 | syntax_highlighter activity) 1.101 +</pre> 1.102 + 1.103 +<h2>Latest ISO</h2> 1.104 +<pre> 1.105 +$(list_isos | syntax_highlighter activity) 1.106 +</pre> 1.107 +EOT 1.108 + # Rolling Bot log. 1.109 + if [ -f "$rollog" ]; then 1.110 + echo "<h2>Rolling log</h2>" 1.111 + echo '<pre>' 1.112 + cat $rollog 1.113 + echo '</pre>' 1.114 + fi ;; 1.115 +esac 1.116 + 1.117 +# Close xHTML page 1.118 +cat << EOT 1.119 +</div> 1.120 + 1.121 +<div id="footer"> 1.122 + <a href="http://www.slitaz.org/">SliTaz Website</a> 1.123 + <a href="cookiso.cgi">Cookiso</a> 1.124 + <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html"> 1.125 + Documentation</a> 1.126 +</div> 1.127 + 1.128 +</body> 1.129 +</html> 1.130 +EOT 1.131 + 1.132 +exit 0