tazirc view 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
children 710ed4ffb0f8
line source
1 #!/bin/sh
2 #
3 # TazIRC - SliTaz IRC client: Keep it small! Maybe use a plugins system
4 # We use a single temporary text file to send commands to the IRC server
5 # and handle custom user commands such /q to quit.
6 #
7 # Copyright 2014 (C) SliTaz GNU/Linux - BSD License
8 # Author: Christophe Lincoln <pankso@slitaz.org>
9 #
10 . /lib/libtaz.sh
12 # Internationalization
13 TEXTDOMAIN='tazirc'
14 export TEXTDOMAIN
16 if [ ! "$1" ] || [ ! "$2" ]; then
17 cat << EOT
19 $(boldify "$(gettext 'Usage:')") $(basename $0) [host] [nick] [--option]"
21 $(boldify "$(gettext 'Options:')")
22 --chan= $(gettext "Join specified channel after connection")
23 --mode= $(gettext "Use specified mode. Default: +i")
24 --port= $(gettext "Use specified port. Default: 6667")
26 EOT
27 exit 0
28 fi
30 # Cmdline --options= are parsed by libtaz.sh
31 [ "$mode" ] || mode="+i"
32 [ "$port" ] || port="6667"
33 host="$1" && nick="$2"
34 send="/tmp/tazirc/${host}.${nick}.$$.txt"
36 # Clean up on exit
37 trap "echo 'Exiting...' && rm -f $send" SIGINT INT TERM
38 trap "kill 0" EXIT
39 mkdir -p $(dirname $send)
41 #
42 # Functions
43 #
45 # Error message: error "Message blabla..."
46 error() {
47 echo "$(colorize 31 'ERROR:') $1"
48 }
50 #
51 # Start: send login commands to connect to server then handle commands
52 #
54 # Introduce me!
55 clear
56 colorize 30 "TazIRC - SliTaz IRC Client"
57 boldify "$(gettext 'Connecting to:') $host $([ $chan ] && echo \#${chan})"
58 cat > ${send} << EOT
59 NICK $nick
60 USER $nick $mode * :$0
61 EOT
62 [ "$chan" ] && echo "JOIN #${chan}" >> ${send}
64 # Connect and handle server messages
65 (tail -f ${send} | busybox nc ${host} ${port} | while read MESSAGE
66 do
67 debug "$MESSAGE"
68 case "$MESSAGE" in
69 *" PRIVMSG "*)
70 # Display channel messages
71 user=$(echo "${MESSAGE%!*}" | sed s'/://')
72 text=$(echo "${MESSAGE#* :}")
73 echo "[$(date -u '+%R')] $(colorize 35 "$user"): $text" ;;
74 *" MODE "*)
75 echo "${MESSAGE#* }" ;;
76 PING*)
77 # Responding to ping
78 echo "PONG${MESSAGE#PING}" >> ${send} ;;
79 *)
80 echo "${MESSAGE#* :}" ;;
81 esac
82 done) &
84 # Handle user input commands/messages
85 while read COMMAND
86 do
87 # tazirc> prompt ?
88 # while true: echo -en "$(colorize 33 "tazirc")> "; read COMMAND
89 case "$COMMAND" in
90 "") continue ;;
91 /JOIN*|/join*|/j*)
92 chan="$(echo ${COMMAND} | cut -d '#' -f 2)"
93 boldify "$(gettext 'Joining:') #$chan"
94 echo "JOIN #$chan" >> ${send} ;;
95 /QUIT|/quit|/q)
96 boldify "$(gettext 'Diconnecting from:') $host"
97 echo "QUIT" >> ${send}
98 sleep 1 && rm -f ${send} && break ;;
99 /*)
100 echo "${COMMAND#/}" >> ${send} ;;
101 *)
102 if [ ! "$chan" ]; then
103 error "$(gettext 'No channel to send to')" && continue
104 fi
105 echo "[$(date -u '+%R')] $(colorize 34 "$nick"): ${COMMAND}"
106 echo "PRIVMSG #$chan :${COMMAND}" >> ${send} ;;
107 esac
108 done
110 exit 0