Commit 6ed4f14b authored by stettberger's avatar stettberger

remove old stettberger stiis

parent 319b208d
install:
mkdir -p ${HOME}/irc
mkdir -p ${HOME}/bin
touch ${HOME}/irc/serv.def
touch ${HOME}/irc/chan.def
cp irc_shell ${HOME}/bin
cp irc_client ${HOME}/bin
cp connect ${HOME}/bin
cp demultiplexer.py ${HOME}/bin
cp buddylist ${HOME}/bin
@echo
@echo "Installed stiis"
@echo
@echo "*******************************************"
@echo "* See README for details in Configuration *"
@echo "*******************************************"
Format of the $HOME/irc/serv.def:
$HOST;$SHORT_NAME;$PROGRAM
an example is:
irc.oftc.net;oftc;ii -s irc.oftc.net -f Didi
Format of the $HOME/irc/chan.def:
$HOST;$CHANNEL;$SHORT_NAME;$COLOR
example:
irc.oftc.net;#ii;ii;yellow
Colors can be:
red
green
yellow
blue
magenta
cyan
white
Programs:
connect - Reads the $HOME/irc/serv.def an executes $PROGRAM
demultiplexer.py - Demultiplexes all the Status outputes in $HOME/irc/out (based on inotify)
irc_client - opens 2 Xterms: a multitail with all channels and an with the irc_shell
irc_shell - Input shell
Input Shell:
/p - prints all "channels"
/s $SHORT_NAME - select the channel
/link <$SHORT_NAME> - Reads either the selectet channel or the actual channel for the last url, and opens it
#!/usr/bin/python
import socket, select, os, sys, re, time
import curses
class BuddyList:
def __init__(self, server, prefix="%s/irc"%os.environ['HOME'], buffer=1024):
self.server=os.path.join(prefix,server)
self.server=os.path.join(self.server, "buddylist")
self.socket=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM,0)
self.buffer=buffer
try:
self.socket.connect(self.server)
except:
self.socket=None
def has_data(self):
try:
(iwtd, owtd, ewtd)=select.select([self.socket],[],[],0.05)
except:
return False
if len(iwtd)==0:
return False
return True
def get_buddylist(self):
self.socket.send("getbuddylist\n")
text=self.socket.recv(self.buffer)
ret=[]
for i in text.split('\n'):
(status, nickname)=i.split(",",2)
if(status=="END"):
return ret
ret.append([status, nickname])
return ret
def read(self):
return self.socket.recv(self.buffer).replace("\n", "")
class DeMultiplexer:
def __init__(self, prefix="%s/irc"%os.environ['HOME']):
self.servers=[]
self.scr=None
self.buddylist=[]
for i in os.walk(prefix):
if "buddylist" in i[2]:
server=BuddyList(i[0].replace(prefix, "")[1:])
if server.socket==None:
continue
self.servers.append(server)
def init_curses(self):
self.scr = curses.initscr()
curses.start_color()
curses.noecho()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
self.scr.attron(curses.A_BOLD)
def refresh(self):
self.buddylist=[]
for i in self.servers:
for x in i.get_buddylist():
self.buddylist.append(x)
self.scr.clear()
for i in self.buddylist:
if "D" in i[0]:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(3))
elif "G" in i[0]:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(3) | curses.A_BOLD)
elif "I" in i[0]:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(2) | curses.A_BOLD)
else:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(1) | curses.A_BOLD)
self.scr.refresh()
def run(self):
self.init_curses()
self.refresh()
try:
while True:
for i in self.servers:
if i.has_data():
if i.read() == "update":
self.refresh()
time.sleep(1)
except:
curses.endwin()
fd=DeMultiplexer()
fd.run()
sys.exit(1)
#!/bin/sh
# Starting chats
while read i; do
PROG=$(echo $i | awk -F ';' '{print $3}');
$PROG &
done < $HOME/irc/serv.def
$HOME/bin/demultiplexer.py &
\ No newline at end of file
#!/usr/bin/python
# Author: 2006 Christian Dietrich <stettberger@gmx.de>
# Year: 2006
# License: GPL
import os, sys
from pyinotify import SimpleINotify, ProcessEvent, EventsCodes
ircdir="%s/irc"%os.environ['HOME']
files=[]
tmp=[]
class DeMulti(ProcessEvent):
def process_IN_MODIFY(self, event_k):
for i in files:
if event_k.path == i[0]:
fd=open(os.path.join(ircdir, "out"), "a+")
text=i[1].read()
for line in text.split("\n"):
tok=line.split(" ", 1)
if len(tok)<2:
continue
try:
fd.write("%s [%s] %s\n"%(tok[0], i[2], tok[1]))
except:
pass
fd.close()
def process_default(self, event_k, event):
pass
# Perpare de filelist
for i in os.listdir(ircdir):
path=os.path.join(ircdir, i)
if os.path.isdir(path):
filename=os.path.join(path, "out")
if os.path.isfile(filename):
fd=open(filename)
fd.seek(0,2)
files.append([filename,fd, i])
tmp.append(filename)
print tmp
mask = EventsCodes.IN_MODIFY
ino = SimpleINotify()
wdd = ino.add_watch(tmp , mask, DeMulti(), rec=False)
while True: # loop forever
try:
ino.process_events()
if ino.event_check():
ino.read_events()
except KeyboardInterrupt:
# destroy the inotify's instance on this interrupt (stop monitoring)
ino.close()
break
#!/bin/sh
XTERM="xterm -fg white -bg black"
export IRCDIR="$HOME/irc"
sleep 5
# Channel Joinen
while read i; do
SERVER=$(echo $i | awk -F ';' '{print $1 }')
CHANNEL=$(echo $i | awk -F ';' '{print $2}')
echo "/j $CHANNEL" > $IRCDIR/$SERVER/in
echo "Joined $CHANNEL"
WATCH="$WATCH -f $IRCDIR/$SERVER/$CHANNEL/out"
done < $IRCDIR/chan.def
WATCH="$WATCH -f $IRCDIR/out"
$XTERM -e multitail -CS irc $WATCH -s 2 &
$XTERM -e $HOME/bin/irc_shell
#!/usr/bin/python
#
# Author: Christian Dietrich <stettberger@gmx.de>
# Year: 2006
# License: GPL
import re, sys, os
ircdir="%s/irc"%os.environ['HOME']
browser="firefox \"%s\""
def read_file_reverse(filename, callback, many=1):
fd=open(filename, "r")
fd.seek(0,2)
buf=""
match=[]
while (fd.tell()-10)>0:
fd.seek(fd.tell()-10)
buf=fd.read(10)+buf
fd.seek(fd.tell()-10)
if '\n' in buf:
fd.seek(fd.tell()+buf.find('\n'))
line=buf[buf.find('\n')+1:]
buf=''
ret=callback(line)
if ret != None:
fd.close()
match.append(ret)
if(len(match)==many):
return match
fd.close()
def parse_url(line):
regex=".*(?P<url>(?:(?:[hH][tT]{2}[Pp][sS]?)|(?:[fF][Tt][Pp]))://[a-zA-Z&\?.0-9+\-_=~#/]*).*"
if re.match(regex, line):
return re.match(regex, line).groups("url")[0]
return None
class Server:
colors={"red": "\033[0;40;31m",
"green": "\033[0;40;32m",
"yellow": "\033[0;40;33m",
"blue": "\033[0;40;34m",
"magenta":"\033[0;40;35m",
"cyan": "\033[0;40;36m",
"white": "\033[0;40;37m",
"normal": "\033[0m"}
def __init__(self, name, syn):
self.host=name
self.channels=[]
self.add_channel(None, syn, self.colors['white'])
def add_channel(self, name, syn, color=None):
if color is None:
color=self.colors['normal']
if name != None:
if len(syn)==0:
syn=name
self.channels.append([syn, "%s%s%s"%(color,name,self.colors['normal']), "%s/%s"%(self.host, name)])
else:
self.channels.append([syn, "%s%s%s"%(color,self.host ,self.colors['normal']), "%s"%self.host])
def add_query(self, name, syn, color=None):
if color is None:
color=self.colors['normal']
self.channels.append([syn, "%s%s%s"%(color,name, self.colors['normal']), "%s/query/%s"%(self.host, name)])
def has_channel(self, syn):
for i in self.channels:
if i[0]==syn:
return True
return False
def get_channel(self, syn):
for i in self.channels:
if i[0]==syn:
return i
return None
servers=[]
now=None
def proc_input(line):
# Auswahl von Server/Channel/Query
if line[0:3]=="/s ":
for i in servers:
if i.has_channel(line[3:]):
globals()['now']=i.get_channel(line[3:])
# For Debugging only
elif line[0:2]=="/p":
for i in servers:
print "Server: %s"%i.host
for x in i.channels:
print " %s %s"%(x[0],x[1])
# Link handling
elif line[0:5]=="/link":
tok=re.split("\s+", line)
if len(tok)==1 or len(tok[1])==0:
ch=globals()['now'][2]
else:
for i in servers:
if i.has_channel(tok[1]):
ch=i.get_channel(tok[1])[2]
filename="%s/%s/out"%(ircdir,ch)
urls=read_file_reverse(filename, parse_url)
if urls==None:
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
return
os.system((browser+ "&")%urls[0])
sys.stdout.write("%sUrl opened %s"%(Server.colors['green'], Server.colors['normal']))
# Server/Channel/Query adden
elif line[0:5]=="/add ":
tokens=re.split(" *", line)
if len(tokens)<2:
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
return
# Add a query
if tokens[1]=="query":
if len(tokens)<4:
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
return
for i in servers:
if i.host==tokens[2]:
if len(tokens)==4:
i.add_query(tokens[3], tokens[3])
elif len(tokens)==5:
i.add_query(tokens[3], tokens[4])
elif len(tokens)>5:
i.add_query(tokens[3], tokens[4], Servers.colors[tokens[5]])
return
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
# Add a channel
elif tokens[1]=="channel":
if len(tokens)<4:
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
return
for i in servers:
if i.host==tokens[2]:
if len(tokens)==4:
i.add_channel(tokens[3], tokens[3])
elif len(tokens)==5:
i.add_channel(tokens[3], tokens[4])
elif len(tokens)>5:
i.add_channel(tokens[3], tokens[4], Server.colors[tokens[5]])
return
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
# Add a Server
elif tokens[1]=="server":
if len(tokens)<3:
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
return
if len(tokens)==3:
servers.append(Server(tokens[2], tokens[2]))
elif len(tokens)>3:
servers.append(Server(tokens[2], tokens[3]))
else:
if globals()['now'] is None:
return
t=open("%s/%s/in"%(ircdir, globals()['now'][2]), "w+")
t.write("%s\n"%line)
t.close()
def init():
##Servers
try:
fd=open("%s/serv.def"%ircdir)
except:
print "Error: Couldn't open servers definition"
sys.exit(-1)
for i in fd.readlines():
i=i.split(";", 3)
if len(i)<3:
print i, "is not a valid line (serv.def)"
continue
servers.append(Server(i[0], i[1]))
fd.close()
try:
fd=open("%s/chan.def"%ircdir)
except:
print "Error: Couldn't open channel definition"
for i in fd.readlines():
i=i.split(";", 3)
if len(i)<4:
print i, "is not a valid line (chan.def)"
continue
for s in servers:
if s.host == i[0]:
try:
s.add_channel(i[1], i[2], Server.colors[i[3].replace("\n","")])
except:
print i, " couldn't be appended (chan.def)"
# Initialize channels
init()
while True:
if globals()['now']==None:
if len(servers)==0:
globals()['now']=['','',None]
else:
globals()['now']=servers[0].channels[0]
try:
line=raw_input("%s> "%globals()['now'][1])
except:
sys.exit(0)
if len(line)==0:
continue
try:
proc_input(line)
except:
sys.stdout.write("%sError %s"%(Server.colors['red'], Server.colors['normal']))
allow_8bit:yes
colorscheme:irc
# messages
cs_re_s:magenta,,bold:^..:.. [<].*(stettberger)[>].*$
cs_re_s:magenta:^..:.. <([^<>]+)>.+$
cs_re_s:green:^..:.. [<].*stettberger[>](.*)$
cs_re_s:yellow:^..:.. .*(stettberger):.*$
cs_re_s:cyan:^(..:..).*$
cs_re_s:yellow:^..:.. (\[.*\]).*$
cs_re:yellow:(http:\/\/[a-zA-Z&\?.0-9+\-_~=#/]+)
cs_re_s:magenta:^..:.. \[.*\] [<>]([^<>]*)[<>].*$
# Watches Errors and other status messages
cs_re_s:blue:^..:...*(-!-)
cs_re_s:green:^..:...*(-\?!-)
cs_re_s:red:^..:...*-!- (Error [^\s]+:)
cs_re_s:yellow:^..:...*-!- (Watch:)
# Status lines
cs_re_s:cyan,,bold:^..:.. -!- ([^ \(\[]*)
cs_re_s:cyan:^..:.. -!- [^ \(\[]*(.*) has
cs_re_s:green:^..:.. -!- [^ \(\[]*.* (has .*)
titlebar:%m %u@%h %f (%t) [%l]
tail:/usr/bin/turbotail
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment