tazirc rev 7

Add a small CGI example to have online logs
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jan 14 21:44:19 2014 +0100 (2014-01-14)
parents 92dac62b8fd0
children 58eaeeaa5468
files tools/tazirc-lb.cgi
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/tazirc-lb.cgi	Tue Jan 14 21:44:19 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Small CGI example to display TazIRC Log Bot logs.
     1.7 +#
     1.8 +. /usr/lib/slitaz/httphelper.sh
     1.9 +
    1.10 +host="irc.freenode.net"
    1.11 +chan="slitaz"
    1.12 +logdir="log/$host/$chan"
    1.13 +
    1.14 +# Send content type
    1.15 +header
    1.16 +
    1.17 +# HTML Header
    1.18 +cat << EOT
    1.19 +<!DOCTYPE html>
    1.20 +<html lang="en">
    1.21 +<head>
    1.22 +	<meta charset="utf-8" />
    1.23 +	<title>TazIRC Log Bot</title>
    1.24 +	<link rel="stylesheet" type="text/css" href="style.css" />
    1.25 +	<style type="text/css">
    1.26 +		html { height: 102%; }
    1.27 +		body { margin: 40px 80px; font-size: 90%; }
    1.28 +	</style>
    1.29 +</head>
    1.30 +<body>
    1.31 +EOT
    1.32 +
    1.33 +# Handle GET actions 
    1.34 +case " $(GET) " in
    1.35 +	*\ log\ *)
    1.36 +		log="$(GET log)"
    1.37 +		echo "<h2>#${chan} $log</h2>"
    1.38 +		IFS="|"
    1.39 +		cat ${logdir}/${log}.log | while read time user text
    1.40 +		do
    1.41 +		cat << EOT
    1.42 +<div>
    1.43 +[$time] <span style="color: blue;">$user:</span> $text
    1.44 +</div>
    1.45 +EOT
    1.46 +		done 
    1.47 +		unset IFS ;;
    1.48 +	*)
    1.49 +		# List all logs by date
    1.50 +		echo "<h2>#${chan} Logs</h2>"
    1.51 +		echo "<pre>"
    1.52 +		for log in $(ls $logdir/*.log | sort -r -n)
    1.53 +		do
    1.54 +			log="$(basename ${log%.log})"
    1.55 +			echo "<a href='?log=$log'>$log</a>"
    1.56 +		done
    1.57 +		echo "</pre>"
    1.58 +esac
    1.59 +
    1.60 +# HTML Footer
    1.61 +cat << EOT
    1.62 +</body>
    1.63 +</html>
    1.64 +EOT