Licensed under GPLv3 or later, cleanup

This commit is contained in:
Sebastian Lohff 2012-01-16 22:35:15 +01:00
parent ef70a0f20b
commit 77287d9e62
11 changed files with 67 additions and 216 deletions

View File

@ -1,184 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# TODO
# Reconnecting to IRC-Server
# Complete switched networks
# Reduce debug output / add good output
# For more security use packet id + srcnick as key for fragmented packages
from conf import *
import pytap
from pytap import TapDevice
import select
import time
import irclib
import commands
import re
import base64
import random
dev = None
headerlen = 1 + 5 + 1 # flag + number + whitespace
packets = {}
def getMacFromIf(iface):
mac = commands.getoutput("/sbin/ifconfig %s|grep %s|egrep -o '([a-fA-F0-9]{2}(:|.)){6}'" % (iface, iface))
print "Debug: %s has mac address %s" % (iface, mac)
return mac
def getDstMacFromPkt(packet):
if len(packet) < 10:
return None
return packet[4:10]
def binToHexStr(binmac):
return "".join(["%02x" % ord(i) for i in binmac])
def isBroadcast(packet):
binmac = getDstMacFromPkt(packet)
# normal broadcast
if binmac == '\xff\xff\xff\xff\xff\xff':
return True
# v6 multicast
if binmac.startswith('\x33\x33'):
return True
return False
def sendToIRC(dev, server):
msg = dev.read()
oldencmsg = encmsg = base64.encodestring(msg).replace("\n", "")
slices = []
encmsglen = ircmsglen-headerlen
msgid = "%05d" % random.randint(0, 99999)
while len(encmsg) > encmsglen:
slices.append(encmsg[:encmsglen])
encmsg = encmsg[encmsglen:]
slices.append(encmsg)
# HUB or SWITCH?
if mode == "SWITCH" and not isBroadcast(package):
target = "VPN-%s" % (binToHexStr(getDstMacFromPkt(packet)),)
else:
target = broadcastchan
if len(slices) == 0:
print "DEBUG: EMPTY PACKAGE FROM DEV?"
elif len(slices) == 1:
print "Debug: Sending oneliner to dev"
server.privmsg(target, "o%s %s" % (msgid, slices[0]))
else:
print "Debug: Sending fragmented package to dev"
print " ---- COMPLETE MESSAGE BEFORE SLICES ---- "
print oldencmsg
print " ---- SLICES SLICES SLICES ---- "
print "\n".join(slices)
print " ---- SLICES SLICES SLICES ---- "
server.privmsg(target, "b%s %s" % (msgid, slices.pop(0)))
while len(slices) > 1:
server.privmsg(target, "c%s %s" % (msgid, slices.pop(0)))
server.privmsg(target, "e%s %s" % (msgid, slices.pop(0)))
def sendToDev(dev, server, isBroadcast, c, e):
parsed = pkgre.match(e.arguments()[0])
if not parsed:
print "message could not be parsed", e.arguments()[0]
return
(flag, msgid, basemsg) = parsed.groups()
print "flag: %s msgid: %s msg: %s" % (flag, msgid, basemsg)
try:
msgid = int(msgid)
except ValueError:
print "Debug: messageid was not a number"
return
if not ignoreNonMacUser:
# FIXME: ignore the non prefix-mac user
if not nickre.match():
print "is not allowed in our network"
print e.arguments(), irclib.nm_to_n(e.source()), e.target()
if flag == "o":
# oneliner!
print "Debug: Writing onliner to dev"
try:
msg = base64.decodestring(basemsg)
except base64.binascii.Error, e:
print "Debug: Error decoding base64 irc message (%s)" % e
return
#FIXME if packetAllowed(, , chan)
dev.write(msg)
elif flag == 'b':
if packets.has_key(msgid):
print "Warning: Overwriting lost package with id %s" % msgid
packets[msgid] = basemsg
elif flag in ('c', 'e'):
if not packets.has_key(msgid):
print "Error: Continue package has no matching entry in packets, discarding!"
else:
packets[msgid] += basemsg
if flag == 'e':
arrmsg = packets[msgid]
del(packets[msgid])
try:
print "arrmsg is", arrmsg.replace("\n", "\n\n\n")
msg = base64.decodestring(arrmsg)
except base64.binascii.Error, e:
print "Debug: Error decoding base64 irc message (%s)" % e
return
print "Debug: writing fragmented package to dev"
print binToHexStr(msg)
dev.write(msg)
#print "GOT in %s (broadcast %s) from %s msg %s" (e.target(), isBroadcast, irclib.nm_to_n(e.source()), e.arguments()[0])
def packetAllowed(src, nick, packet):
if not acceptNonMatchingMac:
# check if user-mac == packetmac
# FIXME if not getDstMacFromPkt(packet) ==
pass
# FIXME: Maybe move nick check to here
if mode != "HUB" and strictSwichedNetwork:
if src.startswith("#"): # its a channel
return False
return True
def startup():
# setup the tap device
dev = TapDevice(pytap.IFF_TAP)
dev.ifconfig(address=ip, netmask=netmask)
if gateway != "":
print "Setting default route %s" % gateway
os.sys("route add default gw %s")
# setup IRC foo
ircnick = nickPrefix + getMacFromIf(dev.name).replace(":", "")
print "Debug: Connectiong to %s as %s" % (ircserver, ircnick)
irc = irclib.IRC()
irc.add_global_handler("privmsg", lambda c, e: sendToDev(dev, server, False, c, e), -20)
irc.add_global_handler("pubmsg", lambda c, e: sendToDev(dev, server, True, c, e), -20)
server = irc.server()
server.connect(ircserver[0], ircserver[1], ircnick)
server.join(broadcastchan)
try:
while True:
sockets = [dev.__fd__]
# get private irc sockets :)
sockets.extend(map(lambda x: x._get_socket(), irc.connections))
sockets = filter(lambda x: x != None, sockets)
print "sockets", sockets
(readFDs, _, _) = select.select(sockets, [], [])
for readFD in readFDs:
print "EVENT BY", readFD
if readFD == dev.__fd__:
sendToIRC(dev, server)
else:
print "IRC event"
irc.process_once(0.1)
except KeyboardInterrupt:
pass
print "Shutting down!"
server.quit("RST")
if __name__ == '__main__':
startup()

View File

@ -1,19 +1,23 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import sys
sys.path.append("../../../")
from ether2any import Ether2Any
import base64
import irclib
import logging
import re
import random
import subprocess
import time
from conf import Conf
import time
import irclib
import re
import base64
import random
import logging
import subprocess
from ether2any import Ether2Any
from ether2any.helper import getDstMacFromPkt, isBroadcast, binToHexStr
class IrcVPN(Ether2Any):

View File

@ -1,4 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import irclib
from conf import Conf

View File

@ -1,25 +1,29 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import sys
import os
import re
import time
import struct
import base64
import StringIO
import gobject
import gtk
import mutex
import opencv
from opencv import highgui, adaptors
import qrencode
import zbar
import os
from PIL import Image
import gtk
import gobject
import urllib
import socket
import subprocess
import qrencode
import Queue
import re
import socket
import struct
import StringIO
import subprocess
import sys
import threading
import mutex
import time
import urllib
import zbar
sys.path.append("../../../")
from ether2any import Ether2Any

View File

@ -1,5 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import pyudev
import subprocess

View File

@ -1,21 +1,25 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import time
import asyncore
import email
from email.mime.text import MIMEText
import imaplib
import select
import smtpd
import smtplib
import imaplib
import email
from email.mime.text import MIMEText
import time
import threading
import sys
sys.path.append("../../../")
from wtbase import SpamGenerator, DecodingException
from ether2any import Ether2Any
from ether2any.helper import getDstMacFromPkt, isBroadcast, binToHexStr
from conf import Conf, ENCRYPTION_NONE, ENCRYPTION_STARTTLS, ENCRYPTION_SSL
from wtbase import SpamGenerator, DecodingException
# Todo
# Error checking at some places

View File

@ -1,14 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
""" wtbase - what the base
Provides classes to encode text to arbitrary bases (base 2^n supported) and
then to textual forms. """
from collections import deque
import math
from random import randint, randrange
import sys
import time
from collections import deque
class DecodingException(Exception):
pass

View File

@ -1,4 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import pyudev

View File

@ -1,5 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import logging
import os
@ -11,9 +14,9 @@ import threading
import time
sys.path.append("../../../")
from conf import Conf
from ether2any import Ether2Any
class USBWriter(threading.Thread):
def __init__(self, dev, networkQueue, writeLock):
threading.Thread.__init__(self)

View File

@ -1,11 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import bitarray
import random
import re
import urllib
from HTMLParser import HTMLParser
class PHelper():
""" Packaging Helper baseclass """

View File

@ -1,5 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Lohff <seba@seba-geek.de>
# Licensed under GPL v3 or later
import base64
import collections
@ -11,7 +14,6 @@ import time
import tweepy
sys.path.append("../../../")
from conf import Conf
from ether2any import Ether2Any
@ -24,7 +26,7 @@ class TwittStreamHandler(tweepy.StreamListener):
self.coder = coder
def on_status( self, status ):
""" On statis, decode and reassemble packet-status-texts. If complete, write them to the tun-dev. """
""" On status, decode and reassemble packet-status-texts. If complete, write them to the tun-dev. """
sourcePacket = status.text
if self.debug: